-
Notifications
You must be signed in to change notification settings - Fork 900
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
Env variable vs code - precedence #4413
Comments
We discussed this previously with respect to resource attribute precedence, but did not come to a definite conclusion. |
In Go the code has precedence over env vars in most of the cases. In think that it offers more fine-grained control. In "options" configuration code has precedence over env vars. E.g. https://pkg.go.dev/go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp#WithEndpoint For "auto" packages the env var is used and accepts a default value which is used when env var is not set: https://pkg.go.dev/go.opentelemetry.io/contrib/propagators/autoprop#NewTextMapPropagator. But one can say that this a special API which is designed explicitly to support env vars. If users does not want to support env var, they simply do not use the "auto" package. In my opinion, this makes Go to favor code over env vars. |
In java code has precedence. In fact, env variables are completely ignored unless you use a dedicated autoconfigure package. |
Languages that treat explicit code config as higher precedence than ENV
Language that treat ENV variable as higher precedence
|
Erlang/Elixir is a third way. Configuration is one of the first things the SDK constructs on boot. It is built from both environment variables and Erlang's Application environment ( Reading configuration on boot and not in each process when it starts is common practice. This is for cleaner code and so that configuration that can be changed at runtime is only exposed through functions/messages to the process, rather than the user being able to set new configuration with We don't expect people to ever bring SDK pieces up in code except in extreme situations, doing it through configuration means OpenTelemetry can boot fully before any other part of the program boots. Eh, I suppose this is really just "code take precedence" and I could have saved a lot of your time. Since the user can either read and pass the environment configuration or not this is still done in code... so yea, code takes precedence. |
Related to #3929 which is proposing to make ENV variable support RECOMMENDED, and not optional.
I'd like to also ask if spec would make a recommendation on order of precedence when something is specified programmatically and Env variable.
For example:
Pseudo Code:
var exporter. = new OTLPExporter();
exporter.EndPoint = "http://endpoint-from-code"
ENV Variable specifies endpoint as "http://endpoint-from-env"
Which one should the application respect? The one from CODE or the one from ENV variable? Based on my exploration, each language follows its own way and there is no consistency here.
(I'll try to find any prior discussions on this and add here)
The text was updated successfully, but these errors were encountered: