Example #1
0
        internal static object Run(string host, int port)
        {
            // 1. Configure exporter to export traces to Jaeger
            var exporter = new JaegerExporter(
                new JaegerExporterOptions
            {
                ServiceName = "tracing-to-jaeger-service",
                AgentHost   = host,
                AgentPort   = port,
            },
                Tracing.SpanExporter);

            exporter.Start();

            // 2. Configure 100% sample rate for the purposes of the demo
            ITraceConfig traceConfig   = Tracing.TraceConfig;
            ITraceParams currentConfig = traceConfig.ActiveTraceParams;
            var          newConfig     = currentConfig.ToBuilder()
                                         .SetSampler(Samplers.AlwaysSample)
                                         .Build();

            traceConfig.UpdateActiveTraceParams(newConfig);

            // 3. Tracer is global singleton. You can register it via dependency injection if it exists
            // but if not - you can use it as follows:
            var tracer = Tracing.Tracer;

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

            // 5. Gracefully shutdown the exporter so it'll flush queued traces to Zipkin.
            Tracing.SpanExporter.Dispose();

            return(null);
        }
Example #2
0
        private static void ConsfigExporter()
        {
            // 1. Configure exporter to export traces to Jaeger
            var exporter = new JaegerExporter(
                new JaegerExporterOptions
            {
                ServiceName = "OpenTelemetrySample",
                AgentHost   = "localhost",
                AgentPort   = 5775,
            },
                Tracing.SpanExporter);

            exporter.Start();

            // 2. Configure 100% sample rate for the purposes of the demo
            ITraceConfig traceConfig   = Tracing.TraceConfig;
            ITraceParams currentConfig = traceConfig.ActiveTraceParams;
            var          newConfig     = currentConfig.ToBuilder()
                                         .SetSampler(Samplers.AlwaysSample)
                                         .Build();

            traceConfig.UpdateActiveTraceParams(newConfig);
        }