|
| 1 | +using OpenTelemetry; |
1 | 2 | using OpenTelemetry.Instrumentation.AspNetCore;
|
2 |
| -using OpenTelemetry.Logs; |
3 | 3 | using OpenTelemetry.Metrics;
|
4 | 4 | using OpenTelemetry.Resources;
|
5 | 5 | using OpenTelemetry.Trace;
|
|
13 | 13 | serviceVersion: typeof(Program).Assembly.GetName().Version?.ToString() ?? "unknown",
|
14 | 14 | serviceInstanceId: Environment.MachineName);
|
15 | 15 |
|
16 |
| -const string DefaultEndpoint = "http://127.0.0.1:4317"; |
17 |
| - |
18 | 16 | // Configure OpenTelemetry tracing and metrics with auto-start using the
|
19 | 17 | // AddOpenTelemetry() extension method from the OpenTelemetry.Extensions.Hosting package.
|
20 | 18 | appBuilder.Services.AddOpenTelemetry()
|
21 | 19 | .ConfigureResource(configureResource)
|
| 20 | + .UseOtlpExporter() |
22 | 21 | .WithTracing(builder =>
|
23 | 22 | {
|
24 | 23 | builder
|
|
28 | 27 | // Use IConfiguration binding for AspNetCore instrumentation options.
|
29 | 28 | appBuilder.Services.Configure<AspNetCoreTraceInstrumentationOptions>(
|
30 | 29 | 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 |
| - }); |
38 | 30 | })
|
39 | 31 | .WithMetrics(builder =>
|
40 | 32 | {
|
41 | 33 | builder
|
42 | 34 | .AddHttpClientInstrumentation()
|
43 | 35 | .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 |
| - }); |
51 | 36 | });
|
52 | 37 |
|
53 | 38 | // Clear default logging providers used by WebApplication host.
|
|
60 | 45 | var resourceBuilder = ResourceBuilder.CreateDefault();
|
61 | 46 | configureResource(resourceBuilder);
|
62 | 47 | 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 |
| - }); |
70 | 48 | });
|
71 | 49 |
|
72 | 50 | var app = appBuilder.Build();
|
|
0 commit comments