Skip to content

feat: support resource detector auto-configuration with OTEL_GO_DETECTORS env var #2438

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

ezhang6811
Copy link

This PR allows AWS resource detectors to be initialized upon startup via the OTEL_GO_DETECTORS environment variable. The known values are "all", "ec2", "ecs", "eks", and "lambda". See #2434 for more context.

Order of priority is similar to that of OTEL_PHP_DETECTORS variable in PHP. If "all" is present, return all detectors. Else, iterate through the list and add instances of recognized detectors. Unrecognized or empty values will be ignored.

@ezhang6811 ezhang6811 requested a review from a team as a code owner June 21, 2025 23:20
@MrAlias
Copy link
Contributor

MrAlias commented Jun 25, 2025

This PR introduces an unfair bias to support only AWS resource detectors. I do not think it should be accepted as proposed.

Why not just use the WithResourceAttributes in your setup code that supplies attributes from any detector you want to use?

@ezhang6811
Copy link
Author

I'm not sure that WithResourceAttributes covers this use case, as it doesn't support dynamic resource detection and only adds static key-values, which should already be covered by OTEL_RESOURCE_ATTRIBUTES.

Our goal is to provide AWS customers running Go applications with a tracing experience similar to that of other languages which already support auto resource detection out of the box. Other vendors are welcome to add their own resource detectors on top of this implementation.

Would it help remove the "all" option as to not suggest that AWS resource detectors are exclusively covered by this env var?

@MrAlias
Copy link
Contributor

MrAlias commented Jun 25, 2025

I'm not sure that WithResourceAttributes covers this use case, as it doesn't support dynamic resource detection and only adds static key-values, which should already be covered by OTEL_RESOURCE_ATTRIBUTES.

Resource detection is done once and the attributes are static after Detect returns. Why doesn't this act the same way?

// detector is a composite resource.Detector defined by the user.
attr, err := detector.Detect(ctx)
// handle err
otelsdk.NewHandler(ctx, otelsdk.WithResourceAttributes(attrs...))

@ezhang6811
Copy link
Author

That's true, but why would the user initialize their own TraceHandler if they want to use the autoinstrumentation? Writing application code in order to manage resource detection defeats the purpose of zero-code instrumentation.

@MrAlias
Copy link
Contributor

MrAlias commented Jun 25, 2025

I see. If you want to add a solution to the default that is shipped here it needs to follow the OpenTelemetry tenet of being vendor neutral.

If you would like to provide only a AWS focused solution, feel free to build your own distribution on top of this project as that is its intended design.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants