internal static object Run(OpenTracingShimOptions options) { // Enable OpenTelemetry for the source "MyCompany.MyProduct.MyWebServer" // and use Console exporter. using var openTelemetry = Sdk.CreateTracerProviderBuilder() .AddSource("MyCompany.MyProduct.MyWebServer") .SetResource(Resources.CreateServiceResource("MyServiceName")) .AddConsoleExporter(opt => opt.DisplayAsJson = options.DisplayAsJson) .Build(); // The above line is required only in applications // which decide to use OpenTelemetry. // Following shows how to use the OpenTracing shim var tracer = new TracerShim(TracerProvider.Default.GetTracer("MyCompany.MyProduct.MyWebServer"), new TextMapPropagator()); using (IScope parentScope = tracer.BuildSpan("Parent").StartActive(finishSpanOnDispose: true)) { parentScope.Span.SetTag("my", "value"); parentScope.Span.SetOperationName("parent span new name"); // The child scope will automatically use parentScope as its parent. using (IScope childScope = tracer.BuildSpan("Child").StartActive(finishSpanOnDispose: true)) { childScope.Span.SetTag("Child Tag", "Child Tag Value").SetTag("ch", "value").SetTag("more", "attributes"); } } System.Console.WriteLine("Press Enter key to exit."); return null; }
public void BuildSpan_NotNull() { var tracer = TracerProvider.Default.GetTracer(TracerName); var shim = new TracerShim(tracer, new TextMapPropagator()); // Internals of the SpanBuilderShim tested elsewhere Assert.NotNull(shim.BuildSpan("foo") as SpanBuilderShim); }
public void BuildSpan_NotNull() { var tracerMock = new Mock <Trace.Tracer>(); var shim = new TracerShim(tracerMock.Object, new TraceContextFormat(), new BinaryFormat()); // Internals of the SpanBuilderShim tested elsewhere Assert.NotNull(shim.BuildSpan("foo") as SpanBuilderShim); }
public void BuildSpan_NotNull() { var tracer = TracerProvider.GetTracer(TracerName); var shim = new TracerShim(tracer, new TraceContextFormat()); // Internals of the SpanBuilderShim tested elsewhere Assert.NotNull(shim.BuildSpan("foo") as SpanBuilderShim); }
internal static object Run(OpenTracingShimOptions options) { // Enable OpenTelemetry for the source "MyCompany.MyProduct.MyWebServer" // and use Console exporter. using var openTelemetry = Sdk.CreateTracerProviderBuilder() .AddSource("MyCompany.MyProduct.MyWebServer") .SetResourceBuilder(ResourceBuilder.CreateDefault().AddService("MyServiceName")) .AddConsoleExporter() .Build(); // Instantiate the OpenTracing shim. The underlying OpenTelemetry tracer will create // spans using the "MyCompany.MyProduct.MyWebServer" source. var tracer = new TracerShim( TracerProvider.Default.GetTracer("MyCompany.MyProduct.MyWebServer"), Propagators.DefaultTextMapPropagator); // Not necessary for this example, though it is best practice per // the OpenTracing project to register a GlobalTracer. OpenTracing.Util.GlobalTracer.Register(tracer); // The code below is meant to resemble application code that has been instrumented // with the OpenTracing API. using (IScope parentScope = tracer.BuildSpan("Parent").StartActive(finishSpanOnDispose: true)) { parentScope.Span.SetTag("my", "value"); parentScope.Span.SetOperationName("parent span new name"); // The child scope will automatically use parentScope as its parent. using (IScope childScope = tracer.BuildSpan("Child").StartActive(finishSpanOnDispose: true)) { childScope.Span.SetTag("Child Tag", "Child Tag Value").SetTag("ch", "value").SetTag("more", "attributes"); } } System.Console.WriteLine("Press Enter key to exit."); System.Console.ReadLine(); return(null); }