---
title: Set Up the Agent's Collector on ECS Fargate
description: Datadog, the leading service for cloud-scale monitoring.
breadcrumbs: >-
  Docs > OpenTelemetry in Datadog > Send OpenTelemetry Data to Datadog > DDOT
  Collector > Install > Set Up the Agent's Collector on ECS Fargate
---

> For the complete documentation index, see [llms.txt](https://docs.datadoghq.com/llms.txt).

# Set Up the Agent's Collector on ECS Fargate

## Overview{% #overview %}

Deploy the Agent's Collector on Amazon ECS Fargate. The Agent's Collector is the OpenTelemetry Collector that runs alongside the Datadog Agent as a separate process. Because ECS Fargate does not support host-based deployments, the Datadog Agent runs as a sidecar container in the same ECS task as your application.

{% alert level="info" %}
**Need additional OpenTelemetry components?** If you need components beyond those included in the default package, follow [Add Components to the Agent's Collector](https://docs.datadoghq.com/opentelemetry/setup/ddot_collector/custom_components.md) to extend the Datadog Agent's capabilities. For a list of components included by default, see [OpenTelemetry Collector components](https://docs.datadoghq.com/opentelemetry/agent.md#opentelemetry-collector-components).
{% /alert %}

## Requirements{% #requirements %}

To complete this guide, you need the following:

**Datadog account**:

1. [Create a Datadog account](https://www.datadoghq.com/free-datadog-trial/) if you don't have one.
1. Find or create your [Datadog API key](https://app.datadoghq.com/organization-settings/api-keys/).

**AWS**:

- An AWS account with access to Amazon ECS Fargate.
- The [AWS CLI](https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html) configured with permissions to create and manage ECS task definitions and services.

**Network**: Allow traffic to the ports used by the configured export path:

| Export path                                  | Protocol             | Default port | Destination                                   |
| -------------------------------------------- | -------------------- | ------------ | --------------------------------------------- |
| Traces, metrics, and logs exported over OTLP | OTLP (gRPC/HTTP)     | 4317 / 4318  | Datadog Agent OTLP receiver or DDOT Collector |
| Traces exported in Datadog format            | Datadog trace intake | 8126 (TCP)   | Datadog Trace Agent                           |
| Runtime metrics exported through DogStatsD   | DogStatsD            | 8125 (UDP)   | DogStatsD server                              |

If the OTLP receiver uses a different port, allow traffic to that port instead.

## Install the Datadog Agent with OpenTelemetry Collector{% #install-the-datadog-agent-with-opentelemetry-collector %}

{% alert level="info" %}
This installation is required for both DDOT SDK + Agent's Collector and upstream OpenTelemetry SDK + Agent's Collector configurations. In this route, the Agent's Collector receives and forwards OTLP metrics and logs.
{% /alert %}

### Create an ECS task definition{% #create-an-ecs-task-definition %}

On ECS Fargate, the Datadog Agent and your application run as containers within the same ECS task. Create an ECS task definition that includes both containers.

{% alert level="info" %}
The Datadog Agent image must be `public.ecr.aws/datadog/agent:latest-full`. The `latest-full` image includes the Agent's Collector. The standard `latest` image does not.
{% /alert %}

Use the following task definition as a starting point:

In the `task-definition.json` file:

```json
{
    "family": "<TASK_FAMILY>",
    "containerDefinitions": [
        {
            "name": "datadog-agent",
            "image": "public.ecr.aws/datadog/agent:latest-full",
            "essential": true,
            "cpu": 0,
            "environment": [
                {
                    "name": "ECS_FARGATE",
                    "value": "true"
                },
                {
                    "name": "DD_LOGS_ENABLED",
                    "value": "true"
                },
                {
                    "name": "DD_OTELCOLLECTOR_ENABLED",
                    "value": "true"
                },
                {
                    "name": "DD_OTELCOLLECTOR_INSTALLATION_METHOD",
                    "value": "ecs-fargate"
                },
                {
                    "name": "DD_SITE",
                    "value": "<DATADOG_SITE>"
                },
                {
                    "name": "DD_LOGS_CONFIG_CONTAINER_COLLECT_ALL",
                    "value": "true"
                }
            ],
            "secrets": [
                {
                    "name": "DD_API_KEY",
                    "valueFrom": "<DD_API_KEY_SECRET_ARN>"
                }
            ],
            "logConfiguration": {
                "logDriver": "awslogs",
                "options": {
                    "awslogs-group": "/ecs/<TASK_FAMILY>",
                    "awslogs-create-group": "true",
                    "awslogs-region": "<AWS_REGION>",
                    "awslogs-stream-prefix": "ecs"
                }
            },
            "mountPoints": [],
            "portMappings": [],
            "volumesFrom": []
        },
        {
            "name": "<APP_CONTAINER_NAME>",
            "image": "<APP_IMAGE>",
            "essential": true,
            "cpu": 0,
            "environment": [
                {
                    "name": "OTEL_SERVICE_NAME",
                    "value": "<SERVICE_NAME>"
                },
                {
                    "name": "OTEL_RESOURCE_ATTRIBUTES",
                    "value": "service.version=<VERSION>,deployment.environment.name=<ENV>"
                }
            ],
            "logConfiguration": {
                "logDriver": "awslogs",
                "options": {
                    "awslogs-group": "/ecs/<TASK_FAMILY>",
                    "awslogs-create-group": "true",
                    "awslogs-region": "<AWS_REGION>",
                    "awslogs-stream-prefix": "ecs"
                }
            },
            "mountPoints": [],
            "portMappings": [],
            "volumesFrom": []
        }
    ],
    "executionRoleArn": "<EXECUTION_ROLE_ARN>",
    "networkMode": "awsvpc",
    "volumes": [],
    "requiresCompatibilities": [
        "FARGATE"
    ],
    "cpu": "256",
    "memory": "512"
}
```

Replace the following placeholders:

- `<TASK_FAMILY>`: A name for your ECS task definition family.
- `<DD_API_KEY_SECRET_ARN>`: The ARN of the AWS Secrets Manager secret or SSM Parameter Store parameter that contains your Datadog API key. The task execution role must have `secretsmanager:GetSecretValue` (Secrets Manager) or `ssm:GetParameters` (SSM) permission to retrieve the secret.
- `<DATADOG_SITE>`: Your [Datadog site](https://docs.datadoghq.com/getting_started/site.md). Your site is <YOUR_DATADOG_SITE>. (Ensure the correct DATADOG SITE is selected on the right.)
- `<AWS_REGION>`: The AWS region where your ECS tasks run (for example, `us-east-1`).
- `<APP_CONTAINER_NAME>`: The name of your application container.
- `<APP_IMAGE>`: Your application container image.
- `<SERVICE_NAME>`: The name of your service.
- `<VERSION>`: The version of your service.
- `<ENV>`: Your deployment environment (for example, `production`).
- `<EXECUTION_ROLE_ARN>`: The ARN of your ECS task execution IAM role.

### Configure ECS resource detection{% #configure-ecs-resource-detection %}

The `infraattributes` processor in the Agent's Collector enriches your telemetry with ECS infrastructure tags when the `aws.ecs.task.arn` resource attribute is present. To provide this attribute, add the ECS resource detector to your OpenTelemetry SDK.

The ECS resource detector automatically populates the following attributes:

- `aws.ecs.task.arn`
- `aws.ecs.launchtype` (set to `fargate`)
- `cloud.provider`

Refer to your language's OpenTelemetry SDK documentation to add the ECS resource detector. For example:

- **Go**: [go.opentelemetry.io/contrib/detectors/aws/ecs](https://pkg.go.dev/go.opentelemetry.io/contrib/detectors/aws/ecs#NewResourceDetector)
- **All languages**: See the [ECS resource detector documentation](https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/main/processor/resourcedetectionprocessor/internal/aws/ecs/documentation.md) in the OpenTelemetry Collector contrib repository.

### Use a custom Collector configuration{% #use-a-custom-collector-configuration %}

The default configuration of the Agent's Collector supports standard OTLP ingestion. To customize the pipeline, for example to add a processor that drops specific metrics, provide your own `otel-config.yaml`.

The Agent's Collector always loads its configuration from a fixed path inside the container: `/etc/datadog-agent/otel-config.yaml`. Because ECS Fargate doesn't support host volumes, build a custom image that includes your configuration at this path:

1. Create your `otel-config.yaml` file with the pipeline you need.

1. Create a `Dockerfile` that copies your configuration into the Datadog Agent image:

In the `Dockerfile` file:

   ```dockerfile
   FROM public.ecr.aws/datadog/agent:latest-full
   COPY otel-config.yaml /etc/datadog-agent/otel-config.yaml
```

1. Build the image and push it to a container registry that your ECS task can access, such as Amazon ECR:

   ```bash
   docker build -t <YOUR_REGISTRY>/datadog-agent-ddot:<TAG> .
   docker push <YOUR_REGISTRY>/datadog-agent-ddot:<TAG>
```

1. In your task definition, set the `datadog-agent` container's `image` field to your custom image instead of `public.ecr.aws/datadog/agent:latest-full`.

Repeat this process for each Agent version upgrade to keep the Agent's Collector version compatible with the rest of the image.

{% alert level="info" %}
The Datadog Agent's entrypoint always starts the Agent's Collector with `--config /etc/datadog-agent/otel-config.yaml`. Passing a configuration through an environment variable, such as an OpenTelemetry Collector `env:` configuration provider, is not supported on ECS Fargate.
{% /alert %}

To add OpenTelemetry components not included by default, see [Add Components to the Agent's Collector](https://docs.datadoghq.com/opentelemetry/setup/ddot_collector/custom_components.md).

## Send your telemetry to Datadog{% #send-your-telemetry-to-datadog %}

To send your telemetry data to Datadog:

1. Instrument your application
1. Configure the application
1. Correlate observability data
1. Run your application

### Instrument the application{% #instrument-the-application %}

Instrument your application [using the OpenTelemetry API](https://docs.datadoghq.com/tracing/trace_collection/custom_instrumentation/otel_instrumentation.md).

{% collapsible-section %}
Example application instrumented with the OpenTelemetry API
As an example, you can use the [Calendar sample application](https://github.com/DataDog/opentelemetry-examples/tree/main/apps/rest-services/java/calendar) that's already instrumented for you. The following code instruments the [CalendarService.getDate()](https://github.com/DataDog/opentelemetry-examples/blob/main/apps/rest-services/java/calendar/src/main/java/com/otel/service/CalendarService.java#L27-L48) method using the OpenTelemetry annotations and API:

In the `CalendarService.java` file:

```java
@WithSpan(kind = SpanKind.CLIENT)
public String getDate() {
    Span span = Span.current();
    span.setAttribute("peer.service", "random-date-service");
    ...
}
```

{% /collapsible-section %}

### Configure the application{% #configure-the-application %}

Because the Agent's Collector runs in a sidecar container in the same ECS task, your application sends OTLP data to `localhost`. Add the following environment variables to your application container in the task definition:

In the `task-definition.json` file:

```json
{
    "name": "OTEL_EXPORTER_OTLP_ENDPOINT",
    "value": "http://localhost:4317"
},
{
    "name": "OTEL_EXPORTER_OTLP_PROTOCOL",
    "value": "grpc"
}
```

### Correlate observability data{% #correlate-observability-data %}

[Unified service tagging](https://docs.datadoghq.com/getting_started/tagging/unified_service_tagging.md) ties observability data together in Datadog so you can navigate across metrics, traces, and logs with consistent tags.

The `OTEL_SERVICE_NAME` and `OTEL_RESOURCE_ATTRIBUTES` environment variables in the task definition above configure unified service tagging.

### Run the application{% #run-the-application %}

1. Register the task definition with AWS:

   ```bash
   aws ecs register-task-definition --cli-input-json file://task-definition.json
```

1. If you don't have an ECS cluster, create one:

   ```bash
   aws ecs create-cluster --cluster-name <CLUSTER_NAME>
```

1. Create an ECS service to run the task:

   ```bash
   aws ecs create-service \
     --cluster <CLUSTER_NAME> \
     --service-name <SERVICE_NAME> \
     --task-definition <TASK_FAMILY> \
     --desired-count 1 \
     --launch-type FARGATE \
     --network-configuration "awsvpcConfiguration={subnets=[<SUBNET_IDS>],securityGroups=[<SECURITY_GROUP_IDS>],assignPublicIp=ENABLED}"
```

Replace `<CLUSTER_NAME>` with your ECS cluster name, `<SERVICE_NAME>` with a name for your ECS service, `<SUBNET_IDS>` with your subnet IDs (comma-separated), and `<SECURITY_GROUP_IDS>` with your security group IDs.

If you are updating an existing service to a new task definition revision, run:

   ```bash
   aws ecs update-service \
     --cluster <CLUSTER_NAME> \
     --service <SERVICE_NAME> \
     --task-definition <TASK_FAMILY>
```

After the task starts, unified service tagging is fully enabled for your metrics, traces, and logs.

### Validate the deployment{% #validate-the-deployment %}

1. Verify that your ECS task is running and both containers are in `RUNNING` state:

   ```shell
   aws ecs describe-tasks \
     --cluster <CLUSTER_NAME> \
     --tasks <TASK_ID> \
     --query "tasks[0].containers[*].{name:name,status:lastStatus}" \
     --output table
   ```

Use Datadog to explore the observability data for your application.

### Logs{% #logs %}

View logs to monitor and troubleshoot application and system operations.

{% image
   source="https://docs.dd-static.net/images/opentelemetry/embedded_collector/logs.3399501b14c5a2c7bf9ab8dd4aa8bf52.png?auto=format&fit=max&w=850 1x, https://docs.dd-static.net/images/opentelemetry/embedded_collector/logs.3399501b14c5a2c7bf9ab8dd4aa8bf52.png?auto=format&fit=max&w=850&dpr=2 2x"
   alt="View logs from the Log Explorer." /%}

### Traces{% #traces %}

View traces and spans to observe the status and performance of requests processed by your application, with infrastructure metrics correlated in the same trace.

{% image
   source="https://docs.dd-static.net/images/opentelemetry/embedded_collector/traces.0dfe8b50575dbfcea5b0d06131826db9.png?auto=format&fit=max&w=850 1x, https://docs.dd-static.net/images/opentelemetry/embedded_collector/traces.0dfe8b50575dbfcea5b0d06131826db9.png?auto=format&fit=max&w=850&dpr=2 2x"
   alt="View traces from the Trace Explorer." /%}

### Runtime metrics{% #runtime-metrics %}

Monitor your runtime (JVM) metrics for your applications.

{% image
   source="https://docs.dd-static.net/images/opentelemetry/embedded_collector/metrics.1f91a119276f91ecfb2976f16eed58ef.png?auto=format&fit=max&w=850 1x, https://docs.dd-static.net/images/opentelemetry/embedded_collector/metrics.1f91a119276f91ecfb2976f16eed58ef.png?auto=format&fit=max&w=850&dpr=2 2x"
   alt="View JVM metrics from the JVM Metrics dashboard" /%}

### Collector health metrics{% #collector-health-metrics %}

View metrics from the Agent's Collector to monitor the Collector health.

{% image
   source="https://docs.dd-static.net/images/opentelemetry/embedded_collector/dashboard.f6e65b6b9a8708b1a7e172da215947af.png?auto=format&fit=max&w=850 1x, https://docs.dd-static.net/images/opentelemetry/embedded_collector/dashboard.f6e65b6b9a8708b1a7e172da215947af.png?auto=format&fit=max&w=850&dpr=2 2x"
   alt="View Collector health metrics from the OTel dashboard." /%}

## Further reading{% #further-reading %}

Additional helpful documentation, links, and articles:

- [Add Components to the Agent's Collector](https://docs.datadoghq.com/opentelemetry/setup/ddot_collector/custom_components.md)
