Skip to content

feat(collector): add resourcedetectionprocessor with minimal env+lambda fork - #2160

Draft
RaphaelManke wants to merge 1 commit into
open-telemetry:mainfrom
RaphaelManke:lambda-resource-detectors
Draft

RaphaelManke wants to merge 1 commit into
open-telemetry:mainfrom
RaphaelManke:lambda-resource-detectors

Conversation

@RaphaelManke

Copy link
Copy Markdown
Contributor

Summary

Fixes #2047OTEL_RESOURCE_ATTRIBUTES is not picked up by the collector layer.

This PR adds the resourcedetectionprocessor to the default collector build, with two detectors enabled:

  • env — reads OTEL_RESOURCE_ATTRIBUTES and merges the key/value pairs into the resource of every span, metric and log
  • lambda — auto-populates faas.*, cloud.* and aws.log.* attributes from Lambda environment variables (AWS_LAMBDA_FUNCTION_NAME, AWS_REGION, AWS_LAMBDA_FUNCTION_MEMORY_SIZE, etc.)

The binary size problem — and how it's solved

The upstream resourcedetectionprocessor from opentelemetry-collector-contrib compiles 26 cloud-provider detectors into every binary (EC2, ECS, EKS, GCP, Kubernetes, Docker, Azure, DigitalOcean, Hetzner, Consul, OpenShift, …). For a Lambda layer that only needs env and lambda, this pulls in ~100 MB of transitive cloud SDK dependencies with no benefit.

To avoid this, a minimal local fork is shipped under collector/lambdacomponents/processor/resourcedetectionprocessor/ containing only the env and lambda detectors. The fork is wired into the build via a replace directive in lambdacomponents/go.mod — no import paths in application code change.

Binary size comparison (GOOS=linux GOARCH=amd64, -trimpath)

Build Size Delta
No resourcedetectionprocessor (baseline) 66.63 MiB
This PR — minimal fork, env + lambda only 66.75 MiB +121 KiB
Full upstream, all 26 detectors 167.37 MiB +100.7 MiB

The minimal fork adds 121 KiB over the baseline — effectively zero overhead — while the full upstream would more than double the binary size.

Keeping the fork in sync

The fork is maintained via two patch files and a sync script:

File Purpose
factory.patch Strips the 24 unused detector imports/registrations from factory.go
config.patch Strips unused detector config structs from config.go
sync-from-upstream.sh Fetches all upstream files and applies the patches

make build runs the sync automatically against the opentelemetry-collector-contrib version declared in lambdacomponents/go.mod. Upgrading to a new upstream release is:

# bump version in lambdacomponents/go.mod, then:
make build
# if patches fail to apply, the script prints how to regenerate them

Test plan

  • go build ./... in collector/lambdacomponents/ compiles cleanly
  • GOOS=linux GOARCH=amd64 go build -trimpath of the full binary succeeds
  • sync-from-upstream.sh v0.145.0 fetches, patches and tidies without errors
  • Binary size confirmed at 66.75 MiB vs 66.63 MiB baseline (+121 KiB)
  • Manual test: set OTEL_RESOURCE_ATTRIBUTES=deployment.environment.name=dev on a Lambda and verify the attribute appears in exported telemetry

…da fork

Adds the resourcedetectionprocessor to the default collector build to fix
OTEL_RESOURCE_ATTRIBUTES not being picked up (ref open-telemetry#2047). The env detector
reads OTEL_RESOURCE_ATTRIBUTES and merges those attributes into every span,
metric and log resource. The lambda detector adds faas.*, cloud.* and aws.*
attributes from Lambda environment variables.

The upstream resourcedetectionprocessor bundles 26 cloud-provider detectors
(EC2, ECS, EKS, GCP, Kubernetes, Docker, Azure, DigitalOcean, etc.) which
pull in ~100 MB of cloud SDK dependencies. To avoid this, a minimal local
fork is shipped under lambdacomponents/processor/resourcedetectionprocessor/
containing only the env and lambda detectors, kept in sync with upstream via
patch files and a sync script. make build re-syncs automatically.

Binary size (GOOS=linux GOARCH=amd64, -trimpath, no ldflags stripping):
  No resourcedetectionprocessor (baseline): 66.63 MiB
  Minimal fork, env+lambda only (this PR):  66.75 MiB  (+121 KiB)
  Full upstream, all 26 detectors:         167.37 MiB  (+100.7 MiB)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Awaiting Author

Development

Successfully merging this pull request may close these issues.

Telemetryapi receiver not respecting OTEL_RESOURCE_ATTRIBUTES env var

2 participants