-
Notifications
You must be signed in to change notification settings - Fork 707
Allow requiring OpenTelemetry protocol if needed #10507
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
4 commits
Select commit
Hold shift + click to select a range
5b50f03
Allow requiring OpenTelemetry protocol if needed
twsouthwick cd2f3b2
add comment and move private method down
twsouthwick f9c1f1b
Merge remote-tracking branch 'origin/main' into otlp
twsouthwick 1cd3bb6
react to comment changes from merge
twsouthwick 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
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,20 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| namespace Aspire.Hosting; | ||
|
|
||
| /// <summary> | ||
| /// Protocols available for OTLP exporters. | ||
| /// </summary> | ||
| public enum OtlpProtocol | ||
| { | ||
| /// <summary> | ||
| /// A gRPC-based OTLP exporter. | ||
| /// </summary> | ||
| Grpc, | ||
|
|
||
| /// <summary> | ||
| /// Http/Protobuf-based OTLP exporter. | ||
| /// </summary> | ||
| HttpProtobuf | ||
| } |
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,72 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| using Aspire.Hosting.Tests.Utils; | ||
| using Aspire.Hosting.Utils; | ||
| using Microsoft.AspNetCore.InternalTesting; | ||
| using Microsoft.Extensions.DependencyInjection; | ||
|
|
||
| namespace Aspire.Hosting.Tests; | ||
|
|
||
| public class WithOtlpExporterTests | ||
| { | ||
| [InlineData(default, "http://localhost:8889", null, "http://localhost:8889", "grpc")] | ||
| [InlineData(default, "http://localhost:8889", "http://localhost:8890", "http://localhost:8889", "grpc")] | ||
| [InlineData(default, null, "http://localhost:8890", "http://localhost:8890", "http/protobuf")] | ||
| [InlineData(OtlpProtocol.HttpProtobuf, "http://localhost:8889", "http://localhost:8890", "http://localhost:8890", "http/protobuf")] | ||
| [InlineData(OtlpProtocol.Grpc, "http://localhost:8889", "http://localhost:8890", "http://localhost:8889", "grpc")] | ||
| [InlineData(OtlpProtocol.Grpc, null, null, "http://localhost:18889", "grpc")] | ||
| [Theory] | ||
| public async Task OtlpEndpointSet(OtlpProtocol? protocol, string? grpcEndpoint, string? httpEndpoint, string expectedUrl, string expectedProtocol) | ||
| { | ||
| using var builder = TestDistributedApplicationBuilder.Create(); | ||
|
|
||
| builder.Configuration["ASPIRE_DASHBOARD_OTLP_ENDPOINT_URL"] = grpcEndpoint; | ||
| builder.Configuration["ASPIRE_DASHBOARD_OTLP_HTTP_ENDPOINT_URL"] = httpEndpoint; | ||
|
|
||
| var container = builder.AddResource(new ContainerResource("testSource")); | ||
|
|
||
| if (protocol is { } value) | ||
| { | ||
| container = container.WithOtlpExporter(value); | ||
| } | ||
| else | ||
| { | ||
| container = container.WithOtlpExporter(); | ||
| } | ||
|
|
||
| using var app = builder.Build(); | ||
|
|
||
| var serviceProvider = app.Services.GetRequiredService<IServiceProvider>(); | ||
|
|
||
| var config = await EnvironmentVariableEvaluator.GetEnvironmentVariablesAsync( | ||
| container.Resource, | ||
| serviceProvider: serviceProvider | ||
| ).DefaultTimeout(); | ||
|
|
||
| Assert.Equal(expectedUrl, config["OTEL_EXPORTER_OTLP_ENDPOINT"]); | ||
| Assert.Equal(expectedProtocol, config["OTEL_EXPORTER_OTLP_PROTOCOL"]); | ||
| } | ||
|
|
||
| [Fact] | ||
| public async Task RequiredHttpOtlpThrowsExceptionIfNotRegistered() | ||
| { | ||
| using var builder = TestDistributedApplicationBuilder.Create(); | ||
|
|
||
| builder.Configuration["ASPIRE_DASHBOARD_OTLP_HTTP_ENDPOINT_URL"] = null; | ||
|
|
||
| var container = builder.AddResource(new ContainerResource("testSource")) | ||
| .WithOtlpExporter(OtlpProtocol.HttpProtobuf); | ||
|
|
||
| using var app = builder.Build(); | ||
|
|
||
| var serviceProvider = app.Services.GetRequiredService<IServiceProvider>(); | ||
|
|
||
| await Assert.ThrowsAsync<InvalidOperationException>(() => | ||
| EnvironmentVariableEvaluator.GetEnvironmentVariablesAsync( | ||
| container.Resource, | ||
| serviceProvider: serviceProvider | ||
| ).DefaultTimeout() | ||
| ); | ||
| } | ||
| } |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The existing
AddOtlpEnvironmentoverload should probably call this one to reduce code duplication.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
protocolparameter is non nullable here and so theRequiredProtocolis set to it, while if nothing is passed theRequiredProtocolwill be null.I did it this way since I don't think I can add a optional nullable parameter to the existing signature, to it was the simplest I could make it without having a third private method that took a nullable protocol which didn't seem to add much value here.