---
title: "Monitor your Fargate container logs with FireLens and Datadog"
description: "Learn how you can use FireLens for Amazon ECS to collect container logs generated by your Fargate tasks and seamlessly monitor them in Datadog."
author: "Mallory Mooney"
date: 2019-11-04
tags: ["serverless monitoring", "log management", "aws", "aws fargate", "firelens", "amazon ecs", "logs"]
blog_type_id: the-monitor
locale: en
---

To centralize logging from your entire stack—from traditional infrastructure to serverless components—Datadog is announcing native support for the launch of [FireLens for Amazon ECS](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/using_firelens.html). FireLens streamlines logging by enabling you to configure a log collection and forwarding tool such as [Fluent Bit](https://fluentbit.io/) directly in your [Fargate](https://aws.amazon.com/fargate/) tasks.

We've partnered with AWS to provide [built-in Fluent Bit support](https://github.com/aws-samples/amazon-ecs-firelens-examples/tree/master/examples/fluent-bit/datadog) for Datadog so that you can now seamlessly route container logs from AWS Fargate. Once your logs are flowing into Datadog, you can monitor them alongside other Fargate metrics to get visibility into your containerized services.

![Custom Fargate dashboard](https://web-assets.dd-static.net/42588/1776292542-collect-fargate-logs-with-firelens-fargate_dash_new.png)
*Datadog's new Fluent Bit plugin helps you monitor Fargate container logs alongside your container metrics in dashboards.*

## Configure Fluent Bit directly in your Fargate tasks

In order to start forwarding Fargate container logs to Datadog with Fluent Bit, you will need to specify a new [container definition](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/task_definition_parameters.html#container_definitions) for your Fargate task:

*fargate-task.yaml*
```text
"containerDefinitions": [{
    "essential": true,
    "image": "amazon/aws-for-fluent-bit:latest",
    "name": "log_router",
    "firelensConfiguration": {
	    "type": "fluentbit",
	    "options": {
		    "enable-ecs-log-metadata": "true"
	    }
    }
}]
```

This will create a FireLens container using Amazon's [Fluent Bit image](https://hub.docker.com/r/amazon/aws-for-fluent-bit) so you can use Fargate task definitions to route logs with Fluent Bit. The [`essential` parameter](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/task_definition_parameters.html#container_definition_storage) ensures that containers that rely on this configuration won't continue running if the FireLens container stops for any reason. The `enable-ecs-log-metadata` option enables FireLens to [automatically detect metadata from Fargate](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/task-metadata-endpoint-v3.html) and append it to your logs, such as the ECS cluster and the ECS task definition associated with the container that generated the log.

Then, in the same Fargate task, create a new log configuration that uses AWS FireLens as the log driver and specifies output options for Fluent Bit:

*fargate-task.yaml*
```text

"logConfiguration": {
    "logDriver": "awsfirelens",
    "options": {
        "Name": "datadog",
        "apiKey": "<DATADOG_API_KEY>",
        "dd_service": "my-httpd-service",
        "dd_source": "httpd",
        "dd_tags": "project:example",
        "TLS": "on",
        "provider": "ecs"
    }
}
```

You can find your API key in your [Datadog account](https://app.datadoghq.com/account/settings#api). The `dd_service` and `dd_source` options associate your container logs with a specific service and source in Datadog. The service should be the name of the service that is generating your logs (e.g., my-httpd-service), while the source should be the underlying technology for the service (e.g., httpd). The source option will automatically trigger a log processing pipeline in Datadog for your integration (if [available](https://docs.datadoghq.com/integrations.md#cat-log-collection)). You can also add tags to your logs (e.g., `project:example`) to help you easily find, filter, and analyze them in Datadog. The `provider` option maps metadata from ECS to Datadog tags.

## Monitor your Fargate tasks in Datadog

Whenever a Fargate task runs, Fluent Bit will automatically route the container logs to Datadog so that you can begin monitoring them. These logs contain information about all of the containers managed by your Fargate tasks, including the container name and the associated ECS cluster. Datadog will also automatically ingest any additional tags you've added to your Fluent Bit configuration or Fargate tasks so you can easily sift through and analyze your logs.

![Explore Fargate tasks in Log Explorer](https://web-assets.dd-static.net/42588/1776292547-collect-fargate-logs-with-firelens-new_fargate_logs.png)

If you've enabled Datadog's [Fargate integration](https://docs.datadoghq.com/integrations/ecs_fargate.md), you can monitor your logs alongside metrics from all of your Fargate containers, such as CPU and memory usage. In the [Live Container view](https://docs.datadoghq.com/graphing/infrastructure/livecontainers.md?tab=linuxwindows), resource metrics are graphed at a [two-second resolution](https://www.datadoghq.com/blog/introducing-live-container-monitoring.md#providing-context) so you can detect critical performance spikes in your container infrastructure. You can also easily stream your logs from within any container.

![Creating Datadog dashboard lists](https://web-assets.dd-static.net/42588/1776292552-collect-fargate-logs-with-firelens-ecs_fargate-compressed.mp4)

And with [Autodiscovery](https://docs.datadoghq.com/agent/autodiscovery.md), Datadog automatically detects containerized services on Fargate and configures Datadog Agent checks for 1,000+ [integrations](https://docs.datadoghq.com/integrations.md) like Redis and NGINX, so you can easily start collecting and analyzing key service metrics.

## Start monitoring Fargate tasks with FireLens and Fluent Bit

Datadog's Fluent Bit plugin for FireLens is readily available for forwarding logs from your Fargate applications and provides a seamless way to monitor and explore your logs alongside metrics from your containerized services. See our [AWS Fargate monitoring guide](https://www.datadoghq.com/blog/aws-fargate-metrics.md) for more information and [follow these steps](https://docs.datadoghq.com/integrations/ecs_fargate.md#fluent-bit-and-firelens) to start forwarding logs to Datadog. If you're not yet using Datadog, you can sign up for a <!-- Sign-up trigger (free trial) omitted --> today.