internal static object Run(string zipkinUri)
        {
            // Prerequisite for running this example.
            // Setup zipkin inside local docker using following command:
            // docker run -d -p 9411:9411 openzipkin/zipkin

            // To run this example, run the following command from
            // the reporoot\examples\Console\.
            // (eg: C:\repos\opentelemetry-dotnet\examples\Console\)
            //
            // dotnet run zipkin -u http://localhost:9411/api/v2/spans

            // Enable OpenTelemetry for the sources "Samples.SampleServer" and "Samples.SampleClient"
            // and use the Zipkin exporter.
            using var openTelemetry = Sdk.CreateTracerProviderBuilder()
                                      .AddSource("Samples.SampleClient", "Samples.SampleServer")
                                      .AddZipkinExporter(o =>
            {
                o.ServiceName = "test-zipkin";
                o.Endpoint    = new Uri(zipkinUri);
            })
                                      .Build();

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

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

            return(null);
        }
Exemplo n.º 2
0
        private static object RunWithActivitySource()
        {
            // Enable OpenTelemetry for the sources "Samples.SampleServer" and "Samples.SampleClient"
            // and use Console exporter.
            using var tracerProvider = Sdk.CreateTracerProviderBuilder()
                                       .AddSource("Samples.SampleClient", "Samples.SampleServer")
                                       .SetResourceBuilder(ResourceBuilder.CreateDefault().AddService("console-test"))
                                       .AddProcessor(new MyProcessor()) // This must be added before ConsoleExporter
                                       .AddConsoleExporter()
                                       .Build();

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

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

            return(null);
        }
Exemplo n.º 3
0
        internal static object Run(string zipkinUri)
        {
            /*
             * Setup zipkin inside local docker.
             * docker run -d -p 9411:9411 openzipkin/zipkin
             *
             * In zipkinUri, use http://localhost:9411/api/v2/spans
             */

            // Enable OpenTelemetry for the sources "Samples.SampleServer" and "Samples.SampleClient"
            // and use the Zipkin exporter.
            using var openTelemetry = Sdk.CreateTracerProviderBuilder()
                                      .AddSource("Samples.SampleClient", "Samples.SampleServer")
                                      .AddZipkinExporter(o =>
            {
                o.ServiceName = "test-zipkin";
                o.Endpoint    = new Uri(zipkinUri);
            })
                                      .Build();

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

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

            return(null);
        }
        private static object RunWithActivitySource(string endpoint)
        {
            // Adding the OtlpExporter creates a GrpcChannel.
            // This switch must be set before creating a GrpcChannel/HttpClient when calling an insecure gRPC service.
            // See: https://docs.microsoft.com/aspnet/core/grpc/troubleshoot#call-insecure-grpc-services-with-net-core-client
            AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport", true);

            // Enable OpenTelemetry for the sources "Samples.SampleServer" and "Samples.SampleClient"
            // and use OTLP exporter.
            using var openTelemetry = Sdk.CreateTracerProviderBuilder()
                                      .AddSource("Samples.SampleClient", "Samples.SampleServer")
                                      .SetResourceBuilder(ResourceBuilder.CreateDefault().AddService("otlp-test"))
                                      .AddOtlpExporter(opt => opt.Endpoint = new Uri(endpoint))
                                      .Build();

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

                System.Console.WriteLine("Traces are being created and exported" +
                                         "to the OpenTelemetry Collector in the background. " +
                                         "Press ENTER to stop.");
                System.Console.ReadLine();
            }

            return(null);
        }
Exemplo n.º 5
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.CreateTracerProvider(
                      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();

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

            return(null);
        }
Exemplo n.º 6
0
        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();

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

            return(null);
        }
Exemplo n.º 7
0
        private static object RunWithActivitySource(string endpoint, string protocol)
        {
            // Adding the OtlpExporter creates a GrpcChannel.
            // This switch must be set before creating a GrpcChannel when calling an insecure gRPC service.
            // See: https://docs.microsoft.com/aspnet/core/grpc/troubleshoot#call-insecure-grpc-services-with-net-core-client
            AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport", true);

            var otlpExportProtocol = ToOtlpExportProtocol(protocol);

            if (!otlpExportProtocol.HasValue)
            {
                System.Console.WriteLine($"Export protocol {protocol} is not supported. Default protocol 'grpc' will be used.");
                otlpExportProtocol = OtlpExportProtocol.Grpc;
            }

            // Enable OpenTelemetry for the sources "Samples.SampleServer" and "Samples.SampleClient"
            // and use OTLP exporter.
            using var tracerProvider = Sdk.CreateTracerProviderBuilder()
                                       .AddSource("Samples.SampleClient", "Samples.SampleServer")
                                       .SetResourceBuilder(ResourceBuilder.CreateDefault().AddService("otlp-test"))
                                       .AddOtlpExporter(opt =>
            {
                // If endpoint was not specified, the proper one will be selected according to the protocol.
                if (!string.IsNullOrEmpty(endpoint))
                {
                    opt.Endpoint = new Uri(endpoint);
                }

                opt.Protocol = otlpExportProtocol.Value;

                System.Console.WriteLine($"OTLP Exporter is using {opt.Protocol} protocol and endpoint {opt.Endpoint}");
            })
                                       .Build();

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

                System.Console.WriteLine("Traces are being created and exported " +
                                         "to the OpenTelemetry Collector in the background. " +
                                         "Press ENTER to stop.");
                System.Console.ReadLine();
            }

            return(null);
        }
        private static object RunWithActivitySource(string endpoint)
        {
            /*
             * Setup an OpenTelemetry Collector to run on local docker.
             *
             * Open a terminal window at the examples/Console/ directory and
             * launch the OpenTelemetry Collector with an OTLP receiver, by running:
             *
             *  - On Unix based systems use:
             *     docker run --rm -it -p 55680:55680 -v $(pwd):/cfg otel/opentelemetry-collector:0.7.0 --config=/cfg/otlp-collector-example/config.yaml
             *
             *  - On Windows use:
             *     docker run --rm -it -p 55680:55680 -v "%cd%":/cfg otel/opentelemetry-collector:0.7.0 --config=/cfg/otlp-collector-example/config.yaml
             *
             * On another terminal window at the examples/Console/ directory and
             * launch the OTLP example by running:
             *
             *     dotnet run -p Examples.Console.csproj otlp
             *
             * The OpenTelemetry Collector will output all received spans to the stdout of its terminal until
             * it is stopped via CTRL+C.
             *
             * For more information about the OpenTelemetry Collector go to https://github.com/open-telemetry/opentelemetry-collector
             *
             */

            // Enable OpenTelemetry for the sources "Samples.SampleServer" and "Samples.SampleClient"
            // and use OTLP exporter.
            using var openTelemetry = Sdk.CreateTracerProviderBuilder()
                                      .AddSource("Samples.SampleClient", "Samples.SampleServer")
                                      .AddOtlpExporter(opt => opt.Endpoint = endpoint)
                                      .Build();

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

                System.Console.WriteLine("Traces are being created and exported" +
                                         "to OTLP in the background. " +
                                         "Press ENTER to stop.");
                System.Console.ReadLine();
            }

            return(null);
        }
        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 = Sdk.CreateTracerProviderBuilder()
                                      .SetResourceBuilder(ResourceBuilder.CreateDefault().AddService("jaeger-test"))
                                      .AddSource("Samples.SampleClient", "Samples.SampleServer")
                                      .AddJaegerExporter(o =>
            {
                o.AgentHost = host;
                o.AgentPort = port;

                // Examples for the rest of the options, defaults unless otherwise specified
                // Omitting Process Tags example as Resource API is recommended for additional tags
                o.MaxPayloadSizeInBytes = 4096;

                // Using Batch Exporter (which is default)
                // The other option is ExportProcessorType.Simple
                o.ExportProcessorType         = ExportProcessorType.Batch;
                o.BatchExportProcessorOptions = new BatchExportProcessorOptions <Activity>()
                {
                    MaxQueueSize = 2048,
                    ScheduledDelayMilliseconds  = 5000,
                    ExporterTimeoutMilliseconds = 30000,
                    MaxExportBatchSize          = 512,
                };
            })
                                      .Build();

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

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

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

            return(null);
        }
        private static void RunWithActivitySource(ICollection <Activity> exportedItems)
        {
            // Enable OpenTelemetry for the sources "Samples.SampleServer" and "Samples.SampleClient"
            // and use InMemory exporter.
            using var tracerProvider = Sdk.CreateTracerProviderBuilder()
                                       .AddSource("Samples.SampleClient", "Samples.SampleServer")
                                       .SetResourceBuilder(ResourceBuilder.CreateDefault().AddService("inmemory-test"))
                                       .AddInMemoryExporter(exportedItems)
                                       .Build();

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

            System.Console.WriteLine("Traces are being created and exported " +
                                     "to the collection passed in the background. " +
                                     "Press ENTER to stop.");
            System.Console.ReadLine();
        }
        private static object RunWithActivitySource(string endpoint)
        {
            // Enable OpenTelemetry for the sources "Samples.SampleServer" and "Samples.SampleClient"
            // and use OTLP exporter.
            using var openTelemetry = Sdk.CreateTracerProviderBuilder()
                                      .AddSource("Samples.SampleClient", "Samples.SampleServer")
                                      .AddOtlpExporter(opt => opt.Endpoint = endpoint)
                                      .Build();

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

                System.Console.WriteLine("Traces are being created and exported" +
                                         "to the OpenTelemetry Collector in the background. " +
                                         "Press ENTER to stop.");
                System.Console.ReadLine();
            }

            return(null);
        }