예제 #1
0
        internal static object Run(string zipkinUri)
        {
            // 1. Configure exporter to export traces to Zipkin
            var exporter = new ZipkinTraceExporter(
                new ZipkinTraceExporterOptions()
            {
                Endpoint    = new Uri(zipkinUri),
                ServiceName = "tracing-to-zipkin-service",
            },
                Tracing.ExportComponent);

            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;

            var collector = new StackExchangeRedisCallsCollector(null, tracer, null, Tracing.ExportComponent);

            // connect to the server
            ConnectionMultiplexer connection = ConnectionMultiplexer.Connect("localhost:6379");

            connection.RegisterProfiler(collector.GetProfilerSessionsFactory());

            // select a database (by default, DB = 0)
            IDatabase db = connection.GetDatabase();


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

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

            return(null);
        }
        private static void ConfigureOpencensus(string zipkinUri, string appInsightsKey)
        {
            //if we want to have multiple tracers
            //we should use agent mode and send first to agent

            var ocExp = new OpenCensus.Exporter.Ocagent.OcagentExporter(
                Tracing.ExportComponent
                , "http://localhost:55678"
                , Environment.MachineName
                , "distributedtracingdemo"
                );

            ocExp.Start();
            if (!string.IsNullOrEmpty(zipkinUri))
            {
                var zipK = new ZipkinTraceExporter(
                    new ZipkinTraceExporterOptions()
                {
                    Endpoint    = new Uri(zipkinUri),
                    ServiceName = "tracing-to-zipkin-service",
                },
                    Tracing.ExportComponent
                    );
                zipK.Start();
            }
            if (!string.IsNullOrEmpty(appInsightsKey))
            {
                var config = new TelemetryConfiguration(appInsightsKey);
                var appI   = new ApplicationInsightsExporter(
                    Tracing.ExportComponent,
                    Stats.ViewManager,
                    config);
                appI.Start();
            }

            //Metrics
            //define the measure to be used
            // context fields defined, that will be attached
            var invokeView = View.Create(ViewName.Create("executioncounts"), "Number of execs", numberofInvocations, Count.Create(), new[] { tagEnv, tagMachine });

            //register
            Stats.ViewManager.RegisterView(invokeView);

            // 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
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);
        }
예제 #4
0
        internal static object Run(string zipkinUri)
        {
            // 1. Configure exporter to export traces to Zipkin
            var exporter = new ZipkinTraceExporter(
                new ZipkinTraceExporterOptions()
            {
                Endpoint    = new Uri(zipkinUri),
                ServiceName = "tracing-to-zipkin-service",
            },
                Tracing.ExportComponent);

            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 (var scope = tracer.SpanBuilder("Main").StartScopedSpan())
            {
                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.ExportComponent.SpanExporter.Dispose();

            return(null);
        }
예제 #5
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);
        }
예제 #6
0
        public static object Run(string zipkinUri)
        {
            // 1. Configure exporter to export traces to Zipkin
            var exporter = new ZipkinTraceExporter(
                new ZipkinTraceExporterOptions()
            {
                Endpoint    = new Uri(zipkinUri),
                ServiceName = "trace-A",
            },
                Tracing.ExportComponent);

            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);


            //Build application
            // Microsoft.Identity.Client
            var confidentialClientApplication = PublicClientApplicationBuilder
                                                .Create("efe9af1d-0c2a-499e-bc4c-1d23c22a8a87")
                                                .Build();

            // Microsoft.Graph.auth
            DeviceCodeProvider authenticationProvider = new DeviceCodeProvider(confidentialClientApplication);



            var config = new GraphTelemetryConfiguration();

            config.LatencyConfig = new LatencyConfig {
                authenticationLatencyIsEnabled     = true,
                compressionHandlerLatencyIsEnabled = true,
            };

            var client = new GraphServiceClient(authenticationProvider: authenticationProvider, config: config);


            using (var scope = Tracing.Tracer.SpanBuilder("'v1.0/me' full request latency ").StartScopedSpan())
            {
                var user = client.Me.Request().GetAsync().GetAwaiter().GetResult();

                Console.WriteLine("Succesfully captured full latency of /me");
            }


            //using (var scope = Tracing.Tracer.SpanBuilder("v1.0/me/Drive/Root/Children ").StartScopedSpan())
            //{
            //    var driveItemsStream = client.Me.Drive.Items["01ZJ3LUMVJPVXOFF43LVA23PKLT3KRFL54"].Content.Request().GetAsync().GetAwaiter().GetResult();

            //}



            Tracing.ExportComponent.SpanExporter.Dispose();

            return(null);
        }