Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add OpenTelemetry support on yarp container #2750

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

benjaminpetit
Copy link
Member

Add opentelemetry support for the yarp container.

The main issue with the current solution is that when running in Aspire, the container will try to export telemetry to host.docker.internal, which will trigger a SSL error, since the dev cert is only made for localhost .

For the moment, I propose that we ignore this error when running in development.

Other option:

  • require the certificate to be present in the docker at runtime, and ignore only the name missmatch
  • require the cert to be valid for host.docker.internal, and manually trust the cert at runtime (requiring switching to a non distroless base image)

return builder;
}

public static WebApplication MapDefaultEndpoints(this WebApplication app)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing a call to this from Program.cs?

if (useOtlpExporter)
{

if (string.Equals(Environment.GetEnvironmentVariable("YARP_UNSAFE_SKIP_OLTP_CERT_VALIDATION"), "true", StringComparison.InvariantCultureIgnoreCase))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: If this is otherwise equivalent, can we change this to something like?

builder.Services.Configure<OtlpExporterOptions>(options =>
{
    options.HttpClientFactory = () =>
    {
        var handler = new HttpClientHandler();
    
        if (string.Equals(Environment.GetEnvironmentVariable("YARP_UNSAFE_SKIP_OLTP_CERT_VALIDATION"), "true", StringComparison.InvariantCultureIgnoreCase))
        {
            handler.ServerCertificateCustomValidationCallback = HttpClientHandler.DangerousAcceptAnyServerCertificateValidator;
        }
    
        return new HttpClient(handler);
    }
});

builder.Services.AddOpenTelemetry()
    .WithLogging(logging => logging.AddOtlpExporter())
    .WithMetrics(metrics => metrics.AddOtlpExporter())
    .WithTracing(tracing => tracing.AddOtlpExporter());

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants