/// <summary> /// Creates an instance of <see cref="ITracer"/>. /// </summary> /// <param name="spanProcessor">Span processor.</param> /// <param name="traceConfig">Trace configuration.</param> public Tracer(SpanProcessor spanProcessor, TraceConfig traceConfig) { this.spanProcessor = spanProcessor ?? throw new ArgumentNullException(nameof(spanProcessor)); this.ActiveTraceConfig = traceConfig ?? throw new ArgumentNullException(nameof(traceConfig)); this.BinaryFormat = new BinaryFormat(); this.TextFormat = new TraceContextFormat(); }
/// <summary> /// Creates an instance of <see cref="Tracer"/>. /// </summary> /// <param name="spanProcessor">Span processor.</param> /// <param name="traceConfig">Trace configuration.</param> /// <param name="binaryFormat">Binary format context propagator.</param> /// <param name="textFormat">Text format context propagator.</param> public Tracer(SpanProcessor spanProcessor, TraceConfig traceConfig, IBinaryFormat binaryFormat, ITextFormat textFormat) { this.spanProcessor = spanProcessor ?? throw new ArgumentNullException(nameof(spanProcessor)); this.ActiveTraceConfig = traceConfig ?? throw new ArgumentNullException(nameof(traceConfig)); this.BinaryFormat = binaryFormat ?? throw new ArgumentNullException(nameof(binaryFormat)); this.TextFormat = textFormat ?? throw new ArgumentNullException(nameof(textFormat)); }
/// <summary> /// Initializes a new instance of the <see cref="TracerSdk"/> class. /// </summary> /// <param name="spanProcessor">Span processor.</param> /// <param name="sampler">Sampler to use.</param> /// <param name="tracerConfiguration">Trace configuration.</param> /// <param name="libraryResource">Resource describing the instrumentation library.</param> internal TracerSdk(SpanProcessor spanProcessor, Sampler sampler, TracerConfiguration tracerConfiguration, Resource libraryResource) { this.spanProcessor = spanProcessor ?? throw new ArgumentNullException(nameof(spanProcessor)); this.tracerConfiguration = tracerConfiguration ?? throw new ArgumentNullException(nameof(tracerConfiguration)); this.LibraryResource = libraryResource ?? throw new ArgumentNullException(nameof(libraryResource)); this.sampler = sampler ?? throw new ArgumentNullException(nameof(sampler)); }
private TracerFactory(TracerBuilder builder) { this.sampler = builder.Sampler ?? Samplers.AlwaysSample; // TODO separate sampler from options this.configurationOptions = builder.TracerConfigurationOptions ?? new TracerConfiguration(this.sampler); // TODO log warning (or throw?) if there is no exporter this.exporter = builder.SpanExporter ?? new NoopSpanExporter(); this.spanProcessor = builder.ProcessorFactory != null? builder.ProcessorFactory(this.exporter) : new BatchingSpanProcessor(this.exporter); this.binaryFormat = builder.BinaryFormat ?? new BinaryFormat(); this.textFormat = builder.TextFormat ?? new TraceContextFormat(); this.defaultTracer = new Tracer( this.spanProcessor, this.configurationOptions, this.binaryFormat, this.textFormat, Resource.Empty); }
internal Span( Activity activity, Tracestate tracestate, SpanKind spanKind, TraceConfig traceConfig, SpanProcessor spanProcessor, DateTimeOffset startTimestamp, bool ownsActivity) { this.Activity = activity; this.spanContext = new Lazy <SpanContext>(() => SpanContext.Create( this.Activity.TraceId, this.Activity.SpanId, this.Activity.ActivityTraceFlags, tracestate)); this.Name = this.Activity.OperationName; this.traceConfig = traceConfig; this.spanProcessor = spanProcessor; this.Kind = spanKind; this.OwnsActivity = ownsActivity; this.IsRecordingEvents = this.Activity.Recorded; this.startTimestamp = startTimestamp; if (this.IsRecordingEvents) { this.spanProcessor.OnStart(this); } }
public void ProcessorDoesNotBlockOnExporter() { spanExporter = new TestExporter(async _ => await Task.Delay(500)); spanProcessor = new SimpleSpanProcessor(spanExporter); var sampledActivity = new Activity("foo"); sampledActivity.ActivityTraceFlags |= ActivityTraceFlags.Recorded; sampledActivity.SetIdFormat(ActivityIdFormat.W3C); sampledActivity.Start(); var span = new Span( sampledActivity, Tracestate.Empty, SpanKind.Internal, TraceConfig.Default, spanProcessor, PreciseTimestamp.GetUtcNow(), default); // does not block var sw = Stopwatch.StartNew(); span.End(); sw.Stop(); Assert.InRange(sw.Elapsed, TimeSpan.Zero, TimeSpan.FromMilliseconds(100)); var exported = WaitForSpans(spanExporter, 1, TimeSpan.FromMilliseconds(600)); Assert.Single(exported); }
internal Span( Activity activity, IEnumerable <KeyValuePair <string, string> > tracestate, SpanKind spanKind, TracerConfiguration tracerConfiguration, SpanProcessor spanProcessor, DateTimeOffset startTimestamp, bool ownsActivity, Resource libraryResource) { this.Activity = activity; this.spanContext = new Lazy <SpanContext>(() => new SpanContext( this.Activity.TraceId, this.Activity.SpanId, this.Activity.ActivityTraceFlags, tracestate)); this.Name = this.Activity.OperationName; this.tracerConfiguration = tracerConfiguration; this.spanProcessor = spanProcessor; this.Kind = spanKind; this.OwnsActivity = ownsActivity; this.IsRecordingEvents = this.Activity.Recorded; this.startTimestamp = startTimestamp; this.LibraryResource = libraryResource; if (this.IsRecordingEvents) { this.spanProcessor.OnStart(this); } }
/// <summary> /// Creates an instance of <see cref="Tracer"/>. /// </summary> /// <param name="spanProcessor">Span processor.</param> /// <param name="traceConfig">Trace configuration.</param> /// <param name="binaryFormat">Binary format context propagator.</param> /// <param name="textFormat">Text format context propagator.</param> public Tracer(SpanProcessor spanProcessor, TraceConfig traceConfig, IBinaryFormat binaryFormat, ITextFormat textFormat) { this.spanProcessor = spanProcessor ?? new SimpleSpanProcessor(new NoopSpanExporter()); this.ActiveTraceConfig = traceConfig; this.BinaryFormat = binaryFormat ?? new BinaryFormat(); this.TextFormat = textFormat ?? new TraceContextFormat(); }
internal SpanBuilder(string name, SpanProcessor spanProcessor, TracerConfiguration tracerConfiguration, Resource libraryResource) { this.name = name ?? throw new ArgumentNullException(nameof(name)); this.spanProcessor = spanProcessor ?? throw new ArgumentNullException(nameof(spanProcessor)); this.tracerConfiguration = tracerConfiguration ?? throw new ArgumentNullException(nameof(tracerConfiguration)); this.libraryResource = libraryResource ?? throw new ArgumentNullException(nameof(libraryResource)); }
private Span( string name, SpanContext parentSpanContext, ActivityAndTracestate activityAndTracestate, bool ownsActivity, SpanKind spanKind, SpanCreationOptions spanCreationOptions, TracerConfiguration tracerConfiguration, SpanProcessor spanProcessor, Resource libraryResource) { this.Name = name; this.LibraryResource = libraryResource; IEnumerable <Link> links = null; if (spanCreationOptions != null) { links = spanCreationOptions.Links ?? spanCreationOptions.LinksFactory?.Invoke(); this.startTimestamp = spanCreationOptions.StartTimestamp; } if (this.startTimestamp == default) { this.startTimestamp = PreciseTimestamp.GetUtcNow(); } this.tracerConfiguration = tracerConfiguration; this.spanProcessor = spanProcessor; this.Kind = spanKind; this.OwnsActivity = ownsActivity; this.Activity = activityAndTracestate.Activity; var tracestate = activityAndTracestate.Tracestate; this.IsRecording = MakeSamplingDecision( parentSpanContext, name, null, links, // we'll enumerate again, but double enumeration over small collection is cheaper than allocation this.Activity.TraceId, this.Activity.SpanId, this.tracerConfiguration); if (this.IsRecording) { this.Activity.ActivityTraceFlags |= ActivityTraceFlags.Recorded; this.SetLinks(links); this.spanProcessor.OnStart(this); } else { this.Activity.ActivityTraceFlags &= ~ActivityTraceFlags.Recorded; } // this context is definitely not remote, setting isRemote to false this.Context = new SpanContext(this.Activity.TraceId, this.Activity.SpanId, this.Activity.ActivityTraceFlags, false, tracestate); }
public TracerTest() { spanProcessor = new SimpleSpanProcessor(new TestExporter(null)); tracerConfiguration = new TracerConfiguration(); tracerFactory = TracerFactory.Create(b => b .AddProcessorPipeline(p => p.AddProcessor(_ => spanProcessor))); this.tracerSdk = (TracerSdk)tracerFactory.GetTracer(null); }
/// <summary> /// Creates an instance of <see cref="Tracer"/>. /// </summary> /// <param name="spanProcessor">Span processor.</param> /// <param name="tracerConfiguration">Trace configuration.</param> /// <param name="binaryFormat">Binary format context propagator.</param> /// <param name="textFormat">Text format context propagator.</param> /// <param name="libraryResource">Resource describing the instrumentation library.</param> internal Tracer(SpanProcessor spanProcessor, TracerConfiguration tracerConfiguration, IBinaryFormat binaryFormat, ITextFormat textFormat, Resource libraryResource) { this.spanProcessor = spanProcessor ?? throw new ArgumentNullException(nameof(spanProcessor)); this.tracerConfiguration = tracerConfiguration ?? throw new ArgumentNullException(nameof(tracerConfiguration)); this.BinaryFormat = binaryFormat ?? throw new ArgumentNullException(nameof(binaryFormat)); this.TextFormat = textFormat ?? throw new ArgumentNullException(nameof(textFormat)); this.LibraryResource = libraryResource ?? throw new ArgumentNullException(nameof(libraryResource)); }
public TracerFactory(SpanProcessor spanProcessor = null, TracerConfiguration tracerConfiguration = null, ITextFormat textFormat = null, IBinaryFormat binaryFormat = null) { this.spanProcessor = spanProcessor ?? Tracing.SpanProcessor; this.tracerConfiguration = tracerConfiguration ?? Tracing.TracerConfiguration; this.textFormat = textFormat ?? new TraceContextFormat(); this.binaryFormat = binaryFormat ?? new BinaryFormat(); this.defaultTracer = new Tracer(this.spanProcessor, this.tracerConfiguration, this.binaryFormat, this.textFormat, Resource.Empty); }
internal static Span CreateFromParentSpan( string name, ISpan parentSpan, SpanKind spanKind, DateTimeOffset startTimestamp, IEnumerable <Link> links, TracerConfiguration tracerConfiguration, SpanProcessor spanProcessor, Resource libraryResource) { if (parentSpan.Context.IsValid) { return(new Span( name, parentSpan.Context, FromParentSpan(name, parentSpan), true, spanKind, startTimestamp, links, tracerConfiguration, spanProcessor, libraryResource)); } var currentActivity = Activity.Current; if (currentActivity == null) { return(new Span( name, SpanContext.Blank, CreateRoot(name), true, spanKind, startTimestamp, links, tracerConfiguration, spanProcessor, libraryResource)); } return(new Span( name, new SpanContext( currentActivity.TraceId, currentActivity.SpanId, currentActivity.ActivityTraceFlags), FromCurrentParentActivity(name, currentActivity), true, spanKind, startTimestamp, links, tracerConfiguration, spanProcessor, libraryResource)); }
public TracerTest() { spanProcessor = new SimpleSpanProcessor(new NoopSpanExporter()); tracerConfiguration = new TracerConfiguration(); tracerFactory = TracerFactory.Create(b => b .SetExporter(new NoopSpanExporter()) .SetProcessor(e => new SimpleSpanProcessor(e))); tracer = (Tracer)tracerFactory.GetTracer(null); }
public async Task ShutdownTwice() { spanProcessor = new SimpleSpanProcessor(new NoopSpanExporter()); await spanProcessor.ShutdownAsync(CancellationToken.None).ConfigureAwait(false); // does not throw await spanProcessor.ShutdownAsync(CancellationToken.None).ConfigureAwait(false); }
public SpanCollector(Uri uri, uint maxProcessorBatchSize) { if (spanQueue == null) { spanQueue = new BlockingCollection <Span>(MAX_QUEUE_SIZE); } spanProcessor = new SpanProcessor(uri, spanQueue, maxProcessorBatchSize); }
private void SetupSpanCollector() { clientProviderStub = MockRepository.GenerateStub <IClientProvider>(); spanCollector = new SpanCollector(clientProviderStub, 0); SpanCollector.spanQueue = fixture.Create <BlockingCollection <Span> >(); spanProcessorStub = MockRepository.GenerateStub <SpanProcessor>(SpanCollector.spanQueue, clientProviderStub, 0); spanCollector.spanProcessor = spanProcessorStub; }
private void SetupSpanCollector() { spanCollector = new SpanCollector(new Uri("http://localhost"), 0); SpanCollector.spanQueue = fixture.Create <BlockingCollection <Span> >(); spanProcessorStub = MockRepository.GenerateStub <SpanProcessor>(new Uri("http://localhost"), SpanCollector.spanQueue, (uint)0); spanCollector.spanProcessor = spanProcessorStub; }
public void Init() { fixture = new Fixture(); queue = new BlockingCollection <Span>(); clientProvider = MockRepository.GenerateStub <IClientProvider>(); testMaxBatchSize = 10; spanProcessor = new SpanProcessor(queue, clientProvider, testMaxBatchSize); taskFactory = MockRepository.GenerateStub <SpanProcessorTaskFactory>(); spanProcessor.spanProcessorTaskFactory = taskFactory; }
public void Init() { fixture = new Fixture(); queue = new BlockingCollection<Span>(); clientProvider = MockRepository.GenerateStub<IClientProvider>(); testMaxBatchSize = 10; spanProcessor = new SpanProcessor(queue, clientProvider, testMaxBatchSize); taskFactory = MockRepository.GenerateStub<SpanProcessorTaskFactory>(); spanProcessor.spanProcessorTaskFactory = taskFactory; }
public SpanTest() { spanProcessor = spanProcessorMock.Object; attributes.Add("MyStringAttributeKey", "MyStringAttributeValue"); attributes.Add("MyLongAttributeKey", 123L); attributes.Add("MyBooleanAttributeKey", false); expectedAttributes = new List <KeyValuePair <string, object> >(attributes) { new KeyValuePair <string, object>("MySingleStringAttributeKey", "MySingleStringAttributeValue"), }; }
public void Init() { fixture = new Fixture(); logger = MockRepository.GenerateStub <ILog>(); queue = new BlockingCollection <Span>(); testMaxBatchSize = 10; spanProcessor = MockRepository.GenerateStub <SpanProcessor>(new Uri("http://localhost"), queue, testMaxBatchSize); spanProcessor.Stub(x => x.SendSpansToZipkin(Arg <string> .Is.Anything)).WhenCalled(s => { }); taskFactory = MockRepository.GenerateStub <SpanProcessorTaskFactory>(logger, null); spanProcessor.spanProcessorTaskFactory = taskFactory; }
private Span CreateSampledEndedSpan(string spanName, SpanProcessor spanProcessor) { var tracer = TracerFactory.Create(b => b .SetSampler(Samplers.AlwaysSample) .SetProcessor(_ => spanProcessor) .SetTracerOptions(new TracerConfiguration())).GetTracer(null); var context = new SpanContext(ActivityTraceId.CreateRandom(), ActivitySpanId.CreateRandom(), ActivityTraceFlags.Recorded); var span = (Span)tracer.StartSpan(spanName, context); span.End(); return(span); }
private Span( string name, SpanContext parentSpanContext, ActivityAndTracestate activityAndTracestate, bool ownsActivity, SpanKind spanKind, DateTimeOffset startTimestamp, IEnumerable <Link> links, TracerConfiguration tracerConfiguration, SpanProcessor spanProcessor, Resource libraryResource) { this.Name = name; this.LibraryResource = libraryResource; this.startTimestamp = startTimestamp; this.tracerConfiguration = tracerConfiguration; this.spanProcessor = spanProcessor; this.Kind = spanKind; this.OwnsActivity = ownsActivity; this.Activity = activityAndTracestate.Activity; var tracestate = activityAndTracestate.Tracestate; this.IsRecordingEvents = MakeSamplingDecision( parentSpanContext, name, null, links, // we'll enumerate again, but double enumeration over small collection is cheaper than allocation this.Activity.TraceId, this.Activity.SpanId, this.tracerConfiguration); if (this.IsRecordingEvents) { this.Activity.ActivityTraceFlags |= ActivityTraceFlags.Recorded; if (links != null) { foreach (var link in links) { this.AddLink(link); } } this.spanProcessor.OnStart(this); } else { this.Activity.ActivityTraceFlags &= ~ActivityTraceFlags.Recorded; } this.Context = new SpanContext(this.Activity.TraceId, this.Activity.SpanId, this.Activity.ActivityTraceFlags, tracestate); }
private SpanSdk CreateNotSampledEndedSpan(string spanName, SpanProcessor spanProcessor) { var tracer = TracerFactory.Create(b => b .SetSampler(new AlwaysOffSampler()) .AddProcessorPipeline(p => p.AddProcessor(_ => spanProcessor)) .SetTracerOptions(new TracerConfiguration())).GetTracer(null); var context = new SpanContext(ActivityTraceId.CreateRandom(), ActivitySpanId.CreateRandom(), ActivityTraceFlags.None); var span = (SpanSdk)tracer.StartSpan(spanName, context); span.End(); return(span); }
public SpanTest() { Activity.DefaultIdFormat = ActivityIdFormat.W3C; Activity.ForceDefaultIdFormat = true; spanProcessor = spanProcessorMock.Object; attributes.Add("MyStringAttributeKey", "MyStringAttributeValue"); attributes.Add("MyLongAttributeKey", 123L); attributes.Add("MyBooleanAttributeKey", false); expectedAttributes = new List <KeyValuePair <string, object> >(attributes) { new KeyValuePair <string, object>("MySingleStringAttributeKey", "MySingleStringAttributeValue"), }; }
public void Ctor_DefaultProcessor_NotStarted() { var logger = Substitute.For <ILogger <SpanProcessor> >(); var spanProcessorTask = Substitute.For <ISpanProcessorTask>(); var spanCollector = Substitute.For <ISpanCollector>(); var config = new ZipkinConfig(new Uri("http://localhost")) { SpanProcessorBatchSize = 10 }; var sp = new SpanProcessor(spanProcessorTask, spanCollector, config, logger); Assert.IsFalse(sp.IsStarted); }
private Span CreateSampledEndedSpan(string spanName, SpanProcessor spanProcessor) { var sampledActivity = new Activity(spanName); sampledActivity.ActivityTraceFlags |= ActivityTraceFlags.Recorded; sampledActivity.SetIdFormat(ActivityIdFormat.W3C); sampledActivity.Start(); var span = new Span( sampledActivity, Enumerable.Empty <KeyValuePair <string, string> >(), SpanKind.Internal, new TracerConfiguration(), spanProcessor, PreciseTimestamp.GetUtcNow(),
public SpanTest() { Activity.DefaultIdFormat = ActivityIdFormat.W3C; Activity.ForceDefaultIdFormat = true; spanProcessor = spanProcessorMock.Object; tracerFactory = TracerFactory.Create(b => b.AddProcessorPipeline(p => p.AddProcessor(_ => spanProcessor))); attributes.Add("MyStringAttributeKey", "MyStringAttributeValue"); attributes.Add("MyLongAttributeKey", 123L); attributes.Add("MyBooleanAttributeKey", false); expectedAttributes = new List <KeyValuePair <string, object> >(attributes) { new KeyValuePair <string, object>("MySingleStringAttributeKey", "MySingleStringAttributeValue"), }; }
public async Task Start_PropertyIsStarted_IsTrue() { var logger = Substitute.For <ILogger <SpanProcessor> >(); var spanProcessorTask = Substitute.For <ISpanProcessorTask>(); var spanCollector = Substitute.For <ISpanCollector>(); var config = new ZipkinConfig(new Uri("http://localhost")) { SpanProcessorBatchSize = 10 }; var sp = new SpanProcessor(spanProcessorTask, spanCollector, config, logger); await sp.Start(); Assert.IsTrue(sp.IsStarted); }
private bool ValidateStartAction(Action y, SpanProcessor spanProcessor) { Assert.AreEqual(() => spanProcessor.LogSubmittedSpans(), y); return true; }
public void CTOR_WithNullClientProvider() { var spanProcessor = new SpanProcessor(new BlockingCollection<Span>(), null, fixture.Create<int>()); }
public void CTOR_WithNullSpanQueue() { var spanProcessor = new SpanProcessor(null, MockRepository.GenerateStub<IClientProvider>(), fixture.Create<int>()); }
private void SetupSpanCollector() { clientProviderStub = MockRepository.GenerateStub<IClientProvider>(); spanCollector = new SpanCollector(clientProviderStub, 0); SpanCollector.spanQueue = fixture.Create<BlockingCollection<Span>>(); spanProcessorStub = MockRepository.GenerateStub<SpanProcessor>(SpanCollector.spanQueue, clientProviderStub, 0); spanCollector.spanProcessor = spanProcessorStub; }