Skip to content

WithEnvironment does not override actual environment variable in runtime #14152

@kcadduk

Description

@kcadduk

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

Setting the OTEL endpoint via WithEnvironment is reflected in the Aspire Dashboard, but the application ignores it at runtime. For example:

builder.AddProject<Api>("weather-api") .WithEnvironment("OTEL_EXPORTER_OTLP_ENDPOINT","http://localhost:4317");

Dashboard shows http://localhost:4317 for OTEL_EXPORTER_OTLP_ENDPOINT

Runtime actually uses a different endpoint like http://localhost:62312

This prevents redirecting traces to a custom OTEL collector.

Notes:

I have not called AddOpenTelemetryCollector(...), per previous feedback (#11298) that WithEnvironment should suffice. It's not needed to reproduce the problem. However if used, the behaviour is exactly the same.

The discrepancy is between what Aspire reports and the actual environment in the running app.

Repo for reproduction: AspireOtelDemo

Expected Behavior

WithEnvironment should respect the configured OTEL endpoint

Steps To Reproduce

As Above

Exceptions (if any)

None

.NET Version info

9 & 10

Anything else?

None

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-app-modelIssues pertaining to the APIs in Aspire.Hosting, e.g. DistributedApplication

    Type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions