/
Program.cs
37 lines (29 loc) · 1023 Bytes
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
#if NET6_0_OR_GREATER
using System.Diagnostics;
using System.Net.Http;
using Azure.Monitor.OpenTelemetry.AspNetCore;
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddOpenTelemetry().UseAzureMonitor();
/*
builder.Services.AddOpenTelemetry().UseAzureMonitor(o =>
{
o.ConnectionString = "InstrumentationKey=00000000-0000-0000-0000-00000000CODE";
// Set the Credential property to enable AAD based authentication:
// o.Credential = new DefaultAzureCredential();
});
*/
var app = builder.Build();
app.MapGet("/", () =>
{
app.Logger.LogInformation("Hello World!");
using var client = new HttpClient();
var response = client.GetAsync("https://www.bing.com/").Result;
return $"Hello World! OpenTelemetry Trace: {Activity.Current?.Id}";
});
app.Run();
#endif