Skip to content

Commit af35c63

Browse files
Simplify configuration
Only configure OTLP once, and get values from environment variables not configuration.
1 parent d578879 commit af35c63

File tree

4 files changed

+4
-28
lines changed

4 files changed

+4
-28
lines changed

examples/dotnet/Program.cs

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using OpenTelemetry;
12
using OpenTelemetry.Instrumentation.AspNetCore;
23
using OpenTelemetry.Logs;
34
using OpenTelemetry.Metrics;
@@ -13,12 +14,11 @@
1314
serviceVersion: typeof(Program).Assembly.GetName().Version?.ToString() ?? "unknown",
1415
serviceInstanceId: Environment.MachineName);
1516

16-
const string DefaultEndpoint = "http://127.0.0.1:4317";
17-
1817
// Configure OpenTelemetry tracing and metrics with auto-start using the
1918
// AddOpenTelemetry() extension method from the OpenTelemetry.Extensions.Hosting package.
2019
appBuilder.Services.AddOpenTelemetry()
2120
.ConfigureResource(configureResource)
21+
.UseOtlpExporter()
2222
.WithTracing(builder =>
2323
{
2424
builder
@@ -28,26 +28,12 @@
2828
// Use IConfiguration binding for AspNetCore instrumentation options.
2929
appBuilder.Services.Configure<AspNetCoreTraceInstrumentationOptions>(
3030
appBuilder.Configuration.GetSection("AspNetCoreInstrumentation"));
31-
32-
builder.AddOtlpExporter(otlpOptions =>
33-
{
34-
// Use IConfiguration directly for OTLP exporter endpoint option.
35-
otlpOptions.Endpoint = new Uri(
36-
appBuilder.Configuration.GetValue("Otlp:Endpoint", defaultValue: DefaultEndpoint)!);
37-
});
3831
})
3932
.WithMetrics(builder =>
4033
{
4134
builder
4235
.AddHttpClientInstrumentation()
4336
.AddAspNetCoreInstrumentation();
44-
45-
builder.AddOtlpExporter(otlpOptions =>
46-
{
47-
// Use IConfiguration directly for OTLP exporter endpoint option.
48-
otlpOptions.Endpoint = new Uri(
49-
appBuilder.Configuration.GetValue("Otlp:Endpoint", defaultValue: DefaultEndpoint)!);
50-
});
5137
});
5238

5339
// Clear default logging providers used by WebApplication host.
@@ -60,13 +46,6 @@
6046
var resourceBuilder = ResourceBuilder.CreateDefault();
6147
configureResource(resourceBuilder);
6248
options.SetResourceBuilder(resourceBuilder);
63-
64-
options.AddOtlpExporter(otlpOptions =>
65-
{
66-
// Use IConfiguration directly for OTLP exporter endpoint option.
67-
otlpOptions.Endpoint = new Uri(
68-
appBuilder.Configuration.GetValue("Otlp:Endpoint", defaultValue: DefaultEndpoint)!);
69-
});
7049
});
7150

7251
var app = appBuilder.Build();

examples/dotnet/appsettings.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,5 @@
2121
"Url": "http://+:8083"
2222
}
2323
}
24-
},
25-
"Otlp": {
26-
"Endpoint": "http://127.0.0.1:4317"
2724
}
2825
}

examples/dotnet/docker-compose.oats.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,6 @@ services:
88
ports:
99
- 8080:8083
1010
environment:
11-
- Otlp__Endpoint=http://lgtm:4317
11+
- OTEL_EXPORTER_OTLP_ENDPOINT=http://otel-lgtm:4318
12+
- OTEL_EXPORTER_OTLP_PROTOCOL=http/protobuf
1213
- OTEL_METRIC_EXPORT_INTERVAL=5000 # so we don't have to wait 60s for metrics

examples/dotnet/docker-compose.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ services:
88
ports:
99
- 8083:8083
1010
environment:
11-
- Otlp__Endpoint=http://otel-lgtm:4318
1211
- OTEL_EXPORTER_OTLP_ENDPOINT=http://otel-lgtm:4318
1312
- OTEL_EXPORTER_OTLP_PROTOCOL=http/protobuf
1413
- OTEL_METRIC_EXPORT_INTERVAL=5000 # so we don't have to wait 60s for metrics

0 commit comments

Comments
 (0)