Skip to content

🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.

chore(deploy): tag dd-trace telemetry with ECS task_arn via DD_TAGS (LFE-11028) (#15286)

Niklas Semmler194134086f44
diff --git a/web/entrypoint.sh b/web/entrypoint.sh
index 9061847427..d8d53a1098 100644
--- a/web/entrypoint.sh
+++ b/web/entrypoint.sh
@@ -124,5 +124,24 @@ if [ $status -ne 0 ]; then
exit $status
fi
+# On ECS, resolve the task ARN from the container metadata endpoint and append
+# it to DD_TAGS so dd-trace stamps tracer telemetry (runtime metrics, spans)
+# with task_arn. The full ARN exact-match joins with EventBridge's taskArn
+# field and Datadog's ECS task_arn tag convention. Reuses the separator
+# DD_TAGS already uses (comma or space). Best-effort, bounded to ~2s total:
+# on any failure DD_TAGS is left untouched and startup proceeds — this block
+# never fails boot.
+if [ -n "$ECS_CONTAINER_METADATA_URI_V4" ]; then
+ _task_arn=$(timeout 2 wget -T 2 -qO- "${ECS_CONTAINER_METADATA_URI_V4}/task" | sed -n 's/.*"TaskARN"[[:space:]]*:[[:space:]]*"\([^"]*\)".*/\1/p')
+ if [ -n "$_task_arn" ]; then
+ case "$DD_TAGS" in
+ *,*) _sep="," ;;
+ *" "*) _sep=" " ;;
+ *) _sep="," ;;
+ esac
+ export DD_TAGS="${DD_TAGS:+${DD_TAGS}${_sep}}task_arn:${_task_arn}"
+ fi
+fi
+
# Run the command passed to the docker image on start
exec "$@"
diff --git a/worker/entrypoint.sh b/worker/entrypoint.sh
index a372cfab32..8f3d10cae7 100644
--- a/worker/entrypoint.sh
+++ b/worker/entrypoint.sh
@@ -19,5 +19,21 @@ if [ -z "$DATABASE_URL" ]; then
fi
fi
+# On ECS, append task_arn:<full TaskARN> from the container metadata endpoint
+# to DD_TAGS, reusing its existing separator (bounded ~2s total; never fails
+# boot). Full ARN exact-match joins with EventBridge taskArn / Datadog's ECS
+# task_arn tag convention.
+if [ -n "$ECS_CONTAINER_METADATA_URI_V4" ]; then
+ _task_arn=$(timeout 2 wget -T 2 -qO- "${ECS_CONTAINER_METADATA_URI_V4}/task" | sed -n 's/.*"TaskARN"[[:space:]]*:[[:space:]]*"\([^"]*\)".*/\1/p')
+ if [ -n "$_task_arn" ]; then
+ case "$DD_TAGS" in
+ *,*) _sep="," ;;
+ *" "*) _sep=" " ;;
+ *) _sep="," ;;
+ esac
+ export DD_TAGS="${DD_TAGS:+${DD_TAGS}${_sep}}task_arn:${_task_arn}"
+ fi
+fi
+
# Run the command passed to the docker image on start
exec "$@"