BuildImplementation guide6 min read

AWS Lambda Implementation Guide

By Nicolas Narbais

Make Lambda functions visible with AWS-native metrics, the OpenTelemetry layer, structured logs, and application traces.

Last updated on

Make AWS Lambda functions operationally visible in Tsuga across three progressive levels. Lambda has no host agent or long-lived Collector; the OpenTelemetry Lambda layer embeds a Collector extension directly inside each execution environment.

LevelSignals addedPath
1AWS-native invocations, errors, duration, throttles, concurrencyCloudWatch Metric Stream → Firehose → Tsuga
2Platform/app logs + custom OTLP metricsLambda Telemetry API + OTel layer extension
3Handler traces, dependency spans, propagation, log correlationLanguage auto-instrumentation + manual spans
flowchart LR CW["AWS/Lambda CloudWatch metrics"] --> MS["Metric Stream (OTel 1.0)"] --> FH["Firehose"] --> TM["Tsuga Metrics"] FH -.->|"Failed deliveries"| S3["S3 backup"] RT["Lambda runtime + stdout"] -->|"Telemetry API"| EXT["Lambda Collector extension"] --> TL["Tsuga Logs"] APP["Handler SDK / auto-instrumentation"] -->|"OTLP traces & app metrics"| EXT EXT --> TT["Tsuga Traces & Metrics"]

The three levels separate what you enable, not three separate Collectors. Keep the trace pipeline wired in Level 2, but only call a function trace-instrumented once its handler emits meaningful spans and propagates context downstream.

Before starting

  • Scope: agree on AWS accounts, regions, functions, environments, owners, and any data-residency restrictions.
  • Secrets: store the Tsuga ingestion key in your secret store, never in code, deployment zips, or checked-in Collector YAML.
  • Egress: verify outbound HTTPS to Tsuga (VPC-attached functions need NAT or an approved egress path).
  • Single log route: keep CloudWatch during rollout if needed, but if the Lambda layer ships logs to Tsuga, do not also forward that CloudWatch log group to Tsuga.
  • Identity: lock service.name and deployment.environment.name before expanding past one pilot function.
  • Layer match: pick the exact OpenTelemetry Lambda layer ARN for your runtime, region, and architecture (x86_64 vs arm64).

Choose your Lambda service-identity model

A Lambda function name (faas.name) is AWS infrastructure identity, not automatically your service boundary. Never put environments, mutable aliases, or invocation IDs in service.name.

ModelWhen to useUpsideTradeoff
One function = one serviceIndependently owned, deployed, and alerted functionClean per-function health and SLOsFragments multi-Lambda journeys
Several functions = one bounded service (default)Functions ship and operate as one capabilityUnified traffic, errors, latency, deploymentsRequires grouping by faas.name for function-level regressions

Always preserve automatic faas.name attributes and set immutable release identity via environment variables (use a commit SHA or published Lambda version, never $LATEST or a mutable alias):

OTEL_SERVICE_NAME=<LOGICAL_SERVICE_NAME>
OTEL_RESOURCE_ATTRIBUTES=service.namespace=<TEAM_OR_PRODUCT>,service.version=<IMMUTABLE_BUILD_VERSION>,deployment.environment.name=<ENVIRONMENT>

Level 1 - Stream AWS-native metrics

Stream the AWS/Lambda CloudWatch namespace to Tsuga via a CloudWatch Metric Stream (OpenTelemetry 1.0 format), a Firehose HTTP delivery stream, and an S3 backup for failed deliveries. Restrict the stream to in-scope namespaces (AWS/Lambda first).

This requires zero code, layer, or execution-role changes and immediately gives you:

  • Core health: invocations, errors, duration, throttles, concurrent executions.
  • Trigger-specific signals: dead-letter/async outcomes, provisioned concurrency, and iterator age where applicable.

Build your first dashboard and monitors from these metrics (throttles, sustained errors with an invocation floor, duration jumps), validating in order: Metric Stream → Firehose deliveries/S3 backup → Tsuga Metrics.

Exit criteria: Recent AWS-native invocation, error, duration, and concurrency metrics appear in Tsuga, Firehose retains failures in S3, and on-call can spot throttled or failing functions without code changes.

Level 2 - Add the Lambda layer for logs and app metrics

Attach the matching upstream OpenTelemetry Lambda layer without overwriting existing layers. Point OPENTELEMETRY_COLLECTOR_CONFIG_URI to a packaged config file (fewest runtime dependencies; S3/HTTP adds cold-start fetches) and expose TSUGA_OTLP_ENDPOINT and TSUGA_API_KEY from your secret store:

receivers:
  telemetryapi:
  otlp:
    protocols:
      http:
      grpc:

processors:
  batch:
  decouple:

exporters:
  otlp_http/tsuga:
    endpoint: ${env:TSUGA_OTLP_ENDPOINT}
    headers:
      Authorization: Bearer ${env:TSUGA_API_KEY}

service:
  pipelines:
    logs:
      receivers: [telemetryapi]
      processors: [batch, decouple]
      exporters: [otlp_http/tsuga]
    metrics:
      receivers: [otlp]
      processors: [batch, decouple]
      exporters: [otlp_http/tsuga]
    traces:
      receivers: [otlp]
      processors: [batch, decouple]
      exporters: [otlp_http/tsuga]

Keep decouple so the extension can flush exports after the handler returns before Lambda freezes the sandbox. Keep CloudWatch for AWS-native metrics and use OTLP metrics strictly for custom domain/application metrics; never duplicate the same metric across both paths.

Make log format and ownership explicit

  • Structured JSON: emit one JSON object per line with timestamp, level, stable message, and bounded fields, with no secrets, auth headers, or raw payloads.
  • CloudWatch cutoff: only deny logs:CreateLogGroup, logs:CreateLogStream, and logs:PutLogEvents after validating direct Telemetry API delivery (never during initial rollout).

Invoke once with a unique harmless log token and confirm it appears once in Tsuga with the agreed context.service.name, environment, and Lambda metadata (trace IDs arrive in Level 3).

Exit criteria: Platform and application logs arrive in Tsuga exactly once with correct identity, CloudWatch forwarding is not duplicating records, and any custom OTLP metric is distinct from AWS-native metrics.

Level 3 - Trace handler invocations and dependencies

Enable the OpenTelemetry Lambda layer’s language wrapper/bootstrap so auto-instrumentation loads before your handler and framework (never initialize a second global SDK provider if the layer owns one):

  1. Root invocation span: trigger the function normally and confirm the root span carries the agreed service and environment identity.
  2. Automatic dependency spans: verify AWS SDK, HTTP, and database spans appear without duplicating them manually.
  3. Purposeful manual spans: add small spans only for business work (validate-order, calculate-price). Never put request IDs or payloads in span names.
  4. Cross-boundary propagation: set OTEL_PROPAGATORS=tracecontext,baggage where supported. Keep synchronous API Gateway/HTTP calls in one trace; link asynchronous SQS/EventBridge/SNS consumer spans to the producer context instead of inflating parent-child duration.
  5. Log correlation: configure the runtime logger bridge to emit active trace_id and span_id on every log record.

Keep metric dimensions bounded (route, operation, AWS service, outcome, status) and exclude user IDs, tenant ARNs, request IDs, and message bodies. Test both a normal invocation and a controlled failure to prove trace-to-log and log-to-trace pivots work in both directions.

Exit criteria: Normal and failed invocations produce searchable traces with dependency/business spans, sync and async causality work as intended, logs pivot to traces, and all signals share one identity.

Add monitors and SLOs after Level 3

Pair AWS-native metrics (platform failures and capacity) with trace-derived metrics (user-facing errors and latency):

  • Throttles / concurrency: sustained throttles or concurrency saturation.
  • Error rate: elevated errors paired with a minimum invocation floor.
  • Latency: high handler or end-to-end duration on critical operations.
  • Async backlog: failed async deliveries or rising iterator age.
  • SLOs: base SLOs on customer-visible outcomes (one SLO across a multi-Lambda order service, or per function for a standalone auth Lambda).

Troubleshooting path

SymptomCheck firstFix
Missing AWS-native metricsCloudWatch Metric Stream → Firehose → S3 backupFix stream namespace filter, Firehose intake endpoint, or IAM role
Duplicate logs in TsugaCloudWatch log forwarding vs Telemetry API extensionDisable one of the two Tsuga log routes
Logs arrive, traces are missingLayer wrapper/bootstrap config and local OTLP exportLoad language wrapper before handler; avoid duplicate SDK init
Wrong service.nameOTEL_SERVICE_NAME and OTEL_RESOURCE_ATTRIBUTESStandardize deployment env vars; never rename post-collection
Direct telemetry never arrivesLayer ARN match, OPENTELEMETRY_COLLECTOR_CONFIG_URI, VPC NATVerify runtime/arch ARN, extension errors, and outbound HTTPS

Completion criterion and CLI validation

A known invocation appears as a trace with the agreed service.name and environment, its log arrives exactly once, and the function’s AWS-native metrics are visible for the same window.

# 1. Confirm spans arrived through the Lambda layer
tsuga traces search \
  --query "context.service.name:<service>" \
  --from -15m \
  --to now \
  --max-results 10

# 2. Confirm the test log arrived exactly once
tsuga logs search \
  --query "context.service.name:<service> <unique-log-token>" \
  --from -15m \
  --to now \
  --max-results 10

If command 1 is empty while command 2 returns the log, fix the language wrapper/bootstrap rather than the exporter. If command 2 returns two copies, remove the duplicate CloudWatch log route. Verify Level 1 AWS-native metrics directly in Tsuga Metrics, as CloudWatch-derived metric names differ from raw namespace names.

References

Written by

Nicolas Narbais

Nicolas Narbais builds, breaks, debugs, and scales observability systems using OpenTelemetry and modern telemetry pipelines. He shares practical, opinionated lessons to help engineers get better signal with less noise.

Olatuak Editorial Philosophy

Better signal, not more telemetry.

Olatuak helps platform engineers, SREs, and observability teams turn noisy telemetry into clear operational decisions without blindly collecting more data.

Scroll to zoom · Drag to pan · Double-click to reset