Skip to content

Conversation

@twsouthwick
Copy link
Member

@twsouthwick twsouthwick commented Jul 17, 2025

For some scenarios (mine is running ASP.NET framework applications), gRPC is not supported. This change adds an overload for AddOtlpExporter APIs to have a required protocol. Since there's not a default http endpoint if one is not set, this will throw an exception pointing the user to set that variable.

Fixes #6789

@Copilot Copilot AI review requested due to automatic review settings July 17, 2025 19:14
@twsouthwick twsouthwick requested a review from mitchdenny as a code owner July 17, 2025 19:14
@github-actions github-actions bot added the area-app-model Issues pertaining to the APIs in Aspire.Hosting, e.g. DistributedApplication label Jul 17, 2025
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR introduces the ability to explicitly require a specific OpenTelemetry protocol (gRPC or HTTP/Protobuf) when configuring the OTLP exporter, including new enums, overloads, annotations, and accompanying tests.

  • Defines a new OtlpProtocol enum and extends the annotation model with RequiredProtocol
  • Adds overloads for AddOtlpEnvironment and WithOtlpExporter to accept a protocol parameter
  • Implements protocol-specific environment-variable registration logic and verifies behavior in tests

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
tests/Aspire.Hosting.Tests/WithOtlpExporterTests.cs Adds tests for protocol selection and exception when HTTP endpoint is missing
src/Aspire.Hosting/OtlpProtocol.cs Introduces OtlpProtocol enum
src/Aspire.Hosting/OtlpConfigurationExtensions.cs Implements protocol-aware environment setup and new overloads
src/Aspire.Hosting/ApplicationModel/OtlpExporterAnnotation.cs Extends annotation model with nullable RequiredProtocol property
Comments suppressed due to low confidence (2)

src/Aspire.Hosting/OtlpConfigurationExtensions.cs:44

  • The <param> description for protocol should be updated to reflect that this overload requires the protocol explicitly and does not use a fallback behavior. For example: "The protocol to use for the OTLP exporter."
    /// <param name="protocol">The protocol to use for the OTLP exporter. If not set, it will try gRPC then Http.</param>

src/Aspire.Hosting/ApplicationModel/OtlpExporterAnnotation.cs:15

  • The summary refers to a "default protocol," but the property is RequiredProtocol. Consider updating to: "Gets or sets the required protocol for the OTLP exporter."
    /// Gets or sets the default protocol for the OTLP exporter.

For some scenarios (mine is runnin it ASP.NET framework applications), gRPC is not supported. This change adds an overload for AddOtlpExporter APIs to have a required protocol. Since there's not a default http endpoint if one is not set, this will throw an exception pointing the user to set that variable.
/// <param name="configuration">The configuration to use for the OTLP exporter endpoint URL.</param>
/// <param name="environment">The host environment to check if the application is running in development mode.</param>
/// <param name="protocol">The protocol to use for the OTLP exporter. If not set, it will try gRPC then Http.</param>
public static void AddOtlpEnvironment(IResource resource, IConfiguration configuration, IHostEnvironment environment, OtlpProtocol protocol)
Copy link
Member

Choose a reason for hiding this comment

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

The existing AddOtlpEnvironment overload should probably call this one to reduce code duplication.

Copy link
Member Author

Choose a reason for hiding this comment

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

The protocol parameter is non nullable here and so the RequiredProtocol is set to it, while if nothing is passed the RequiredProtocol will 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.

@twsouthwick twsouthwick requested a review from mitchdenny July 23, 2025 15:32
@davidfowl davidfowl requested a review from JamesNK July 29, 2025 05:33
@davidfowl
Copy link
Member

This change is good, we should also support http vs https here. @JamesNK can you advise on how we should expand this to support both scenarios?

@davidfowl davidfowl merged commit e66159a into dotnet:main Aug 21, 2025
276 checks passed
@dotnet-policy-service dotnet-policy-service bot added this to the 9.5 milestone Aug 21, 2025
@davidfowl
Copy link
Member

@twsouthwick test out the end to end once we get builds! See https://github.com/dotnet/aspire/blob/main/docs/using-latest-daily.md

@twsouthwick twsouthwick deleted the otlp branch August 25, 2025 19:44
@github-actions github-actions bot locked and limited conversation to collaborators Sep 25, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-app-model Issues pertaining to the APIs in Aspire.Hosting, e.g. DistributedApplication

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow users to configure preferred protocol (gRPC or HTTP/Protobuf) for OpenTelemetry endpoints

3 participants