2
2
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
3
3
// See the LICENSE file in the project root for more information
4
4
5
- using System . Diagnostics ;
5
+ using Elastic . OpenTelemetry ;
6
+ using Microsoft . Extensions . Logging ;
6
7
using OpenTelemetry ;
7
- using OpenTelemetry . Resources ;
8
- using OpenTelemetry . Trace ;
9
8
10
9
namespace Example . Console ;
11
10
12
11
internal static class Usage
13
12
{
14
- private const string ActivitySourceName = "CustomActivitySource" ;
15
- private static readonly ActivitySource ActivitySource = new ( ActivitySourceName , "1.0.0" ) ;
16
- private static readonly HttpClient HttpClient = new ( ) ;
17
-
18
- public static async Task BasicBuilderUsageAsync ( )
13
+ public static void BasicBuilderUsage ( )
19
14
{
20
15
// NOTE: This sample assumes ENV VARs have been set to configure the Endpoint and Authorization header.
21
16
@@ -48,10 +43,20 @@ public static async Task BasicBuilderUsageAsync()
48
43
// .AddConsoleExporter())
49
44
// .Build();
50
45
46
+ using var loggerFactory = LoggerFactory . Create ( static builder =>
47
+ {
48
+ builder
49
+ . AddFilter ( "Elastic.OpenTelemetry" , LogLevel . Debug )
50
+ . AddConsole ( ) ;
51
+ } ) ;
52
+
53
+ var options = new ElasticOpenTelemetryOptions
54
+ {
55
+ AdditionalLoggerFactory = loggerFactory
56
+ } ;
57
+
51
58
using var sdk = OpenTelemetrySdk . Create ( builder => builder
52
- . WithElasticDefaults ( )
53
- . ConfigureResource ( resource => resource
54
- . AddService ( "MyCustomServiceName" ) ) ) ;
59
+ . WithElasticDefaults ( options ) ) ;
55
60
56
61
//This is the most flexible approach for a consumer as they can include our processor(s)
57
62
//using var tracerProvider = Sdk.CreateTracerProviderBuilder()
@@ -62,23 +67,23 @@ public static async Task BasicBuilderUsageAsync()
62
67
// serviceVersion: "1.0.0"))
63
68
// .AddConsoleExporter()
64
69
// .AddElasticProcessors()
65
- // .Build();
70
+ //// .Build();
66
71
67
- await DoStuffAsync ( ) ;
72
+ // await DoStuffAsync();
68
73
69
- static async Task DoStuffAsync ( )
70
- {
71
- using var activity = ActivitySource . StartActivity ( "DoingStuff" , ActivityKind . Internal ) ;
72
- activity ? . SetTag ( "CustomTag" , "TagValue" ) ;
74
+ // static async Task DoStuffAsync()
75
+ // {
76
+ // using var activity = ActivitySource.StartActivity("DoingStuff", ActivityKind.Internal);
77
+ // activity?.SetTag("CustomTag", "TagValue");
73
78
74
- await Task . Delay ( 100 ) ;
75
- var response = await HttpClient . GetAsync ( "http://elastic.co" ) ;
76
- await Task . Delay ( 50 ) ;
79
+ // await Task.Delay(100);
80
+ // var response = await HttpClient.GetAsync("http://elastic.co");
81
+ // await Task.Delay(50);
77
82
78
- if ( response . StatusCode == System . Net . HttpStatusCode . OK )
79
- activity ? . SetStatus ( ActivityStatusCode . Ok ) ;
80
- else
81
- activity ? . SetStatus ( ActivityStatusCode . Error ) ;
82
- }
83
+ // if (response.StatusCode == System.Net.HttpStatusCode.OK)
84
+ // activity?.SetStatus(ActivityStatusCode.Ok);
85
+ // else
86
+ // activity?.SetStatus(ActivityStatusCode.Error);
87
+ // }
83
88
}
84
89
}
0 commit comments