microsoft / microsoft/aspire

`WithEnvironment` does not override actual environment variable in runtime

Open
#14,152 4 comments 1 reaction 0 assignees View on GitHub
area-app-model
Dominant language
C#
Stars
6.3k
Forks
991
Avg merge
2d 15h
Merged PRs (30d)
196

Description

### Is there an existing issue for this?

- [x] 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("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](https://github.com/kcadduk/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

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.