/// <summary> /// Creates an instance of <see cref="ITracer"/>. /// </summary> /// <param name="startEndHandler">Start/end event handler.</param> /// <param name="traceConfig">Trace configuration.</param> /// <param name="spanExporter">Exporter for span.</param> /// <param name="binaryFormat">Binary format context propagator.</param> /// <param name="textFormat">Text format context propagator.</param> public Tracer(IStartEndHandler startEndHandler, ITraceConfig traceConfig, SpanExporter spanExporter, IBinaryFormat binaryFormat, ITextFormat textFormat) { this.spanBuilderOptions = new SpanBuilderOptions(startEndHandler, traceConfig); this.spanExporter = spanExporter ?? (SpanExporter)SpanExporter.Create(ExporterBufferSize, ExporterScheduleDelay); this.BinaryFormat = binaryFormat ?? new BinaryFormat(); this.TextFormat = textFormat ?? new TraceContextFormat(); }
internal SpanBuilderOptions(IRandomGenerator randomGenerator, IStartEndHandler startEndHandler, IClock clock, ITraceConfig traceConfig) { RandomHandler = randomGenerator; StartEndHandler = startEndHandler; Clock = clock; TraceConfig = traceConfig; }
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); }
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); }
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); }
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); }
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); }
public Tracer(IRandomGenerator randomGenerator, IStartEndHandler startEndHandler, ITraceConfig traceConfig, IExportComponent exportComponent, IBinaryFormat binaryFormat, ITextFormat textFormat) { this.spanBuilderOptions = new SpanBuilderOptions(randomGenerator, startEndHandler, traceConfig); this.binaryFormat = binaryFormat ?? new BinaryFormat(); this.textFormat = textFormat ?? new TraceContextFormat(); }
public TracerTest() { startEndHandler = Mock.Of <IStartEndHandler>(); traceConfig = Mock.Of <ITraceConfig>(); tracer = new Tracer(new RandomGenerator(), startEndHandler, TestClock.Create(), traceConfig); }
public TracerTest() { startEndHandler = Mock.Of <IStartEndHandler>(); traceConfig = Mock.Of <ITraceConfig>(); tracer = new Tracer(new RandomGenerator(), startEndHandler, traceConfig, null); }
public Tracer(IRandomGenerator randomGenerator, IStartEndHandler startEndHandler, IClock clock, ITraceConfig traceConfig) { spanBuilderOptions = new SpanBuilderOptions(randomGenerator, startEndHandler, clock, traceConfig); }
internal SpanBuilderOptions(IStartEndHandler startEndHandler, ITraceConfig traceConfig) { this.StartEndHandler = startEndHandler; this.TraceConfig = traceConfig; }
/// <summary> /// Creates an instance of <see cref="ITracer"/>. /// </summary> /// <param name="startEndHandler">Start/end event handler.</param> /// <param name="traceConfig">Trace configuration.</param> public Tracer(IStartEndHandler startEndHandler, ITraceConfig traceConfig) : this(startEndHandler, traceConfig, null, null, null) { }
internal SpanBuilderOptions(IRandomGenerator randomGenerator, IStartEndHandler startEndHandler, ITraceConfig traceConfig) { this.RandomHandler = randomGenerator; this.StartEndHandler = startEndHandler; this.TraceConfig = traceConfig; }
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); }
public Tracer(IRandomGenerator randomGenerator, IStartEndHandler startEndHandler, ITraceConfig traceConfig, IExportComponent exportComponent) : this(randomGenerator, startEndHandler, traceConfig, exportComponent, null, null) { }
public Tracer(IRandomGenerator randomGenerator, IStartEndHandler startEndHandler, ITraceConfig traceConfig, IExportComponent exportComponent) { this.spanBuilderOptions = new SpanBuilderOptions(randomGenerator, startEndHandler, traceConfig); }
public TracerTest() { startEndHandler = Mock.Of <IStartEndHandler>(); traceConfig = Mock.Of <ITraceConfig>(); tracer = new Tracer(startEndHandler, traceConfig); }