Tracing AWS Lambda functions with OpenTelemetry
OpenTelemetry for AWS Lambda gives a team a way to trace serverless functions with community instrumentation layers for Java, JavaScript, Python and Ruby, which export telemetry from each function invocation. The layers attach to the function at deploy time, so application code often needs little or no change to produce spans for the function's own work. Teams that run several Lambda functions behind API Gateway, queues, or event sources, and that cannot yet follow one request from end to end, are the usual candidates. Teams that want the trace data to stay portable across vendors are another, because the instrumentation follows the open standard rather than one monitoring product.
OpenTelemetry is not an observability backend. It generates and exports traces, metrics and logs, but it does not store or visualize them, so a separate tool such as Jaeger, Grafana with a trace store, or a commercial platform must receive the data. Before choosing one, confirm which backend your organization already runs, whether it accepts OTLP directly from a function or needs a Collector in between, and who owns its retention and access rules. Those answers decide whether the function exports straight to the backend or through a Collector, which changes network paths, credentials and the cost of each invocation.
The Java, JavaScript, Python and Ruby layers do not include the Collector. Teams must either add the Collector as a separate layer or configure an external Collector that the functions export to. Check the current layer versions and their supported runtimes in the OpenTelemetry documentation before you pin them, because layer releases and the runtimes they support change over time. Confirm also that each team's function runtime is on the supported list, since a team running a runtime outside that list will need a different path.
Which Lambda runtimes the community layers cover
The community instrumentation layer covers Java functions. Teams running Java on Lambda should plan for the layer to be attached to each function and for the agent's startup work to be measured against the function's memory and timeout settings. Java is often the runtime where cold start effects are most visible, so the trial should run on a configuration close to production.
- Layer attachment: Add the Java instrumentation layer to each function version you deploy, usually through your infrastructure as code.
- Handler and wrapper settings: Confirm the handler and wrapper configuration described in the layer documentation for your packaging method.
- Memory and timeout: Test cold starts at the memory size you plan to run, since agent startup adds work to initialization.
- Collector choice: Decide whether the Collector layer or an external Collector receives Java spans.
Confirm the current Java layer version and the supported Java versions in the OpenTelemetry Lambda documentation before you pin a version.
The community layer covers JavaScript functions, including Node.js handlers. Teams should check how their bundler, package manager and module format interact with the layer, because instrumentation depends on how libraries are loaded. Plan a test function that mirrors your build pipeline before rolling the layer across a service.
- Module format: Check whether your handlers use CommonJS or ES modules, since loading behavior differs and the layer documentation describes the supported setup.
- Bundling: If you bundle with a tool that inlines dependencies, verify that instrumented libraries are still detected at runtime.
- Dependency versions: Record the versions of the HTTP client, database and messaging libraries your functions call, and test them against the layer.
- Coverage gaps: Expect some libraries to need manual spans, and list those in advance.
Confirm the supported Node.js runtime versions and the layer's library coverage in the OpenTelemetry Lambda documentation.
The community layer covers Python functions. Python teams often run a mix of frameworks and packaging methods, so the first step is to inventory how each function is packaged, either as a zip archive or a container image, and to test the layer against each method your organization uses.
- Packaging method: Confirm whether the layer fits your zip or container image deployments, because the setup steps differ.
- Library versions: Check that the instrumented libraries your functions import are within the versions the layer documentation lists.
- Dependency conflicts: Test for conflicts between the layer's packages and your own pinned dependencies.
- Logs signal: Confirm the state of log export for Python in the OpenTelemetry status information before counting on it for log correlation.
Confirm the supported Python versions and the current layer version in the OpenTelemetry Lambda documentation.
The community layer covers Ruby functions. Ruby teams should confirm the layer version against their Ruby runtime and gem set, since gem compatibility is the usual source of trouble. Because Ruby coverage is the narrowest of the four, check the supported instrumentation list before committing to tracing across every function.
- Runtime version: Confirm the Ruby runtime your functions use is listed as supported for the layer version you plan to deploy.
- Gem compatibility: Test the instrumented gems your functions use, especially database and HTTP clients.
- Bundler setup: Confirm how the layer loads with your Gemfile and bundle configuration.
- Coverage check: Compare the instrumented libraries against what your functions call, and plan manual spans for gaps.
Confirm the current Ruby support and layer version in the OpenTelemetry Lambda documentation before you plan rollout.
The community instrumentation layers do not cover runtimes outside Java, JavaScript, Python and Ruby. Functions in Go, .NET, PHP, custom runtimes or other languages need a different path, and that path should be chosen during planning rather than discovered during rollout. Teams with mixed runtimes should split the plan by language so each group gets a suitable approach.
- Inventory: List every function by runtime, packaging and owning team before choosing a path.
- Manual SDK instrumentation: Functions in a language with an SDK may be instrumented in code, which adds build and release work.
- External Collector path: Decide whether one Collector configuration will receive spans from all functions regardless of runtime.
- Mixed estates: Keep the trace context format consistent across runtimes so that spans from different functions join into one trace.
Confirm the runtimes each option supports with the OpenTelemetry documentation for that language before you commit to a path.
Layer Collector or external Collector: how to choose
The community instrumentation layers for Java, JavaScript, Python and Ruby do not include the OpenTelemetry Collector. You must either add the Collector as a separate layer, so it runs inside each function's execution environment, or configure the function to export to a Collector you run outside Lambda. That choice is the first design decision for this topic, and it shapes credentials, network placement, failure handling and ownership. Confirm the current layer ARNs and the Collector layer's supported configuration in the OpenTelemetry Lambda documentation before you pin versions in your infrastructure code.
The layer path keeps each function self-contained. Telemetry leaves the function from its own environment, the deployment is one artifact per function, and no shared service has to exist before tracing works. The costs fall inside the invocation: export work, retries and any batching happen while the function is running, so exporter latency and export failures show up in function duration and billing. An external Collector moves processing, retries and credentials out of the invocation path. Functions send to a service you operate, typically in a VPC subnet that can reach your backends, and that service holds the backend tokens rather than every function role. The trade-off is a new production component with its own scaling, patching, availability and on-call rota that must exist before any trace is useful.
Work through four questions with your security and platform teams. Credentials: a layer keeps backend keys in each function's configuration or secrets store, while an external Collector concentrates them in one place, which can also be authenticated with the Collector's authenticator extensions. Network placement: decide whether functions need VPC attachment to reach a private Collector, and what that does to cold start. Export failures: decide whether a backend outage should slow functions, drop data, or buffer it, and test that behavior under load. Ownership: name who patches the Collector, who changes its configuration and who gets paged when telemetry stops. Ask your team to document the answers for each function group before rollout.
Configuration options and when each fits
This table compares three ways to get Lambda traces out of a function: the instrumentation layer alone, the instrumentation layer with the Collector layer, and the instrumentation layer with an external Collector. Read each row against your own export path, since the right choice depends on where data must go, how much you can tolerate losing, and who operates the Collector.
| Option | Where configuration lives | What happens on export failure | Network and VPC requirements | Typical fit |
|---|---|---|---|---|
| Instrumentation layer only | Environment variables on each function pointing the exporter at an endpoint you manage | Spans are exported directly from the function, so an unreachable endpoint means lost spans and added time inside the invocation | Function must reach the backend endpoint directly, usually through a NAT gateway or endpoint if it runs in a VPC | Small estates with few functions and a backend reachable without a Collector |
| Instrumentation layer plus Collector layer | Collector configuration file packaged with or referenced by the function, updated with each deployment | The local Collector buffers and retries within the execution environment, so data can be lost if the function freezes or stops first | Function still needs outbound access to the backend, so VPC egress and security group rules must allow it | Teams that want processing (for example redaction) inside each function without running shared infrastructure |
| Instrumentation layer with external Collector (agent) | Collector configuration on a host or sidecar in the same VPC, changed without redeploying functions | Failures are handled by the Collector, which can retry and queue, but the function still hands off data first | Function must reach the Collector endpoint privately, so subnets, security groups and routing to the agent must be designed | Teams that need central control of pipelines and a single place to tune buffering |
| Instrumentation layer with external Collector (gateway) | Collector configuration on a shared gateway service that many functions and accounts send to | The gateway can buffer, retry and reroute data, but a gateway outage affects every sender at once | Requires private connectivity from function subnets to the gateway, plus capacity planning for combined traffic | Organizations with many functions, several accounts or regulated data that must be filtered before leaving the network |
| Cold start and latency impact | Set by the layer and configuration chosen, so confirm the effect in a test environment with your own function sizes | Synchronous export adds work to the invocation, so check timeouts and flush behavior for each option | Network path to the collector adds latency that appears in cold start measurements | Benchmark each option on representative functions before choosing a default |
How cold starts change the cost of tracing
Adding a layer adds work to every cold start. An instrumentation layer for Java, JavaScript, Python or Ruby loads its own code and initializes the SDK before your handler runs, and that initialization sits inside the init phase that Lambda bills and that a cold request waits on. If you also add the Collector layer or run the Collector inside the function, the Collector process starts in the same window. Warm invocations pay much less of this, so the cost of tracing shows up mostly in the first request after a new execution environment starts. Treat the init phase as part of the tracing budget, not as a free side effect.
An in-function Collector can also add time to invocations. When the Collector runs as a layer, the function's spans leave through an exporter that runs alongside your code, and export work can compete with the handler for CPU and memory, especially when batches are flushed at the end of an invocation. The factors that move these numbers are the runtime and its startup profile, how many layers you stack, the configured memory size (which sets the CPU share the function receives), and the batching and export settings such as the batch span processor's timeout and queue size. Check the current behavior of each setting against the OpenTelemetry Lambda documentation before you rely on it.
Measure before you roll out, and benchmark your own functions. This section gives no timing figures, because init duration and invocation overhead depend on your runtime version, handler size, memory setting, region and traffic pattern. Record the init duration, billed duration, p95 and p99 latency and error rate for each function on the current configuration, then repeat the same measurements with the layer and Collector settings you plan to use, forcing cold starts with configuration changes or low traffic. Run the comparison at the memory sizes you actually use. Ask your vendor or partner to provide the benchmark method and results for your functions in writing so the decision rests on your data.
Setting up OpenTelemetry on a Lambda function
This sequence takes one Lambda function from an uninstrumented baseline to traced invocations with correct parent-child links, and it checks cold start and duration against a measured baseline before any production alias changes. Each step ends with a check the team can repeat on the next function.
Confirm the runtime and choose the instrumentation layer
The platform team checks the function's runtime against the community instrumentation layers for Java, JavaScript, Python and Ruby. Those are the four runtimes the community layers cover, so a function on another runtime needs a different path, such as the SDK inside the deployment package. Record the runtime version, architecture and handler in the change ticket. The step is done when the team can name the exact layer version it will attach and the owner who will maintain that pin. Confirm the layer version against the OpenTelemetry Lambda documentation, since layer releases are published separately from the Collector.
Decide between the Collector layer and an external Collector
The community instrumentation layers do not include the Collector, so the team must pick one of two paths. The first adds the Collector as a separate Lambda layer inside the function, which keeps export local to each invocation but adds packaging and init work to every cold start. The second sends data to a Collector the team runs elsewhere, such as a gateway in its own VPC, which moves that work out of the function but needs network reachability and a decision on how the endpoint is authenticated. Write the choice down with the cold start and network trade-offs the team accepted. The step is done when the design note names the path and the endpoint owner.
Attach the layers and set the wrapper configuration
The engineer attaches the instrumentation layer, and the Collector layer if that path was chosen, to the function version used for testing, then sets the handler wrapper that the layer documentation specifies for the runtime. Export settings go in environment variables on the function, not in code: the OTLP endpoint, the service name, and the protocol. Keep credentials out of these variables and use the secrets handling your platform already provides. The step is done when a test invocation returns the expected response and the function logs show the instrumentation starting without errors. If the handler is not wrapped, no spans are produced and the logs usually say nothing, so check the handler value first.
Set the export endpoint and service name
The engineer sets the endpoint and service name as environment variables and confirms that the function can reach the endpoint through its subnet, security groups and any egress path. Use one service name per function and a naming pattern the operations team already uses, so dashboards and alerts stay consistent across functions. If an external Collector is used, confirm that its receiver is bound to an address the function can reach, because current Collector releases bind server components to localhost by default. The step is done when a test invocation shows no export errors in the function logs and the Collector or backend reports at least one trace from the new service name.
Deploy to a non-production alias
The engineer publishes the configured function version and points a non-production alias at it, so production traffic keeps using the existing version. Run a representative set of test events, including a success path, a handled error and a path that calls a downstream service. The step is done when the alias is serving test traffic, the rollback target is recorded, and the team has confirmed that the function's business output matches the output of the previous version. Do not move the production alias until the next two steps pass.
Verify spans and parent-child links in the backend
The engineer opens the tracing backend and finds traces from the test invocations. For each trace, check that the function's invocation span is the root, that calls to downstream services appear as child spans, and that the span names and attributes match what the code does. A broken parent-child link often shows up as a separate trace for a downstream call that should belong to the invocation. Check that the trace ID appears in the function logs if log correlation is in scope. The step is done when a sample of at least several traces, including an error case, shows correct nesting and the team can explain any missing spans.
Compare duration and cold start against a baseline
Before the change, the team records invocation duration and cold start behavior for the same function on the same alias configuration, using the platform's own metrics. After the change, it repeats the same test pattern, including forced cold starts, and compares the results. Expect the layer and export path to add some initialization time, and decide in advance how much added latency the function can accept. If the increase is too large, the team can review the layer choice, the batching and export settings, or the external Collector path before promotion. The step is done when the team has a written comparison and a go or no-go decision recorded against the agreed threshold.
Promote the alias and keep the rollback path
After the verification and performance checks pass, the engineer moves the production alias to the new version and keeps the previous version available as the rollback target. The operations team adds a dashboard or alert for export errors and for duration changes on the function, and records the layer version pin in the team's deployment repository so future upgrades are deliberate. The step is done when production traffic is on the new version, the alerts are active, and the rollback steps have been written down and tested in a non-production environment.
How telemetry flows from a Lambda invocation to the backend
The flow starts when Lambda invokes the function. The instrumentation layer loaded with the handler creates spans and exports them over OTLP. Because the community instrumentation layers do not include the Collector, the data goes either to a Collector layer inside the function's environment or to an external Collector you run. Credentials for exporting sit with the Collector, not the handler, so check where they are stored and who can read them. The trust boundary sits at your AWS account and VPC, and the backend is outside it.
Telemetry leaves the function through a Collector you place inside your boundary.
Securing Lambda telemetry pipelines
A Lambda function that exports telemetry to a Collector creates a new path for data to leave your account. The cards below cover the controls that keep that path safe, from where configuration lives to what the function is allowed to read. Each one maps to guidance in the OpenTelemetry Collector security best practices.
Store Collector configuration securely
Collector configuration can contain endpoints, tokens and processor rules, so treat it as sensitive. Keep it in a controlled store rather than baked into a deployment artifact that many people can read. Confirm who can change the configuration, how changes are reviewed, and whether the Collector reads values from secret references instead of plain text. For Lambda, check where the external Collector's config lives and who can update it.
Collector security practicesEncrypt and authenticate exports
Telemetry leaving the function or the external Collector should use TLS and an authenticated connection to the backend. Collector authenticator extensions can authenticate incoming connections, for example with OIDC, and add credentials to outgoing exporter requests, such as through the oauth2client extension. Confirm that receivers reject unauthenticated callers and that exporter credentials rotate on a schedule you can operate.
Collector configuration docsBuild with only needed components
The Collector Builder lets you compile a distribution that includes only the receivers, processors and exporters your pipeline uses. A smaller binary exposes less code and fewer components to review and patch. If you run an external Collector for Lambda, confirm which components your build includes and which contrib components you actually need, then rebuild when the pipeline changes.
Redact sensitive attributes
Instrumentation can capture request payloads, headers, query strings and user identifiers as span attributes or log bodies. Use the redaction processor to remove or mask attributes that carry personal data or secrets before export. Test with real function traffic in a non-production account, because the attributes that matter often come from business code rather than the library defaults.
Keep server components off all interfaces
Since Collector v0.110.0, server components bind to localhost by default rather than to all interfaces. Keep it that way unless a specific receiver needs wider access, and then restrict that access with network rules and authentication. In Lambda, verify that any Collector endpoint you expose is reachable only from the function's network path and that no receiver listens on a public address.
Scope IAM and secrets for the function
The function's execution role should grant only what the instrumentation needs, such as permission to read the secret that holds an exporter token and nothing broader. Store credentials in a secrets service and grant read access to a single secret ARN. Review the role whenever you add a layer, and confirm that developers who change function code cannot silently widen the telemetry path's permissions.
Questions teams ask before rolling out Lambda tracing
What effort does an OpenTelemetry Lambda rollout take, and what drives it?
The effort depends mainly on how many runtimes you run, which Collector pattern you choose, which backend receives the data, and how much security review the rollout must pass. A single-runtime estate with one backend and a standard Collector layer is far smaller work than several runtimes, each with different handlers, IAM roles and networking, feeding a backend that needs new access controls. The community instrumentation layers cover Java, JavaScript, Python and Ruby, so any function on another runtime needs a different approach before it can be scoped. Ask for a written scope that lists each runtime, function group and backend, because those lines set the work. Your own team and an implementation partner both carry the same drivers, so the scope document is the fair basis for comparison.
Can our in-house team roll out Lambda tracing without a partner?
Often yes, if the team already runs Lambda in production, manages IAM and networking for those functions, and has someone who owns the telemetry backend. The layer setup itself is configuration: you attach the instrumentation layer for the runtime, set the environment variables that point to your exporter, and confirm that traces arrive. The harder parts are the decisions around it: whether to use a Collector layer or an external Collector, how to handle secrets and endpoints, how to keep the layer versions current, and how to pass a security review. Check whether your team has capacity to own those decisions for the life of the platform, not just the first deployment. A partner is most useful when those decisions must be documented and reviewed by security or compliance teams.
What do we need to provide before the work starts?
Start with a function inventory: each function's name, runtime and version, trigger type, VPC attachment, memory setting and the team that owns it. Then gather network details, including whether functions run inside a VPC, which egress paths reach your backend, and whether a Collector would sit inside the same network. You also need access to the telemetry backend, including endpoints, credentials handling and the ability to create test data, plus a named owner for each function group who can approve changes. For IAM, expect to provide roles that can read the configuration and deploy layers in a test account first. Missing any of these usually shows up as delay during implementation, so collect them before the scope is signed.
How do we measure cold starts when tracing Lambda functions?
Measure cold starts by comparing initialization duration and total invocation duration for the same function with and without the instrumentation layer, using the same memory setting, runtime and traffic pattern. Lambda reports initialization for cold invocations in its logs and in the platform metrics, so you can separate the added initialization time from the handler time. Run the comparison in a non-production account first, force cold starts by publishing a new version or waiting out idle periods, and repeat the tests enough times to see variation. Record the layer version, Collector choice and memory size alongside each result, because each changes the baseline. Treat the numbers as your own measurements. The OpenTelemetry Lambda documentation explains the setup, and your results will show whether the added startup time is acceptable for each function.
Can we change the Collector choice after the rollout starts?
Yes, but the change touches configuration in every instrumented function, so plan it as a deliberate migration rather than a quick edit. The main options are the Collector layer, which runs alongside each function, and an external Collector that functions send data to over the network. Each has different effects on cold start time, network paths, retry behavior and who operates the Collector. Moving between them changes environment variables, egress rules and sometimes IAM permissions, so test the new path on a sample of functions before switching the rest. Keep the Collector configuration in version control from the start, so the processing rules and exporter settings move with the change. Teams that design the Collector pattern up front and document the reason for it usually find later changes simpler to review.
What security review questions come up for Lambda telemetry?
Reviewers usually ask where telemetry leaves the function, what sensitive data it might carry, and who can change the Collector configuration. Trace attributes can capture request fields, headers or payload fragments, so decide which attributes to drop or redact before data leaves your account. Store exporter credentials in a managed secrets service rather than in plain function configuration, and review which principals can read or update the layer and environment settings. If you run an external Collector, the OpenTelemetry security guidance recommends encrypting and authenticating its endpoints, building it with only the components you need, and using the redaction processor for sensitive attributes. Collector authenticator extensions can authenticate incoming connections and add credentials to outgoing exports, which helps with those reviews. Confirm each control against your own policy rather than assuming the layer provides it.
Does the community Lambda layer include the Collector?
No. The community instrumentation layers for Java, JavaScript, Python and Ruby do not include the Collector. You must add the Collector as a separate layer, or configure an external Collector that the function exports to. Decide this early, because it sets the network path, the operations owner and the configuration files your team must maintain. The OpenTelemetry Lambda documentation describes both setups and the configuration each one needs. Confirm the current layer versions and ARNs in that documentation at the time you build, since they change with releases.
Where to read the official guidance
Start with the OpenTelemetry Lambda auto-instrumentation documentation before you touch a function configuration. It explains which community instrumentation layers exist for Java, JavaScript, Python and Ruby, and it makes clear that these layers do not include the Collector. That gap is the first decision you will face: either add the Collector as a separate layer or point the instrumentation at an external Collector you run yourself. Read the page with your runtime in front of you, confirm the layer names and versions for that runtime in the current release notes, and note which environment variables the page says to set, since those are the settings your deployment template will carry.
The Collector configuration guidance is the second read, and it matters most if you choose an external Collector. It covers how receivers, processors and exporters fit together, and it sets out the security expectations: store configuration securely, encrypt and authenticate endpoints, build only the components you need, and use the redaction processor to strip sensitive attributes before data leaves your boundary. Read the authenticator extension material next, because a Lambda function sending spans to an endpoint you control needs a defined way to authenticate. Before you commit to either pattern, confirm the stability level of each Collector component you plan to use, since the README for each component documents it.
How DeployOpen scopes and delivers Lambda tracing
DeployOpen plans, implements, tests, documents and supports OpenTelemetry tracing for AWS Lambda functions inside your own AWS accounts. Engagements start with a written scope that fixes the runtimes, layers, Collector topology and deliverables before any function is changed.
How we scope
- Inventory every function by runtime, including Java, JavaScript, Python, Ruby and any unsupported runtimes that need another approach.
- Agree in writing whether the Collector runs as an added layer or as an external Collector, with the reasons for that choice.
- Confirm which backend receives traces, the cold start budget per function and the AWS accounts, Regions and IAM roles in scope.
How we build
- Add the community instrumentation layer and the Collector layer to a pilot function, then set environment variables through your infrastructure-as-code tooling.
- Test trace propagation across synchronous and asynchronous invocations, and measure cold start effects in a staging account before rollout.
- Apply redaction and export settings so request payloads and credentials stay out of exported spans, and check the result against the written scope.
How we hand over
- Deliver infrastructure-as-code for layers, configuration and IAM permissions, along with a record of the versions pinned during the build.
- Document the runbook for adding a new function, rotating credentials, and checking that traces reach the backend.
- Walk your platform and security teams through the test results and the configuration decisions behind each function.
How we support
- Support is available as a retainer covering layer version updates, runtime changes and periodic checks of trace coverage.
- Ask any quote to state who maintains the Collector configuration after handover and how upgrades are tested first.
- Confirm with your team and the layer documentation which runtime and layer versions your functions currently use before the build begins.

