Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

builder.AddProject<Projects.CommunityToolkit_Aspire_Hosting_OpenTelemetryCollector_Api>("api");

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

Copilot AI Jan 20, 2026

Copy link

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.
.WithAppForwarding()
.WithConfig("./config.yaml");

builder.Build().Run();

Copilot AI Jan 20, 2026

Copy link

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.
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,4 @@
<PackageReference Include="Aspire.Hosting" />
</ItemGroup>

<ItemGroup>
<Compile Include="$(SharedDir)\DevCertHostingExtensions.cs" Link="Utils\DevCertHostingExtensions.cs" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -34,42 +34,20 @@ public static IResourceBuilder<OpenTelemetryCollectorResource> AddOpenTelemetryC
var settings = new OpenTelemetryCollectorSettings();
configureSettings?.Invoke(settings);

var isHttpsEnabled = !settings.ForceNonSecureReceiver && url.StartsWith("https", StringComparison.OrdinalIgnoreCase);

var resource = new OpenTelemetryCollectorResource(name);
var resourceBuilder = builder.AddResource(resource)
.WithImage(settings.CollectorImage, settings.CollectorTag)
.WithEnvironment("ASPIRE_ENDPOINT", new HostUrl(url))
.WithEnvironment("ASPIRE_API_KEY", builder.Configuration[DashboardOtlpApiKeyVariableName])
.WithIconName("DesktopPulse");

if (settings.EnableGrpcEndpoint)
resourceBuilder.WithEndpoint(targetPort: 4317, name: OpenTelemetryCollectorResource.GrpcEndpointName, scheme: isHttpsEnabled ? "https" : "http");
if (settings.EnableHttpEndpoint)
resourceBuilder.WithEndpoint(targetPort: 4318, name: OpenTelemetryCollectorResource.HttpEndpointName, scheme: isHttpsEnabled ? "https" : "http");


if (!settings.ForceNonSecureReceiver && isHttpsEnabled && builder.ExecutionContext.IsRunMode)
{
resourceBuilder.RunWithHttpsDevCertificate();
var useHttpsForReceivers = !settings.ForceNonSecureReceiver && url.StartsWith("https", StringComparison.OrdinalIgnoreCase);

// Not using `Path.Combine` as we MUST use unix style paths in the container
var certFilePath = $"{DevCertHostingExtensions.DEV_CERT_BIND_MOUNT_DEST_DIR}/{DevCertHostingExtensions.CERT_FILE_NAME}";
var certKeyPath = $"{DevCertHostingExtensions.DEV_CERT_BIND_MOUNT_DEST_DIR}/{DevCertHostingExtensions.CERT_KEY_FILE_NAME}";
if (settings.EnableGrpcEndpoint)
ConfigureReceiver(4317, OpenTelemetryCollectorResource.GrpcEndpointName);

if (settings.EnableHttpEndpoint)
{
resourceBuilder.WithArgs(
$@"--config=yaml:receivers::otlp::protocols::http::tls::cert_file: ""{certFilePath}""",
$@"--config=yaml:receivers::otlp::protocols::http::tls::key_file: ""{certKeyPath}""");
}
if (settings.EnableGrpcEndpoint)
{
resourceBuilder.WithArgs(
$@"--config=yaml:receivers::otlp::protocols::grpc::tls::cert_file: ""{certFilePath}""",
$@"--config=yaml:receivers::otlp::protocols::grpc::tls::key_file: ""{certKeyPath}""");
}
}
if (settings.EnableHttpEndpoint)
ConfigureReceiver(4318, OpenTelemetryCollectorResource.HttpEndpointName);

if (!settings.DisableHealthcheck)
{
Expand All @@ -83,6 +61,26 @@ public static IResourceBuilder<OpenTelemetryCollectorResource> AddOpenTelemetryC
);
}
return resourceBuilder;

void ConfigureReceiver(int port, string protocol)
{
var scheme = useHttpsForReceivers ? "https" : "http";
resourceBuilder.WithEndpoint(targetPort: port, name: protocol, scheme: scheme);

if (!useHttpsForReceivers)
{
return;
}

#pragma warning disable ASPIRECERTIFICATES001 // Type is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed.
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}"""));
Comment on lines +78 to +79

Copilot AI Jan 20, 2026

Copy link

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.

Copilot AI Jan 20, 2026

Copy link

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.
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.
}

Copilot AI Jan 20, 2026

Copy link

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.
}

/// <summary>
Expand Down Expand Up @@ -123,5 +121,4 @@ public static IResourceBuilder<OpenTelemetryCollectorResource> WithConfig(this I
return builder.WithBindMount(configPath, $"/config/{configFileInfo.Name}")
.WithArgs($"--config=/config/{configFileInfo.Name}");
}

}
152 changes: 0 additions & 152 deletions src/Shared/DevCertHostingExtensions.cs

This file was deleted.

Loading
Loading