-
Notifications
You must be signed in to change notification settings - Fork 905
Add OpenTelemetry support on yarp container #2750
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
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
b9a9c7f
Add OpenTelemetry support on yarp container
benjaminpetit 6123fef
Add YARP_UNSAFE_SKIP_OLTP_CERT_VALIDATION variable to skip oltp cert …
benjaminpetit a7f38f3
Address comments
benjaminpetit f90be38
Fix build
benjaminpetit 88f3500
Update Signing.props for OpenTelemetry.dll
benjaminpetit d42087b
Update Signing.props
benjaminpetit a71793b
Update Signing.props 2
benjaminpetit 0aeb040
Fixes
benjaminpetit 9ee0ab6
Merge branch 'main' into container/optl
benjaminpetit File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,15 @@ | ||
| <Project> | ||
| <!-- Arcade currently requires this file, though it doesn't require any content in it I believe. --> | ||
| <ItemGroup Label="File signing information"> | ||
| <!-- Third-party components which should be signed. --> | ||
| <FileSignInfo Include="HealthChecks.ApplicationStatus.dll" CertificateName="3PartySHA2" /> | ||
| <FileSignInfo Include="OpenTelemetry.dll" CertificateName="3PartySHA2" /> | ||
| <FileSignInfo Include="OpenTelemetry.Api.dll" CertificateName="3PartySHA2" /> | ||
| <FileSignInfo Include="OpenTelemetry.Api.ProviderBuilderExtensions.dll" CertificateName="3PartySHA2" /> | ||
| <FileSignInfo Include="OpenTelemetry.Exporter.OpenTelemetryProtocol.dll" CertificateName="3PartySHA2" /> | ||
| <FileSignInfo Include="OpenTelemetry.Extensions.Hosting.dll" CertificateName="3PartySHA2" /> | ||
| <FileSignInfo Include="OpenTelemetry.Instrumentation.AspNetCore.dll" CertificateName="3PartySHA2" /> | ||
| <FileSignInfo Include="OpenTelemetry.Instrumentation.GrpcNetClient.dll" CertificateName="3PartySHA2" /> | ||
| <FileSignInfo Include="OpenTelemetry.Instrumentation.Http.dll" CertificateName="3PartySHA2" /> | ||
| <FileSignInfo Include="OpenTelemetry.Instrumentation.Runtime.dll" CertificateName="3PartySHA2" /> | ||
| </ItemGroup> | ||
| </Project> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,107 @@ | ||
| using System.Net; | ||
| using System.Security.Cryptography; | ||
| using System.Security.Cryptography.X509Certificates; | ||
| using HealthChecks.ApplicationStatus.DependencyInjection; | ||
| using Microsoft.AspNetCore.Builder; | ||
| using Microsoft.AspNetCore.Diagnostics.HealthChecks; | ||
| using Microsoft.Extensions.DependencyInjection; | ||
| using Microsoft.Extensions.Logging; | ||
| using OpenTelemetry; | ||
| using OpenTelemetry.Exporter; | ||
| using OpenTelemetry.Logs; | ||
| using OpenTelemetry.Metrics; | ||
| using OpenTelemetry.Trace; | ||
| using static System.Net.WebRequestMethods; | ||
|
|
||
| namespace Microsoft.Extensions.Hosting; | ||
|
|
||
| // Adds common .NET Aspire services: service discovery, resilience, health checks, and OpenTelemetry. | ||
| // This project should be referenced by each service project in your solution. | ||
| // To learn more about using this project, see https://aka.ms/dotnet/aspire/service-defaults | ||
| public static class Extensions | ||
| { | ||
| public static TBuilder AddServiceDefaults<TBuilder>(this TBuilder builder) where TBuilder : IHostApplicationBuilder | ||
| { | ||
| builder.ConfigureOpenTelemetry(); | ||
|
|
||
| builder.AddDefaultHealthChecks(); | ||
|
|
||
| builder.Services.AddServiceDiscovery(); | ||
benjaminpetit marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| return builder; | ||
| } | ||
|
|
||
| public static TBuilder ConfigureOpenTelemetry<TBuilder>(this TBuilder builder) where TBuilder : IHostApplicationBuilder | ||
| { | ||
| builder.Logging.AddOpenTelemetry(logging => | ||
| { | ||
| logging.IncludeFormattedMessage = true; | ||
| logging.IncludeScopes = true; | ||
| }); | ||
|
|
||
| builder.Services.AddOpenTelemetry() | ||
| .WithMetrics(metrics => | ||
| { | ||
| metrics.AddAspNetCoreInstrumentation() | ||
| .AddHttpClientInstrumentation() | ||
| .AddRuntimeInstrumentation() | ||
| .SetExemplarFilter(ExemplarFilterType.TraceBased); | ||
| }) | ||
| .WithTracing(tracing => | ||
| { | ||
| tracing.AddAspNetCoreInstrumentation() | ||
| .AddHttpClientInstrumentation() | ||
| .AddOtlpExporter(); | ||
| }); | ||
|
|
||
| builder.AddOpenTelemetryExporters(); | ||
|
|
||
| return builder; | ||
| } | ||
|
|
||
| private static TBuilder AddOpenTelemetryExporters<TBuilder>(this TBuilder builder) where TBuilder : IHostApplicationBuilder | ||
| { | ||
| var useOtlpExporter = !string.IsNullOrWhiteSpace(builder.Configuration["OTEL_EXPORTER_OTLP_ENDPOINT"]); | ||
|
|
||
| if (useOtlpExporter) | ||
| { | ||
|
|
||
| if (string.Equals(Environment.GetEnvironmentVariable("YARP_UNSAFE_OLTP_CERT_ACCEPT_ANY_SERVER_CERTIFICATE"), "true", StringComparison.InvariantCultureIgnoreCase)) | ||
| { | ||
| // We cannot use UseOtlpExporter() since it doesn't support configuration via OtlpExporterOptions | ||
| // https://github.com/open-telemetry/opentelemetry-dotnet/issues/5802 | ||
| builder.Services.Configure<OtlpExporterOptions>(ConfigureOtlpExporterOptions); | ||
| builder.Services.AddOpenTelemetry() | ||
| .WithLogging(logging => logging.AddOtlpExporter()) | ||
| .WithMetrics(metrics => metrics.AddOtlpExporter()) | ||
| .WithTracing(tracing => tracing.AddOtlpExporter()); | ||
| } | ||
| else | ||
| { | ||
| builder.Services.AddOpenTelemetry().UseOtlpExporter(); | ||
| } | ||
| } | ||
|
|
||
| static void ConfigureOtlpExporterOptions(OtlpExporterOptions options) | ||
| { | ||
| options.HttpClientFactory = () => | ||
| { | ||
| var handler = new HttpClientHandler(); | ||
| handler.ServerCertificateCustomValidationCallback = HttpClientHandler.DangerousAcceptAnyServerCertificateValidator; | ||
| var httpClient = new HttpClient(handler); | ||
| return httpClient; | ||
| }; | ||
| } | ||
|
|
||
| return builder; | ||
| } | ||
|
|
||
| public static TBuilder AddDefaultHealthChecks<TBuilder>(this TBuilder builder) where TBuilder : IHostApplicationBuilder | ||
| { | ||
| builder.Services.AddHealthChecks() | ||
| // Add a default liveness check on application status. | ||
| .AddApplicationStatus(tags: ["live"]); | ||
|
|
||
| return builder; | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.