Make OTLP Configuration Optional Instead of Disabled in Publish Mode
- 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
### Is your feature request related to a problem? Please describe the problem.
Currently, in OtlpConfigurationExtensions.cs, OTLP configuration is skipped entirely when IsPublishMode is true:
```cs
if (context.ExecutionContext.IsPublishMode)
{
// REVIEW: Do we want to set references to an imaginary otlp provider as a requirement?
return;
}
```
https://github.com/dotnet/aspire/blob/6d8575a2e5d0171773298a8171ff85a58c873292/src/Aspire.Hosting/OtlpConfigurationExtensions.cs#L40C13-L44C14
I’d like to propose that OTLP configuration should be made an optional setting, rather than being outright disabled in publish mode. This would provide more flexibility for projects that may want to configure OTLP endpoints or telemetry even when publishing.
### Describe the solution you'd like
Instead of returning immediately, allow users to opt-in to OTLP configuration in publish mode via configuration or environment variable.
Provide clear documentation on how to enable or disable OTLP in publish/publish-like scenarios.
This change would help teams who wish to collect telemetry in production or staging environments without having to patch the SDK or override this logic.
### Additional context
My current workaround to get otlp configured in publish mode (mainly create correct env in docker compose file)
```cs
public static IResourceBuilder PublishOtlpEnvironmentPlaceHolder(this IResourceBuilder builder, IResourceBuilder endpoint, IResourceBuilder protocol) where T : IResourceWithEnvironment
{
ArgumentNullException.ThrowIfNull(builder);
if (builder.ApplicationBuilder.ExecutionContext.IsPublishMode)
{
builder.WithEnvironment("OTEL_EXPORTER_OTLP_ENDPOINT", endpoint);
builder.WithEnvironment("OTEL_EXPORTER_OTLP_PROTOCOL", protocol);
}
return builder;
}
```
Contributor guide
Assessment
This issue has not been assessed yet.