Пример #1
0
        internal static object RunWithActivity(string host, int port)
        {
            // Enable OpenTelemetry for the sources "Samples.SampleServer" and "Samples.SampleClient"
            // and use the Jaeger exporter.
            using var openTelemetry = OpenTelemetrySdk.EnableOpenTelemetry(
                      builder => builder
                      .AddActivitySource("Samples.SampleServer")
                      .AddActivitySource("Samples.SampleClient")
                      .UseJaegerExporter(o =>
            {
                o.ServiceName = "jaeger-test";
                o.AgentHost   = host;
                o.AgentPort   = port;
            }));

            // The above lines are required only in Applications
            // which decide to use OT.

            using (var sample = new InstrumentationWithActivitySource())
            {
                sample.Start();

                Console.WriteLine("Traces are being created and exported" +
                                  "to Jaeger in the background. Use Jaeger to view them." +
                                  "Press ENTER to stop.");
                Console.ReadLine();
            }

            return(null);
        }
        internal static object Run(string zipkinUri)
        {
            // Enable OpenTelemetry for the sources "Samples.SampleServer" and "Samples.SampleClient"
            // and use the Zipkin exporter.
            using var openTelemetry = OpenTelemetrySdk.EnableOpenTelemetry(
                      builder => builder
                      .AddActivitySource("Samples.SampleServer")
                      .AddActivitySource("Samples.SampleClient")
                      .UseZipkinExporter(o =>
            {
                o.ServiceName = "test-zipkin";
                o.Endpoint    = new Uri(zipkinUri);
            }));

            using (var sample = new InstrumentationWithActivitySource())
            {
                sample.Start();

                Console.WriteLine("Traces are being created and exported" +
                                  "to Zipkin in the background. Use Zipkin to view them." +
                                  "Press ENTER to stop.");
                Console.ReadLine();
            }

            return(null);
        }
Пример #3
0
        internal static object Run(string zipkinUri, bool useActivitySource)
        {
            if (useActivitySource)
            {
                // Enable OpenTelemetry for the sources "Samples.SampleServer" and "Samples.SampleClient"
                // and use the Zipkin exporter.
                using var openTelemetry = OpenTelemetrySdk.EnableOpenTelemetry(
                          builder => builder
                          .AddActivitySource("Samples.SampleServer")
                          .AddActivitySource("Samples.SampleClient")
                          .UseZipkinActivityExporter(o =>
                {
                    o.ServiceName = "test-zipkin";
                    o.Endpoint    = new Uri(zipkinUri);
                }));

                using (var sample = new InstrumentationWithActivitySource())
                {
                    sample.Start();

                    Console.WriteLine("Sample is running on the background, press ENTER to stop");
                    Console.ReadLine();
                }
            }
            else
            {
                // Configure exporter to export traces to Zipkin
                using (var tracerFactory = TracerFactory.Create(builder => builder
                                                                .UseZipkin(o =>
                {
                    o.ServiceName = "test-zipkin";
                    o.Endpoint = new Uri(zipkinUri);
                })))
                {
                    var tracer = tracerFactory.GetTracer("zipkin-test");

                    // Create a scoped span. It will end automatically when using statement ends
                    using (tracer.WithSpan(tracer.StartSpan("Main")))
                    {
                        Console.WriteLine("About to do a busy work");
                        for (var i = 0; i < 10; i++)
                        {
                            DoWork(i, tracer);
                        }
                    }
                }
            }

            return(null);
        }
Пример #4
0
        private static object RunWithActivitySource(string endpoint)
        {
            // Enable OpenTelemetry for the sources "Samples.SampleServer" and "Samples.SampleClient"
            // and use OTLP exporter.
            using var openTelemetry = OpenTelemetrySdk.EnableOpenTelemetry(
                      builder => builder
                      .AddActivitySource("Samples.SampleServer")
                      .AddActivitySource("Samples.SampleClient")
                      .UseOpenTelemetryProtocolActivityExporter(opt => opt.Endpoint = endpoint));

            // The above line is required only in Applications
            // which decide to use OT.
            using (var sample = new InstrumentationWithActivitySource())
            {
                sample.Start();

                Console.WriteLine("Sample is running on the background, press ENTER to stop");
                Console.ReadLine();
            }

            return(null);
        }