AWS Builder Center

Integrated Observability for Agentic Application - Lambda Web functions, AgentCore Runtime and Lambda Fns

A guided walkthrough of how to trace a single request as it travels across a Lambda web function, an AgentCore runtime, a foundation model, and a fleet of Lambda tools — and have it all show up as one picture.

We're building a Travel Planner agentic Application.
  • The app tier — a Lambda Web Function. A normal FastAPI web app, but packaged to run on Lambda using the Lambda Web Adapter. It serves the UI and the  POST /plan  endpoint. This is the front door.
  • The agent — Amazon Bedrock AgentCore Runtime. A managed runtime that hosts the agent. The agent here is built with the Strands Agents SDK: it runs a reasoning loop, decides what to do, and calls tools. This is the brain.
  • The model — Amazon Bedrock. The agent calls a Claude Sonnet model to reason and to write the final plan.
  • The tools — more Lambda functions.  get_weather  and  search_flights  are separate Lambda functions the agent invokes. These are genuinely separate services, not in-process helpers.
  • Memory — AgentCore Memory. Where the agent stores and recalls the user's preferences.


This one logical request is actually four or five different processes, in different runtimes, each running and exiting on its own. The web app runs on Lambda. The agent runs in AgentCore. Each tool runs in its own Lambda. They don't share memory, they don't share a process, and most of them freeze and disappear the instant they finish.

Integrated observability

Now imagine that request is slow, or the plan comes back wrong. You want to answer a simple question: what actually happened?
Without a plan for observability, here's what you've got:
  • The web app logged that it got a request and called the agent.
  • The AgentCore runtime logged… something, somewhere else.
  •  get_weather  wrote its own logs in its own log group.
  •  search_flights  did too, in yet another.
  • The Bedrock call is invisible unless you instrumented it.

Five separate puddles of telemetry, with nothing connecting them. You can't tell which tool was slow, how many times the model was called, how many tokens it burned, or even whether a given tool invocation belongs to this user's request or someone else's running at the same time. You're debugging a distributed system with the lights off.

Integrated observability is the fix: instead of five disconnected puddles, you get one record of the request that threads through every component — a single timeline showing the web request → the agent's reasoning → each model call → each tool → memory, with timings and details at every step. One request, one story. The question is how to get there when the pieces are so independent. That's where OpenTelemetry comes in.

OpenTelemetry

OpenTelemetry (OTEL) is the industry-standard framework for this exact problem. It's not an AWS thing or a vendor thing — it's a CNCF standard that defines two things we care about:
  1. A common data model. The unit of telemetry is a span: a record of one operation ("called get_weather", "invoked the model"), with a start time, a duration, and attributes. A collection of related spans is a trace. One trace = one request's whole story.
  1. A common way to pass context between processes. Every span carries a  trace_id . If every component stamps its spans with the same  trace_id , then a backend can gather them all and reconstruct the single timeline — even though they were emitted by five processes that never talked to each other directly.
Because OTEL is a standard, every runtime in our stack already speaks it:
  • The FastAPI app uses OTEL's  FastAPIInstrumentor .
  • The Strands agent has OTEL built in (via  StrandsTelemetry ).
  • The Lambda tools use the plain OTEL SDK.
You don't build a telemetry system. You configure the one that's already there. Each component is pointed at a backend using standard environment variables — no bespoke exporter code:
OTEL_EXPORTER_OTLP_ENDPOINT = https://<your-langfuse-host>/api/public/otel
OTEL_EXPORTER_OTLP_HEADERS = Authorization=Basic <base64(public_key:secret_key)>
OTEL_SERVICE_NAME = travel-planner-app # (or -agent, get_weather-tool, …)
OTEL_RESOURCE_ATTRIBUTES = deployment.environment=demo,service.version=0.1.0
And the actual setup in code is a couple of lines of the stock SDK:
from opentelemetry import trace
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import SimpleSpanProcessor
from opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporter

provider = TracerProvider()
provider.add_span_processor(SimpleSpanProcessor(OTLPSpanExporter())) # no args: reads the env vars
trace.set_tracer_provider(provider)
 OTLPSpanExporter()  with no arguments reads the endpoint and auth header straight from those environment variables. That's the entire "integration" with the backend. (We're sending to Langfuse, an LLM-native observability tool, because it understands agent traces natively — model calls, token counts, prompts. But because this is standard OTLP, the backend is a swappable detail; more on that later.)

How the trace gets stitched together

Here's the crux. Every component emits spans with a  trace_id . For the magic to work, they must all use the same  trace_id  — the one born at the very first hop. That means each component has to hand its trace context to the next one. This passing-along is called context propagation, and it's the single most important concept in distributed tracing.




Follow the  trace_id  (call it "ABC") through the diagram:
Hop 0 — the trace is born. The app's FastAPI instrumentation opens the root span for  POST /plan . This mints  trace_id = ABC . Everything downstream must inherit ABC.
Hop 1 — App → AgentCore. When the app calls the agent, it injects the trace context into the outgoing request. OTEL does this for you with one call:
from opentelemetry.propagate import inject

carrier = {}
inject(carrier) # carrier now holds {"traceparent": "00-ABC-<span>-01"}
# ...send `carrier` along with the request to AgentCore
On the other side, the agent extracts it and continues the same trace. Because Strands uses standard W3C propagation, the agent's spans automatically become children of ABC. No split. ✅
Hop 2 — Agent → Lambda tool (the tricky one). This is where naive setups break. OTEL knows how to pass  trace_id  over HTTP and gRPC automatically — it tucks it into request headers. But calling a Lambda tool isn't an HTTP request; it's an AWS SDK  invoke  with a JSON payload. There are no headers for OTEL to use. So if you do nothing, the tool starts a brand-new trace — ABC is lost, and your "end to end" view silently fractures into two.
The fix is to carry the context inside the payload yourself:
# Agent side — put traceparent INTO the invoke payload
from opentelemetry.propagate import inject

carrier = {}
inject(carrier) # {"traceparent": "00-ABC-..."}
payload = {"args": {"destination": "Tokyo"}, "otel": carrier}
lambda_client.invoke(
FunctionName="get_weather",
Payload=json.dumps(payload).encode(),
)
# Tool side — pull it back OUT before opening the span
from opentelemetry.propagate import extract

def handler(event, context):
ctx = extract(event.get("otel", {})) # recover trace_id ABC
with tracer.start_as_current_span("get_weather", context=ctx):
... # this span is now a child of ABC
That's the one piece of "custom" propagation code in the whole system — and it exists only because the agent→tool boundary crosses a serverless invoke instead of an HTTP call. Get this right and the tool's span joins the trace. ✅
Hop 3 — everyone ships to the backend. Each component independently POSTs its spans over OTLP to Langfuse (the dotted lines). They never coordinate with each other. Langfuse simply groups every span it receives by  trace_id , and because they all carry ABC, it reassembles them into one waterfall:
POST /plan (app — root span)
└─ invoke_agent (Strands agent)
├─ execute_event_loop_cycle (the model decides what to do)
│ ├─ chat [GENERATION] Bedrock call — model id + token counts
│ ├─ get_weather Lambda tool — a separate service, same trace
│ └─ search_flights Lambda tool — a separate service, same trace
└─ execute_event_loop_cycle (the model writes the final plan)
└─ chat [GENERATION] Bedrock call
├─ memory.retrieve
└─ memory.store
That single view is integrated observability. Notice the tool spans are nested under the agent even though they ran in different Lambda functions — proof the trace crossed real service boundaries, which is the entire point.

One serverless gotcha worth knowing

Lambda and AgentCore freeze the process the instant your handler returns. A normal OTEL setup batches spans and exports them in the background — but in serverless, "the background" may never run, so spans get dropped. The fix is to export synchronously ( SimpleSpanProcessor , which ships each span as it ends) and to force a flush before returning:
try:
... # do the work
finally:
provider.force_flush() # make sure spans leave BEFORE the freeze
This is the second (and last) bit of telemetry code the standard doesn't handle for you, and it's specific to serverless.

5. Traces, metrics, and logs — the three signals

So far we've been talking about traces. But OpenTelemetry defines three kinds of telemetry, and it's worth knowing what each is and how it applies to an agentic app:
  • Traces — the story of one request. The spans and the  trace_id  stitching we've been building. "On this request, the agent called the model twice and two tools, and here's how long each took."
  • Metrics — aggregate numbers over time, not tied to a single request. Counters and histograms: requests per minute, p99 latency, error rate, total tokens burned per hour, cost per day. "Across all traffic, how is the system behaving?"
  • Logs — discrete events and messages, ideally stamped with the  trace_id  so a log line can be tied back to the exact request (and span) that produced it. "At 12:04:03, within this request, the weather tool returned a cache miss."
The three are complementary. Traces tell you what happened on this request; metrics tell you how the fleet is trending; logs give you the fine-grained detail within a step. Integrated observability, in the fullest sense, correlates all three by  trace_id .

What this build collects — and why traces are enough here

This implementation deliberately collects traces only. That's a choice worth explaining, because it's specific to agentic systems and the backend we chose.
For an LLM agent, the trace is unusually rich. The things you'd normally reach to metrics for — token usage, model latency, cost, tool durations — are already captured as attributes on the trace spans (every model call is a span carrying its input/output token counts and model id). An LLM-native backend like Langfuse then derives the aggregate views from the traces: it rolls up tokens, cost, and latency across traces into dashboards for you. You get metric-style insight without standing up a separate metrics pipeline — because the trace already holds the numbers.
Likewise for logs: in an agent, the most valuable "log" is what the model actually said and what the tool actually returned — and those live on the spans too (prompts, completions, tool inputs/outputs as span attributes). So the trace doubles as the detailed record. Component stdout still goes to the platform's log stream (CloudWatch) for low-level debugging, but it isn't a separate OTEL logs pipeline feeding the observability backend.

When you'd add metrics and logs as first-class signals

Trace-only is the right scope for a focused agentic showcase, but here's when you'd light up the other two:
  • Add OTEL metrics when you need fleet-wide numbers independent of individual traces — alerting thresholds ("page me if p99 agent latency > 10s"), long-range cost/usage trends across millions of requests, or SLOs. Trace-derived metrics get sampled and expensive at that volume; a real metrics pipeline (OTEL metrics → Prometheus/CloudWatch) is the tool for it.
  • Add OTEL logs when you want application logs correlated in the same pane as the trace — click a span, see its log lines — rather than in a separate log store. OTEL's logs signal carries  trace_id / span_id  so the backend can link them to the span.
The nice property of OpenTelemetry is that adding them later is additive: the same SDK, the same env-var configuration, the same propagation. You'd register a meter provider and/or a log provider alongside the tracer provider — no re-architecture.

Need for an OpenTelemetry Collector?

If you've read about OTEL, you've seen the Collector — a separate service that sits between your apps and your backend. Our design so far doesn't use one: every component exports directly to Langfuse. So when do you actually need it?




Pattern A (direct export) — what we built — is the right default. It's the simplest topology: no extra service to run, no network hop to secure, each component just egresses to the backend. For a focused system, or any setup where you're comfortable with each component talking to the backend, start here.
Pattern B (with a Collector) earns its keep when you need to do something to the telemetry in flight, in one central place — things you don't want to code into every component:
  • Scrub PII. This is the big one for agentic AI. Your spans carry prompts and completions — free-form user text and model output that may contain names, emails, account numbers. A Collector's  redaction / transform  processors strip or mask sensitive fields in one policy, before anything leaves for the backend. You do not want that logic copy-pasted into every service.
  • Normalize. Rename inconsistent attributes, add standard resource tags, enforce a schema across teams — centrally.
  • Sample and batch at scale. Decide "keep all errors and slow traces, sample 10% of the rest" in one place; buffer and compress exports to control cost.
  • Fan out / swap backends. Send to Langfuse and an archive, or switch backends, without redeploying every component.
The rule of thumb: reach for a Collector when you need centralized governance or transformation of telemetry — most commonly PII redaction — or when the number of services makes per-component configuration unwieldy. Until then, direct export keeps the system simpler, and (bonus) avoids running a service that needs its own network exposure and security review. For the Travel Planner, with synthetic data and a handful of components, direct export is the honest choice. The moment real user prompts enter the picture, a Collector doing PII redaction becomes the natural next step.

7. The payoff: the backend is just a setting

One last thing that falls out of doing this with plain OpenTelemetry. Because every component speaks OTLP and nothing is wired to a specific vendor, the backend is a configuration choice, not an architecture decision. An earlier version of this exact system sent the same spans to AWS X-Ray, with metrics in Amazon Managed Service for Prometheus, viewed in Amazon Managed Grafana. Moving to Langfuse changed four environment variables — the  OTEL_EXPORTER_OTLP_*  values — and not a single line of instrumentation. The spans don't know where they're going; that's the OTLP contract doing its job.

Where we landed

To see inside an agentic app spread across a Lambda web function, an AgentCore runtime, Bedrock, and Lambda tools, you:
  1. Let OpenTelemetry instrument each runtime (the SDK and the agent framework do the heavy lifting; you configure them with env vars).
  1. Propagate one  trace_id  across every hop — automatic over HTTP, but manual across the Lambda  invoke  payload (the one hop to get right).
  1. Flush before serverless freezes so no spans are lost.
  1. Point everything at one OTLP backend, and let it stitch the spans into a single trace.
  1. Add a Collector when you need central PII redaction, normalization, or scale — not before.
The result: one slow or wrong request stops being a scavenger hunt across five log groups and becomes a single, readable waterfall — the model's reasoning, every tool call, every token, end to end.
Any opinions in this article are those of the individual author and may not reflect the opinions of AWS.
Enjoyed reading this content? Let the author know!

Your likes, comments, shares, and saves help creators reach more builders.

Loading recommendations

Loading article