forked from open-telemetry/opentelemetry-dotnet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTestHttpClient.cs
41 lines (34 loc) · 1.22 KB
/
TestHttpClient.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
38
39
40
41
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
using System.Diagnostics;
using OpenTelemetry;
using OpenTelemetry.Resources;
using OpenTelemetry.Trace;
namespace Examples.Console;
internal class TestHttpClient
{
// To run this example, run the following command from
// the reporoot\examples\Console\.
// (eg: C:\repos\opentelemetry-dotnet\examples\Console\)
//
// dotnet run httpclient
internal static object Run()
{
System.Console.WriteLine("Hello World!");
using var tracerProvider = Sdk.CreateTracerProviderBuilder()
.AddHttpClientInstrumentation()
.ConfigureResource(r => r.AddService("http-service-example"))
.AddSource("http-client-test")
.AddConsoleExporter()
.Build();
using var source = new ActivitySource("http-client-test");
using (var parent = source.StartActivity("incoming request", ActivityKind.Server))
{
using var client = new HttpClient();
client.GetStringAsync("http://bing.com").GetAwaiter().GetResult();
}
System.Console.WriteLine("Press Enter key to exit.");
System.Console.ReadLine();
return null;
}
}