Skip to content

Commit 7c0bd15

Browse files
afscromeFullStackChef
authored andcommitted
Remove Development environments check from otel collector (CommunityToolkit#869)
There is already a guard for `IsRunMode`, so there's no need to further restrict to just Development environments. Fixes CommunityToolkit#857.
1 parent cc703ae commit 7c0bd15

File tree

2 files changed

+3
-34
lines changed

2 files changed

+3
-34
lines changed

src/CommunityToolkit.Aspire.Hosting.OpenTelemetryCollector/OpenTelemetryCollectorExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public static IResourceBuilder<OpenTelemetryCollectorResource> AddOpenTelemetryC
4848
resourceBuilder.WithEndpoint(targetPort: 4318, name: OpenTelemetryCollectorResource.HttpEndpointName, scheme: isHttpsEnabled ? "https" : "http");
4949

5050

51-
if (!settings.ForceNonSecureReceiver && isHttpsEnabled && builder.ExecutionContext.IsRunMode && builder.Environment.IsDevelopment())
51+
if (!settings.ForceNonSecureReceiver && isHttpsEnabled && builder.ExecutionContext.IsRunMode)
5252
{
5353
resourceBuilder.RunWithHttpsDevCertificate();
5454

tests/CommunityToolkit.Aspire.Hosting.OpenTelemetryCollector.Tests/ResourceCreationTests.cs

Lines changed: 2 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -329,37 +329,6 @@ public void ForceNonSecureReceiverOverridesHttpsEndpoints()
329329
Assert.Equal("http", httpEndpoint.UriScheme);
330330
}
331331

332-
[Fact]
333-
public void DevCertificateLogicIsNotTriggeredInNonDevelopmentEnvironment()
334-
{
335-
var builder = DistributedApplication.CreateBuilder();
336-
builder.Configuration["ASPIRE_DASHBOARD_OTLP_ENDPOINT_URL"] = "https://localhost:18889";
337-
338-
builder.AddOpenTelemetryCollector("collector", settings =>
339-
{
340-
settings.ForceNonSecureReceiver = false; // Allow HTTPS
341-
})
342-
.WithAppForwarding();
343-
344-
using var app = builder.Build();
345-
346-
var appModel = app.Services.GetRequiredService<DistributedApplicationModel>();
347-
var collectorResource = appModel.Resources.OfType<OpenTelemetryCollectorResource>().SingleOrDefault();
348-
Assert.NotNull(collectorResource);
349-
350-
// In non-development environment (default test environment), dev cert args should not be added
351-
var args = collectorResource.Annotations.OfType<CommandLineArgsCallbackAnnotation>().ToList();
352-
var context = new CommandLineArgsCallbackContext([]);
353-
foreach (var arg in args)
354-
{
355-
arg.Callback(context);
356-
}
357-
358-
// Should not contain TLS certificate configuration args since we're not in Development environment with RunMode
359-
Assert.DoesNotContain(context.Args.Cast<string>(), a => a.Contains("receivers::otlp::protocols::http::tls::cert_file"));
360-
Assert.DoesNotContain(context.Args.Cast<string>(), a => a.Contains("receivers::otlp::protocols::grpc::tls::cert_file"));
361-
}
362-
363332
[Fact]
364333
public void DevCertificateLogicIsNotTriggeredWhenForceNonSecureReceiverEnabled()
365334
{
@@ -464,7 +433,7 @@ public void RunWithHttpsDevCertificateAddsContainerFilesAndWaitAnnotation()
464433
public void RunWithHttpsDevCertificateNotTriggeredInNonRunMode()
465434
{
466435
// Use regular builder (not TestDistributedApplicationBuilder.Create) which defaults to non-Run mode
467-
var builder = DistributedApplication.CreateBuilder();
436+
var builder = TestDistributedApplicationBuilder.Create(DistributedApplicationOperation.Publish);
468437
builder.Configuration["ASPIRE_DASHBOARD_OTLP_ENDPOINT_URL"] = "https://localhost:18889";
469438

470439
builder.AddOpenTelemetryCollector("collector", settings =>
@@ -522,7 +491,7 @@ public void RunWithHttpsDevCertificateNotTriggeredWhenForceNonSecureEnabled()
522491
}
523492

524493
[Fact]
525-
public void DevCertificateResourcesAddedWhenHttpsEnabledInDevelopment()
494+
public void DevCertificateResourcesAddedWhenHttpsEnabled()
526495
{
527496
var builder = TestDistributedApplicationBuilder.Create(DistributedApplicationOperation.Run);
528497
builder.Configuration["ASPIRE_DASHBOARD_OTLP_ENDPOINT_URL"] = "https://localhost:18889";

0 commit comments

Comments
 (0)