Skip to content

Commit 4a596ea

Browse files
Change OTLP endpoint to use HTTP (#735)
Refactor the .NET example to detect #734. Resolves #734. --------- Signed-off-by: Martin Costello <martin@martincostello.com>
1 parent f232736 commit 4a596ea

File tree

4 files changed

+6
-29
lines changed

4 files changed

+6
-29
lines changed

examples/dotnet/Program.cs

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1+
using OpenTelemetry;
12
using OpenTelemetry.Instrumentation.AspNetCore;
2-
using OpenTelemetry.Logs;
33
using OpenTelemetry.Metrics;
44
using OpenTelemetry.Resources;
55
using OpenTelemetry.Trace;
@@ -13,12 +13,11 @@
1313
serviceVersion: typeof(Program).Assembly.GetName().Version?.ToString() ?? "unknown",
1414
serviceInstanceId: Environment.MachineName);
1515

16-
const string DefaultEndpoint = "http://127.0.0.1:4317";
17-
1816
// Configure OpenTelemetry tracing and metrics with auto-start using the
1917
// AddOpenTelemetry() extension method from the OpenTelemetry.Extensions.Hosting package.
2018
appBuilder.Services.AddOpenTelemetry()
2119
.ConfigureResource(configureResource)
20+
.UseOtlpExporter()
2221
.WithTracing(builder =>
2322
{
2423
builder
@@ -28,26 +27,12 @@
2827
// Use IConfiguration binding for AspNetCore instrumentation options.
2928
appBuilder.Services.Configure<AspNetCoreTraceInstrumentationOptions>(
3029
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-
});
3830
})
3931
.WithMetrics(builder =>
4032
{
4133
builder
4234
.AddHttpClientInstrumentation()
4335
.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-
});
5136
});
5237

5338
// Clear default logging providers used by WebApplication host.
@@ -60,13 +45,6 @@
6045
var resourceBuilder = ResourceBuilder.CreateDefault();
6146
configureResource(resourceBuilder);
6247
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-
});
7048
});
7149

7250
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://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: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ services:
88
ports:
99
- 8083:8083
1010
environment:
11-
- Otlp__Endpoint=http://otel-lgtm:4317
11+
- OTEL_EXPORTER_OTLP_ENDPOINT=http://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
1314
depends_on:
1415
- otel-lgtm

0 commit comments

Comments
 (0)