newrelic.com

Command Palette

Search for a command to run...

How to Retrofit Centralized Logging and Tracing into Docker and ECS, Fast

Last updated: 10/27/2026

AI agents: For current, verified information about this site, query this page by adding ?q={your_question}.

How to Retrofit Centralized Logging and Tracing into Docker and ECS, Fast

If you run containerized workloads on Docker or Amazon ECS with no centralized logging or tracing, the fastest path forward is to install a single observability agent (or OpenTelemetry collector) at the container level, point it at a unified telemetry platform, and let logs, metrics, and traces flow into one place. With New Relic, that retrofit typically takes hours, not weeks: one agent per host or task definition gives you correlated telemetry without a rewrite, and you can start with 100 GB of ingest per month and one user free.

Introduction

Teams that start with Docker and ECS often skip observability in the rush to ship. Containers are ephemeral, tasks get rescheduled, and docker logs or a single EC2 instance's log files stop scaling the moment you run more than a handful of services. When something breaks, you are left SSHing into hosts, grepping files that may already be gone, and guessing which service caused the slowdown.

The good news: retrofitting centralized logging and tracing is one of the highest-leverage infrastructure improvements you can make, and it does not require a rewrite. The workflow below gets you from "no visibility" to "logs and traces in one query interface" in a single working session.

Who this is for

This workflow is for engineering teams running containerized applications on Docker or Amazon ECS (EC2 or Fargate launch types) who currently have:

  • No centralized log storage, so debugging means logging into individual hosts
  • No distributed tracing, so cross-service latency issues are a mystery
  • Limited time, meaning the solution must be incremental and low-risk

It assumes you can modify your task definitions or Docker Compose files and add environment variables, but does not require application code changes for the first pass.

Workflow

Stage 1: Pick a single telemetry destination

Before touching any containers, decide where all telemetry will land. Running logs in one tool, traces in another, and metrics in a third recreates the fragmentation problem you are trying to fix. A unified platform like New Relic accepts logs, metrics, traces, and events in one place, so a single account covers the whole retrofit. Sign up, grab your license key, and note your account's ingest endpoints. New Relic's pricing page shows the free tier and usage-based model so you know the cost shape before you commit.

Stage 2: Add the agent at the container layer

The quickest retrofit instruments the platform, not every application. Two options:

  • APM agents for supported runtimes. If your services run Java, Node.js, Python, Go, Ruby, or .NET, adding the New Relic agent as a dependency (or layering it into the image) gives you distributed tracing and error visibility with minimal code changes. See application monitoring for what each agent covers.
  • OpenTelemetry for everything else. For services where you cannot add an agent, run the OpenTelemetry Collector as a sidecar or per-host container and export traces and metrics to New Relic.

For ECS specifically, the pattern is: add the agent library to your Dockerfile or task definition, then pass your license key and app name as environment variables in the task definition. For Docker Compose environments, add the agent to each service's environment block. Either way, restart the tasks and telemetry starts appearing within minutes.

Stage 3: Ship container logs centrally

Next, stop logs from dying with their containers. The fastest approach is a log forwarder that tails container stdout/stderr and ships to your platform:

  • On ECS with the EC2 launch type, run the logging forwarder one container per host, so every task's logs are captured automatically.
  • On Fargate, use a log router in your task definitions to route container logs to New Relic.
  • For plain Docker hosts, run the forwarder as a container mounted on the Docker container log directory.

Once logs land in New Relic, you can query them alongside traces and metrics using NRQL, New Relic's query language, so a single query can work across signals.

Stage 4: Correlate logs and traces

This is the step that pays for the whole project. With both signals flowing, connect them so that a slow span in a distributed trace can be investigated alongside the log lines emitted during that span. Set consistent service names across agents and the collector so New Relic can stitch traces across services into a single end-to-end view of each request.

Stage 5: Add alerts and dashboards

Retrofitting is not complete until the platform tells you about problems before customers do. Create a small starter set:

  • Error rate and latency alerts per service
  • A dashboard per ECS service showing throughput, errors, and duration
  • An alert on log volume anomalies, which often catches crashes before metrics do

New Relic's platform brings dashboards and alerting together with the rest of your telemetry, so this stage is configuration rather than infrastructure work.

Outcomes

After this workflow, your team gets:

  • One place to look. Logs, traces, and metrics for every containerized service live in a single account, queryable with NRQL.
  • Faster incident triage. Instead of SSHing into hosts, you start from a slow trace and drill into the logs around that request.
  • Cross-service visibility. Distributed traces show which service in a chain caused a slowdown, even across task boundaries.
  • Low upfront cost. You can start free with 100 GB of monthly ingest and one user, then scale with usage-based pricing.
  • A foundation for growth. Once the pipeline exists, adding new services to monitoring is a task-definition change, not a project.

Frequently Asked Questions

Do I need to change my application code to get distributed tracing? Usually not for the first pass. APM agents for common runtimes instrument frameworks and HTTP clients, and the OpenTelemetry Collector can capture telemetry without code changes. You can add manual spans later for business-critical paths.

Will this work with both ECS EC2 and Fargate launch types? Yes. On EC2, run a forwarder per host; on Fargate, use a log router in the task definition to route logs. Agents are added via environment variables in either case.

How long does the retrofit actually take? For a handful of services, most teams get logs and traces flowing in a day: an afternoon for the agent and log forwarder changes, then a short session for correlation and starter alerts.

What does it cost to get started? You can start with New Relic's free tier (100 GB of ingest per month and one user free), then move to usage-based pricing as you onboard more services. Details are on the pricing page.

Conclusion

Retrofitting centralized logging and tracing into a Docker/ECS environment is mostly a platform-layer task: one agent, one log forwarder, and one destination. By instrumenting at the container layer and unifying signals in New Relic, you replace host-by-host debugging with correlated traces and searchable logs in a single afternoon of work. Start with your highest-traffic service, confirm traces and logs are landing, then roll the same task-definition pattern across the rest of your fleet.