|
1 | | -// See https://aka.ms/new-console-template for more information |
2 | | - |
| 1 | +using OpenTelemetry.Resources; |
| 2 | +using OpenTelemetry.Trace; |
3 | 3 | using ConsoleApp; |
4 | 4 | using ConsoleApp.Models.Configuration; |
5 | 5 | using ConsoleApp.Services; |
|
8 | 8 | using Microsoft.Extensions.Hosting; |
9 | 9 | using Microsoft.Identity.Client; |
10 | 10 | using Serilog; |
| 11 | +using OpenTelemetry.Logs; |
11 | 12 |
|
12 | 13 | var builder = Host.CreateDefaultBuilder(args) |
| 14 | + .ConfigureAppConfiguration((hostContext, configBuilder) => |
| 15 | + { |
| 16 | + configBuilder.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true); |
| 17 | + configBuilder.AddUserSecrets<Program>(); |
| 18 | + configBuilder.AddEnvironmentVariables(); |
| 19 | + configBuilder.AddCommandLine(args); |
| 20 | + }) |
13 | 21 | .ConfigureServices((hostContext, services) => |
14 | 22 | { |
15 | 23 | services.AddHostedService<WorkerService>(); |
|
21 | 29 | { |
22 | 30 | httpClient.BaseAddress = new Uri("https://graph.microsoft.com/"); |
23 | 31 | }); |
24 | | - }) |
25 | | - .ConfigureAppConfiguration((hostContext, configBuilder) => |
26 | | - { |
27 | | - configBuilder.AddUserSecrets<Program>(); |
| 32 | + |
| 33 | + var otlpEndpoint = hostContext.Configuration.GetValue<string>("OpenTelemetry:OtlpEndpoint"); |
| 34 | + |
| 35 | + services.AddOpenTelemetry() |
| 36 | + .WithTracing(builder => |
| 37 | + { |
| 38 | + builder |
| 39 | + .SetResourceBuilder(ResourceBuilder.CreateDefault().AddService(nameof(ConsoleApp))) |
| 40 | + .AddOtlpExporter(options => |
| 41 | + { |
| 42 | + options.Endpoint = new Uri(otlpEndpoint); |
| 43 | + }); |
| 44 | + }) |
| 45 | + .WithLogging(builder => |
| 46 | + { |
| 47 | + builder.AddConsoleExporter(); |
| 48 | + }); |
28 | 49 | }) |
29 | 50 | .UseSerilog((context, configuration) => |
30 | 51 | { |
|
0 commit comments