Use WithHttpsCertificateConfiguration to configure tls cert for Otel Collector#1115
Conversation
…n the previous custom implementation of exporting the dev cert.
There was a problem hiding this comment.
Pull request overview
This PR modernizes the OpenTelemetry Collector integration by replacing a custom dev certificate export implementation with the new WithHttpsCertificateConfiguration API introduced in .NET Aspire 13.1. The change simplifies certificate management by delegating to Aspire's built-in certificate handling rather than manually creating an executable resource to export certificates.
Changes:
- Replaced custom dev certificate export logic with
WithHttpsCertificateConfigurationAPI - Removed the
DevCertHostingExtensions.csshared utility file - Removed tests specific to the old certificate export implementation
- Refactored endpoint configuration into a local function for better code organization
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
src/CommunityToolkit.Aspire.Hosting.OpenTelemetryCollector/OpenTelemetryCollectorExtensions.cs |
Replaced custom certificate logic with WithHttpsCertificateConfiguration API; refactored endpoint configuration into a local function |
src/Shared/DevCertHostingExtensions.cs |
Removed entire file as it's no longer needed with the new API |
src/CommunityToolkit.Aspire.Hosting.OpenTelemetryCollector/CommunityToolkit.Aspire.Hosting.OpenTelemetryCollector.csproj |
Removed reference to the deleted shared file |
tests/CommunityToolkit.Aspire.Hosting.OpenTelemetryCollector.Tests/ResourceCreationTests.cs |
Removed tests for old implementation; kept tests verifying certificate logic is properly disabled |
examples/opentelemetry-collector/CommunityToolkit.Aspire.Hosting.OpenTelemetryCollector.AppHost/AppHost.cs |
Minor change to capture resource builder in variable (unused) |
| 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. | ||
| } |
There was a problem hiding this comment.
Remove trailing whitespace at the end of this line. The coding style guidelines require clean formatting without unnecessary whitespace.
| } | |
| } |
| builder.AddProject<Projects.CommunityToolkit_Aspire_Hosting_OpenTelemetryCollector_Api>("api"); | ||
|
|
||
| builder.AddOpenTelemetryCollector("opentelemetry-collector") | ||
| var collector = builder.AddOpenTelemetryCollector("opentelemetry-collector") |
There was a problem hiding this comment.
The variable 'collector' is assigned but never used. If this is meant to demonstrate capturing the resource builder, consider adding a comment explaining its purpose. Otherwise, remove the variable assignment and keep the fluent chain without assignment.
| var collector = builder.AddOpenTelemetryCollector("opentelemetry-collector") | |
| builder.AddOpenTelemetryCollector("opentelemetry-collector") |
| .WithConfig("./config.yaml"); | ||
|
|
||
| builder.Build().Run(); | ||
|
|
There was a problem hiding this comment.
Remove extra blank line at the end of the file. Multiple consecutive blank lines at the end of files should be avoided for consistency.
| 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}""")); |
There was a problem hiding this comment.
Default 'ToString()': ReferenceExpression inherits 'ToString()' from 'Object', and so is not suitable for printing.
| 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}"""); |
| resourceBuilder.WithHttpsCertificateConfiguration(ctx => | ||
| { | ||
| 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}""")); |
There was a problem hiding this comment.
Default 'ToString()': ReferenceExpression inherits 'ToString()' from 'Object', and so is not suitable for printing.
…n the previous custom implementation of exporting the dev cert.
Closes #981
Reopening #1058 targeting main rather than the now gone 13.1 branch
Use the new WithHttpsCertificateConfiguration apis in 13.1 rather than the previous custom implementation of exporting the dev cert.
PR Checklist
Other information