opentelemetry-go icon indicating copy to clipboard operation
opentelemetry-go copied to clipboard

Feature request: span/ metric exporter initialization ignoring environment

Open rob0rt opened this issue 1 year ago • 2 comments

Problem Statement

When deploying to a shared environment, it's possible that the system's environment variables are polluted with other application's OTel configuration that could cause issue during the exporter initialization. For example:

  • OTEL_RESOURCE_ATTRIBUTES may include extra values not desired in the application's attribute configuration
  • OTEL_EXPORTER_OTLP_ENDPOINT might set the protocol to http (insecure), which the SDK currently provides no mechanism to override back to secure (see #1344)

Proposed Solution

  • An entirely new API for otlptracehttp.New or otlpmetrichttp.New (-> NewWithoutEnv) which do not read from the environment
    • Add a new option WithEnvironment, WithDefault?
  • Add an option to the existing API WithoutEnv

Alternatives

Currently the only alternative I've found is to call os.Unsetenv and explicitly remove the polluting environment variables

Prior Art

The resource APIs currently offer a means to initialize without inheriting values from the Environment.

  • resource.Default uses the environment, or when creating a resource explicitly one can use resource.WithFromEnv()

Additional Context

n/a

rob0rt avatar Apr 09 '24 21:04 rob0rt

If you do not want to use an environment variable, use the os.Unsetenv function.

MrAlias avatar Apr 09 '24 21:04 MrAlias

If you do not want to use an environment variable, use the os.Unsetenv function.

I called that out in Alternatives, and is the approach I ended up going with in my application as a workaround.

rob0rt avatar Apr 09 '24 21:04 rob0rt