microsoft / microsoft/aspire

Optional prefix in `WithOtlpExporter`

Open
#11,045 0 comments 0 reactions 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

## Background and Motivation

Well known apps like [Keycloak support OpenTelemetry](https://www.keycloak.org/observability/tracing) but read values from `quarkus*` [prefixed environment variables](https://quarkus.io/guides/opentelemetry). I don't think we can get Keycloak to change this for us.

For example `QUARKUS_OTEL_EXPORTER_OTLP_ENDPOINT` instead of `OTEL_EXPORTER_OTLP_ENDPOINT`

## Proposed API

```diff
namespace Aspire.Hosting;

public static class OtlpConfigurationExtensions
{
- public static IResourceBuilder WithOtlpExporter(this IResourceBuilder builder) where T : IResourceWithEnvironment
+ public static IResourceBuilder WithOtlpExporter(this IResourceBuilder builder, string? prefix = null) where T : IResourceWithEnvironment
}
```

## Usage Examples

```cs
var keycloak = builder.AddKeycloak("keycloak", 5677, adminPassword: keycloakAdminPassword)
.WithLifetime(ContainerLifetime.Persistent)
.WithEnvironment("KC_DB", "mssql")
.WithEnvironment("KC_DB_URL", JdbcExpression.Create(keycloakDb))
.WithEnvironment("KC_DB_USERNAME", "SA")
.WithEnvironment("KC_DB_PASSWORD", keycloakDbPassword)
.WithEnvironment("KC_BOOTSTRAP_ADMIN_USERNAME", "")
.WithEnvironment("KC_TRACING_ENABLED", "true")
.WithReference(keycloakDb)
.WaitFor(keycloakDb)
.WithOtlpExporter("quarkus");
```

## Alternative Designs

I'm currently copying the code of `AddOtlpEnvironment(IResource resource, IConfiguration configuration, IHostEnvironment environment)` to implement this myself in my codebase.

## Risks

No breaking changes 👍

## Related

* #6635

---

I'm willing to provide a PR if this is a valid API change

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.