Expert guidance for configuring and deploying the OpenTelemetry Collector. Use when setting up a Collector pipeline, configuring receivers, exporters, or processors, deploying a Collector to Kubernetes or Docker, or forwarding telemetry to Dash0. Triggers on requests involving collector, pipeline, OTLP receiver, exporter, or Dash0 collector setup.
88%
Does it follow best practices?
Impact
97%
1.15xAverage score across 14 eval scenarios
Low
Low-risk findings worth noting
AWS Lambda functions are instrumented by attaching Lambda layers and setting environment variables on the function configuration, not by adding an SDK bootstrap file to the deployment package.
Lambda freezes the execution environment as soon as the handler returns.
Any telemetry still buffered in the process at that moment is lost, so the standard long-lived BatchSpanProcessor setup described in the SDK rules is wrong here.
Both supported paths solve this with an external Lambda extension — a separate process in the execution environment — that owns the export, which is why layers are mandatory for anything but hand-written instrumentation.
This file is the entry point. It carries the decision process and everything that is the same on both paths; the path-specific configuration lives in one of two files:
| Path | File |
|---|---|
| A — OpenTelemetry layers | AWS Lambda with upstream OpenTelemetry layers |
| B — Dash0 layers | AWS Lambda with the Dash0 Lambda Extension |
Follow these steps in order. Stop at the first match.
dash0-extension-manual layer, which exports for you and resolves DASH0_TOKEN_SECRET_ARN at runtime; otherwise attach the upstream Collector layer and write a Collector configuration.| Path A: upstream layers | Path B: Dash0 extension | Manual SDK | |
|---|---|---|---|
| Runtimes | Node.js, Python, Java, Ruby | Node.js, Python, Java | Any |
| Layers attached | Instrumentation, Collector, configuration | Dash0 extension | Collector or dash0-extension-manual |
| Code changes | None | None | Handler wrapping and provider setup |
| Backends | Any OTLP endpoint, several at once | Dash0 | Any OTLP endpoint |
| Signals | Traces from the layer, logs from the Collector's telemetryapi receiver, metrics only if the app emits them | Traces, metrics, logs | Whatever you instrument |
| Container image packaging | Copy /opt from the layer | Copy /opt from the published extension image | Yes |
| Auth token location | Function environment, readable through lambda:GetFunctionConfiguration | Secrets Manager, resolved at runtime | Depends on the exporter layer |
Go and .NET have no upstream instrumentation layer.
Instrument in code, and attach a layer that owns the export so the handler never blocks on a round trip to the backend: the upstream Collector layer, or dash0-extension-manual when Dash0 is the only backend.
Both run as external Lambda extensions — separate processes in the execution environment — so the in-process SDK exports over loopback and the upstream call happens on the extension's lifecycle rather than the handler's.
Do not set AWS_LAMBDA_EXEC_WRAPPER on this path, there is no wrapper script to run.
Setting OTEL_EXPORTER_OTLP_ENDPOINT is required here: nothing configures the SDK for you, so point it at the exporter layer on loopback explicitly and ensure the SDK flushes the telemetry before returning the response.
Pick the endpoint by the layer the function attaches:
| Exporter layer | OTEL_EXPORTER_OTLP_PROTOCOL | OTEL_EXPORTER_OTLP_ENDPOINT |
|---|---|---|
dash0-extension-manual | http/protobuf | http://127.0.0.1:9009 |
| Upstream Collector layer | http/protobuf | http://localhost:4318 |
| Upstream Collector layer | grpc | http://localhost:4317 |
dash0-extension-manual accepts only OTLP/HTTP on port 9009, and nothing listens on ports 4317 or 4318 when it is the only exporter layer: an SDK pointed there exports nothing, without an error in the function logs.
Set up the tracer provider as described in Go instrumentation, then wrap the handler.
otellambda.WithFlusher is what makes this work on Lambda: it forces a flush at the end of every invocation, before the execution environment freezes.
import (
"github.com/aws/aws-lambda-go/lambda"
awsconfig "github.com/aws/aws-sdk-go-v2/config"
// The detector package is also named `lambda`; alias it to avoid the collision.
lambdadetector "go.opentelemetry.io/contrib/detectors/aws/lambda"
"go.opentelemetry.io/contrib/instrumentation/github.com/aws/aws-lambda-go/otellambda"
"go.opentelemetry.io/contrib/instrumentation/github.com/aws/aws-sdk-go-v2/otelaws"
"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/sdk/resource"
sdktrace "go.opentelemetry.io/otel/sdk/trace"
)
func main() {
ctx := context.Background()
detector := lambdadetector.NewResourceDetector()
res, err := resource.New(ctx, resource.WithDetectors(detector))
if err != nil {
log.Fatalf("resource detection failed: %v", err)
}
tp := sdktrace.NewTracerProvider(
sdktrace.WithBatcher(exporter),
sdktrace.WithResource(res),
)
otel.SetTracerProvider(tp)
// Instrument downstream AWS SDK v2 calls.
cfg, err := awsconfig.LoadDefaultConfig(ctx)
if err != nil {
log.Fatalf("aws config failed: %v", err)
}
otelaws.AppendMiddlewares(&cfg.APIOptions)
lambda.Start(otellambda.InstrumentHandler(handleRequest,
otellambda.WithTracerProvider(tp),
otellambda.WithFlusher(tp),
))
}The AWS Lambda resource detector does not set faas.id or cloud.account.id, because neither is available outside an invocation.
The handler instrumentation sets them as span attributes instead.
This may require normalization with the transform processor in the observability pipeline.
By default otellambda starts a new trace per invocation.
For asynchronous triggers that carry trace context in the payload — SQS, SNS, Kinesis, EventBridge — pass otellambda.WithEventToCarrier so context propagates across the queue instead of breaking the trace at the boundary.
Set up the SDK as described in .NET instrumentation, then apply the four Lambda-specific requirements below. Omitting any of them produces a function that succeeds while exporting nothing.
OpenTelemetry.Instrumentation.AWSLambda.
Add .AddAWSLambdaConfigurations() to the tracer provider and make the configured handler AWSLambdaWrapper.TraceAsync(tracerProvider, OriginalHandler, input, context).
AddAWSLambdaConfigurations() is also what supplies the faas.* and cloud.* resource attributes on this path — without an instrumentation layer, nothing else sets them.PassThrough, so Lambda always passes a not-sampled _X_AMZN_TRACE_ID.
The AWS Lambda instrumentation honors that header by default and drops every span.
Set options.DisableAwsXRayContextExtraction = true on AddAWSLambdaConfigurations.OTEL_EXPORTER_OTLP_PROTOCOL=http/protobuf gives a gRPC client talking to an HTTP receiver and no telemetry.
With dash0-extension-manual, set that variable and use http://127.0.0.1:9009.
With the upstream Collector layer, either set that variable and use http://localhost:4318, or leave the default gRPC protocol and use http://localhost:4317.AWSLambdaWrapper.TraceAsync ends the invocation span and then calls tracerProvider.ForceFlush(), so every span of the invocation is exported in one batch before the environment freezes.
Do not call tracerProvider.ForceFlush() inside the original handler: it runs before the invocation span ends, so the child spans, such as the HttpClient CLIENT span, are exported in a batch without it, and dash0-extension-manual discards a batch that has no invocation span.
The wrapper does not know about the meter provider: call meterProvider.ForceFlush() in a finally block of the original handler.var tracerProvider = Sdk.CreateTracerProviderBuilder()
.AddAWSLambdaConfigurations(options => options.DisableAwsXRayContextExtraction = true)
.AddHttpClientInstrumentation()
.AddOtlpExporter()
.Build();
var meterProvider = Sdk.CreateMeterProviderBuilder()
.AddOtlpExporter()
.Build();
// Configured Lambda handler: Assembly::Namespace.Type::TracingHandler
public async Task<Response> TracingHandler(Request input, ILambdaContext context)
=> await AWSLambdaWrapper.TraceAsync(tracerProvider, Handler, input, context);
public async Task<Response> Handler(Request input, ILambdaContext context)
{
try { /* ... */ }
finally { meterProvider.ForceFlush(); }
}The function's configured handler must be the wrapper method, in the form Assembly::Namespace.Type::Method.
Pointing the handler at the original method bypasses the instrumentation entirely.
Lambda layers cannot be attached to a container-image function, but a layer is a tarball that AWS unpacks into /opt.
Copy the same contents into the image in a multi-stage build and set the same environment variables, and both paths work unchanged.
/opt out of each of the three upstream layers the same way and set the path A environment variables.The platform and the layers supply the FaaS and cloud attributes automatically. Do not set these by hand:
| Attribute | Source |
|---|---|
faas.name | The function name |
faas.version | The function version or alias |
faas.instance | The execution environment |
cloud.provider | aws |
cloud.region | The function's region |
cloud.account.id | Resolved per invocation from the invocation context |
Set the service identity attributes explicitly:
OTEL_SERVICE_NAME=checkout
OTEL_RESOURCE_ATTRIBUTES=service.namespace=shop,service.version=1.4.2,deployment.environment.name=productionWhen OTEL_SERVICE_NAME is unset, service.name falls back to the function name.
That is wrong whenever several functions make up one logical service: checkout-create, checkout-confirm, and checkout-refund are three functions and one service, and leaving the default splits them into three unrelated services in the backend.
Set OTEL_SERVICE_NAME to the service, and let faas.name carry the function identity.
On path A the Collector layer's telemetryapi receiver builds its own resource that does not carry these attributes, see the telemetryapi receiver builds its own resource.
See resolving configuration values for how to derive each value from the codebase, and the faas and aws namespace rows in attributes for the full attribute registry.
aws lambda invoke --function-name <name> /dev/null.
A cold start is required for the layer to initialize, so invoke after the configuration update, not before.service.name and a populated faas.name.
Group the spans by instrumentation scope: the scope name is what identifies which instrumentation produced each span, and it is the only reliable way to tell a missing instrumentation from a missing layer.
See validation for the full backend validation gate.These apply on every path. For path-specific mistakes see the upstream layers and Dash0 extension anti-pattern lists.
BatchSpanProcessor without a force flush in a hand-instrumented function.
Lambda freezes the execution environment the moment the handler returns, and the queued spans are lost.
Use otellambda.WithFlusher in Go, or the equivalent end-of-invocation flush in other runtimes.ResourceNotFoundException.Active.
The X-Ray SDK and OpenTelemetry compete for the trace context; set PassThrough.OTEL_SERVICE_NAME unset.
service.name falls back to the function name, which splits a multi-function service into several unrelated services in the backend..tessl-plugin
skills
otel-collector
otel-instrumentation
otel-ottl
otel-semantic-conventions