Skip to content

Conversation

@afscrome
Copy link
Contributor

@afscrome afscrome commented Dec 11, 2025

Closes #981

Use the new WithHttpsCertificateConfiguration apis in 13.1 rather than the previous custom implementation of exporting the dev cert.

Added some telemetry generator resources to the otel collector's playground app to generate some dummy otel, as well as to test telemetry for container --> container.

PR Checklist

  • Created a feature/dev branch in your fork (vs. submitting directly from a commit on main)
  • Based off latest main branch of toolkit
  • PR doesn't include merge commits (always rebase on top of our main, if needed)
  • Code follows all style conventions

Other information

@afscrome afscrome requested a review from martinjt as a code owner December 11, 2025 19:34
@afscrome afscrome changed the title Use WithHttpsCertificateConfiguration to configure tls cert for the… [13.1] Use WithHttpsCertificateConfiguration to configure tls cert for Otel Collector Dec 11, 2025
Copy link
Contributor

@martinjt martinjt left a comment

Choose a reason for hiding this comment

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

I don't think we need the TelemetryGen as part of this change.

@afscrome
Copy link
Contributor Author

I'll see what I can do tomorrow - reason I added telemetry generator is that I needed something that generated container from a container as I wanted to make sure the cert was being trusted both in host --> container scenarios
(as was already covered by the playground project) and container --> container scenarios

Copilot AI review requested due to automatic review settings December 15, 2025 21:18
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 modernizes the OpenTelemetry Collector integration by adopting Aspire 13.1's new WithHttpsCertificateConfiguration API for TLS certificate management, replacing a custom dev certificate export implementation. The change simplifies the codebase by leveraging built-in Aspire functionality.

  • Replaced custom dev certificate export logic with WithHttpsCertificateConfiguration API
  • Removed DevCertHostingExtensions.cs shared utility file and associated tests
  • Enhanced the example app with telemetry generators to demonstrate container-to-container communication

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
src/CommunityToolkit.Aspire.Hosting.OpenTelemetryCollector/OpenTelemetryCollectorExtensions.cs Refactored certificate configuration to use new Aspire 13.1 API instead of custom implementation
src/CommunityToolkit.Aspire.Hosting.OpenTelemetryCollector/CommunityToolkit.Aspire.Hosting.OpenTelemetryCollector.csproj Removed reference to shared DevCertHostingExtensions.cs file
src/Shared/DevCertHostingExtensions.cs Deleted entire custom dev certificate hosting extensions utility
tests/CommunityToolkit.Aspire.Hosting.OpenTelemetryCollector.Tests/ResourceCreationTests.cs Removed tests specific to custom dev certificate export implementation
examples/opentelemetry-collector/CommunityToolkit.Aspire.Hosting.OpenTelemetryCollector.AppHost/AppHost.cs Added telemetry generator containers to demonstrate collector functionality

var scheme = useHttpsForRecievers ? "https" : "http";
resourceBuilder.WithEndpoint(targetPort: port, name: protocol, scheme: scheme);

if (!useHttpsForRecievers)
Copy link

Copilot AI Dec 15, 2025

Choose a reason for hiding this comment

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

The variable name has a spelling error: "Recievers" should be "Receivers" (the 'i' and 'e' are transposed).

Copilot uses AI. Check for mistakes.
return Task.CompletedTask;
});
#pragma warning restore ASPIRECERTIFICATES001 // Type is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed.
}
Copy link

Copilot AI Dec 15, 2025

Choose a reason for hiding this comment

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

There is trailing whitespace after the closing brace. This should be removed for consistent code formatting.

Suggested change
}
}

Copilot uses AI. Check for mistakes.
.WithArgs(signal,
"--duration", "inf",
"--otlp-endpoint", collector.GetEndpoint("grpc").Property(EndpointProperty.HostAndPort))
.WithArgs(args)
Copy link

Copilot AI Dec 15, 2025

Choose a reason for hiding this comment

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

The variable args is not defined in the scope of the AddTelemetryGenerator method. This appears to be a bug as it references the command-line arguments from the Main method which are not accessible here. This line should likely be removed since the necessary arguments are already added on lines 21-23.

Suggested change
.WithArgs(args)

Copilot uses AI. Check for mistakes.
if (!settings.ForceNonSecureReceiver && isHttpsEnabled && builder.ExecutionContext.IsRunMode)
{
resourceBuilder.RunWithHttpsDevCertificate();
var useHttpsForRecievers = !settings.ForceNonSecureReceiver && url.StartsWith("https", StringComparison.OrdinalIgnoreCase);
Copy link

Copilot AI Dec 15, 2025

Choose a reason for hiding this comment

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

The variable name has a spelling error: "Recievers" should be "Receivers" (the 'i' and 'e' are transposed).

Copilot uses AI. Check for mistakes.

void ConfigureReceiver(int port, string protocol)
{
var scheme = useHttpsForRecievers ? "https" : "http";
Copy link

Copilot AI Dec 15, 2025

Choose a reason for hiding this comment

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

The variable name has a spelling error: "Recievers" should be "Receivers" (the 'i' and 'e' are transposed).

Copilot uses AI. Check for mistakes.
Comment on lines +78 to +79
ctx.Arguments.Add(ReferenceExpression.Create($@"--config=yaml:receivers::otlp::protocols::{protocol}::tls::cert_file: ""{ctx.CertificatePath}"""));
ctx.Arguments.Add(ReferenceExpression.Create($@"--config=yaml:receivers::otlp::protocols::{protocol}::tls::key_file: ""{ctx.KeyPath}"""));
Copy link

Copilot AI Dec 15, 2025

Choose a reason for hiding this comment

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

Default 'ToString()': ReferenceExpression inherits 'ToString()' from 'Object', and so is not suitable for printing.

Suggested change
ctx.Arguments.Add(ReferenceExpression.Create($@"--config=yaml:receivers::otlp::protocols::{protocol}::tls::cert_file: ""{ctx.CertificatePath}"""));
ctx.Arguments.Add(ReferenceExpression.Create($@"--config=yaml:receivers::otlp::protocols::{protocol}::tls::key_file: ""{ctx.KeyPath}"""));
ctx.Arguments.Add($@"--config=yaml:receivers::otlp::protocols::{protocol}::tls::cert_file: ""{ctx.CertificatePath}""");
ctx.Arguments.Add($@"--config=yaml:receivers::otlp::protocols::{protocol}::tls::key_file: ""{ctx.KeyPath}""");

Copilot uses AI. Check for mistakes.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

ReferenceExpression is absolutely required here as certificate and key paths cannot be resolve until after the app host starts.

Comment on lines +78 to +79
ctx.Arguments.Add(ReferenceExpression.Create($@"--config=yaml:receivers::otlp::protocols::{protocol}::tls::cert_file: ""{ctx.CertificatePath}"""));
ctx.Arguments.Add(ReferenceExpression.Create($@"--config=yaml:receivers::otlp::protocols::{protocol}::tls::key_file: ""{ctx.KeyPath}"""));
Copy link

Copilot AI Dec 15, 2025

Choose a reason for hiding this comment

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

Default 'ToString()': ReferenceExpression inherits 'ToString()' from 'Object', and so is not suitable for printing.

Suggested change
ctx.Arguments.Add(ReferenceExpression.Create($@"--config=yaml:receivers::otlp::protocols::{protocol}::tls::cert_file: ""{ctx.CertificatePath}"""));
ctx.Arguments.Add(ReferenceExpression.Create($@"--config=yaml:receivers::otlp::protocols::{protocol}::tls::key_file: ""{ctx.KeyPath}"""));
ctx.Arguments.Add($@"--config=yaml:receivers::otlp::protocols::{protocol}::tls::cert_file: ""{ctx.CertificatePath}""");
ctx.Arguments.Add($@"--config=yaml:receivers::otlp::protocols::{protocol}::tls::key_file: ""{ctx.KeyPath}""");

Copilot uses AI. Check for mistakes.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

ReferenceExpression is absolutely required here as certificate and key paths cannot be resolve until after the app host starts.

Use the new `WithHttpsCertificateConfiguration` apis in 13.1 rather than the previous custom implementation of exporting the dev cert.
@afscrome afscrome force-pushed the otel-tls-injection2 branch from 04e47c4 to 163148e Compare December 17, 2025 22:30
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