/
DemoTrace.cs
37 lines (31 loc) · 1.3 KB
/
DemoTrace.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.
using OpenTelemetry.Resources;
using System.Diagnostics;
// This alias is necessary because it will otherwise try to default to "Microsoft.Azure.Monitor.OpenTelemetry.Sdk" which doesn't exist.
using OpenTelemetrySdk = OpenTelemetry.Sdk;
namespace Microsoft.OpenTelemetry.Exporter.AzureMonitor.Demo.Tracing
{
public static class DemoTrace
{
public static readonly ActivitySource source = new ActivitySource("DemoSource");
public static void Main()
{
var resource = Resources.CreateServiceResource("my-service", "roleinstance1", "my-namespace");
using var tracerProvider = OpenTelemetrySdk.CreateTracerProviderBuilder()
.SetResource(resource)
.AddSource("Demo.DemoServer")
.AddSource("Demo.DemoClient")
.AddAzureMonitorTraceExporter(o => {
o.ConnectionString = $"InstrumentationKey=Ikey;";
})
.Build();
using (var sample = new InstrumentationWithActivitySource())
{
sample.Start();
System.Console.WriteLine("Press ENTER to stop.");
System.Console.ReadLine();
}
}
}
}