Skip to content

Commit 7831070

Browse files
HardBlock729claude
andcommitted
fix(otel): prefer OTLP over console exporter when endpoint is set
Console exporter ran alongside OTLP on deployed environments (ASPNETCORE_ENVIRONMENT=Development), flooding CloudWatch API logs with Activity/metric traces. Now uses OTLP when OTEL_EXPORTER_OTLP_ENDPOINT is present, falling back to console only in pure local dev. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 3bea0b0 commit 7831070

2 files changed

Lines changed: 6 additions & 8 deletions

File tree

G3.AspNetCore.Core/Extensions/OpenTelemetryExtensions.cs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public static class OpenTelemetryExtensions
1717
{
1818
/// <summary>
1919
/// Adds OpenTelemetry tracing and metrics with ASP.NET Core and HTTP client instrumentation.
20-
/// Exports to console in Development; exports to OTLP when OTEL_EXPORTER_OTLP_ENDPOINT is set.
20+
/// Exports to OTLP when OTEL_EXPORTER_OTLP_ENDPOINT is set; falls back to console in Development only.
2121
/// Health check endpoints are excluded from traces to reduce noise.
2222
/// </summary>
2323
public static WebApplicationBuilder AddG3OpenTelemetry(
@@ -46,11 +46,10 @@ public static WebApplicationBuilder AddG3OpenTelemetry(
4646
})
4747
.AddHttpClientInstrumentation(options => options.RecordException = true);
4848

49-
if (builder.Environment.IsDevelopment())
50-
tracing.AddConsoleExporter();
51-
5249
if (!string.IsNullOrEmpty(otlpEndpoint))
5350
tracing.AddOtlpExporter();
51+
else if (builder.Environment.IsDevelopment())
52+
tracing.AddConsoleExporter();
5453
})
5554
.WithMetrics(metrics =>
5655
{
@@ -60,11 +59,10 @@ public static WebApplicationBuilder AddG3OpenTelemetry(
6059
.AddHttpClientInstrumentation()
6160
.AddRuntimeInstrumentation();
6261

63-
if (builder.Environment.IsDevelopment())
64-
metrics.AddConsoleExporter();
65-
6662
if (!string.IsNullOrEmpty(otlpEndpoint))
6763
metrics.AddOtlpExporter();
64+
else if (builder.Environment.IsDevelopment())
65+
metrics.AddConsoleExporter();
6866
});
6967

7068
return builder;

G3.AspNetCore.Core/G3.AspNetCore.Core.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<GenerateDocumentationFile>True</GenerateDocumentationFile>
77
<NoWarn>$(NoWarn);1591</NoWarn>
88
<PackageId>G3Software.Net.AspNetCore.Core</PackageId>
9-
<Version>1.1.1</Version>
9+
<Version>1.1.2</Version>
1010
<Authors>G3Software</Authors>
1111
<Company>G3Software</Company>
1212
<Title>Core ASP.NET Core helpers</Title>

0 commit comments

Comments
 (0)