Skip to content

Use WithHttpsCertificateConfiguration to configure tls cert for Otel Collector#1115

Merged
martinjt merged 1 commit into
CommunityToolkit:mainfrom
afscrome:otel-tls-injection3
Jan 20, 2026
Merged

Use WithHttpsCertificateConfiguration to configure tls cert for Otel Collector#1115
martinjt merged 1 commit into
CommunityToolkit:mainfrom
afscrome:otel-tls-injection3

Conversation

@afscrome
Copy link
Copy Markdown
Contributor

…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

  • 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)
  • Contains NO breaking changes
  • Every new API (including internal ones) has full XML docs
  • Code follows all style conventions

Other information

…n the previous custom implementation of exporting the dev cert.
@afscrome afscrome requested a review from martinjt as a code owner January 20, 2026 18:24
Copilot AI review requested due to automatic review settings January 20, 2026 18:24
Copy link
Copy Markdown
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 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 WithHttpsCertificateConfiguration API
  • Removed the DevCertHostingExtensions.cs shared 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.
}
Copy link

Copilot AI Jan 20, 2026

Choose a reason for hiding this comment

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

Remove trailing whitespace at the end of this line. The coding style guidelines require clean formatting without unnecessary whitespace.

Suggested change
}
}

Copilot uses AI. Check for mistakes.
builder.AddProject<Projects.CommunityToolkit_Aspire_Hosting_OpenTelemetryCollector_Api>("api");

builder.AddOpenTelemetryCollector("opentelemetry-collector")
var collector = builder.AddOpenTelemetryCollector("opentelemetry-collector")
Copy link

Copilot AI Jan 20, 2026

Choose a reason for hiding this comment

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

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.

Suggested change
var collector = builder.AddOpenTelemetryCollector("opentelemetry-collector")
builder.AddOpenTelemetryCollector("opentelemetry-collector")

Copilot uses AI. Check for mistakes.
.WithConfig("./config.yaml");

builder.Build().Run();

Copy link

Copilot AI Jan 20, 2026

Choose a reason for hiding this comment

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

Remove extra blank line at the end of the file. Multiple consecutive blank lines at the end of files should be avoided for consistency.

Suggested change

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 Jan 20, 2026

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.
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}"""));
Copy link

Copilot AI Jan 20, 2026

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.

Copilot uses AI. Check for mistakes.
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.

[13.1]: Replace RunWithHttpsDevCertificate with WithCertificateKeyPair api

3 participants