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