public SpanTest() { timestamp = Timestamp.FromDateTimeOffset(startTime); timestampConverter = Timer.StartNew(startTime, () => interval); spanContext = SpanContext.Create(TraceId.GenerateRandomId(random), SpanId.GenerateRandomId(random), OpenTelemetry.Trace.TraceOptions.Default, Tracestate.Empty); parentSpanId = SpanId.GenerateRandomId(random); attributes.Add( "MyStringAttributeKey", AttributeValue.StringAttributeValue("MyStringAttributeValue")); attributes.Add("MyLongAttributeKey", AttributeValue.LongAttributeValue(123L)); attributes.Add("MyBooleanAttributeKey", AttributeValue.BooleanAttributeValue(false)); expectedAttributes = new Dictionary <String, IAttributeValue>(attributes); expectedAttributes.Add( "MySingleStringAttributeKey", AttributeValue.StringAttributeValue("MySingleStringAttributeValue")); }
public InProcessSampledSpanStoreTest() { timestamp = Timestamp.FromDateTimeOffset(startTime); timestampConverter = Timer.StartNew(startTime, () => interval); sampledSpanContext = SpanContext.Create(TraceId.GenerateRandomId(random), SpanId.GenerateRandomId(random), TraceOptions.Builder().SetIsSampled(true).Build(), Tracestate.Empty); notSampledSpanContext = SpanContext.Create(TraceId.GenerateRandomId(random), SpanId.GenerateRandomId(random), TraceOptions.Default, Tracestate.Empty); parentSpanId = SpanId.GenerateRandomId(random); startEndHandler = new TestStartEndHandler(sampleStore); sampleStore.RegisterSpanNamesForCollection(new List <string>() { REGISTERED_SPAN_NAME }); }
public void ProbabilitySampler_SampleBasedOnTraceId() { ISampler defaultProbability = Samplers.GetProbabilitySampler(0.0001); // This traceId will not be sampled by the ProbabilitySampler because the first 8 bytes as long // is not less than probability * Long.MAX_VALUE; ITraceId notSampledtraceId = TraceId.FromBytes( new byte[] { (byte)0x8F, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, 0, 0, 0, 0, 0, 0, 0, 0 }); Assert.False( defaultProbability.ShouldSample( null, false, notSampledtraceId, SpanId.GenerateRandomId(random), SPAN_NAME, new List <ISpan>())); // This traceId will be sampled by the ProbabilitySampler because the first 8 bytes as long // is less than probability * Long.MAX_VALUE; ITraceId sampledtraceId = TraceId.FromBytes( new byte[] { (byte)0x00, (byte)0x00, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, 0, 0, 0, 0, 0, 0, 0, 0 }); Assert.True( defaultProbability.ShouldSample( null, false, sampledtraceId, SpanId.GenerateRandomId(random), SPAN_NAME, new List <ISpan>())); }
public SpanExporterTest() { sampledSpanContext = SpanContext.Create(TraceId.GenerateRandomId(random), SpanId.GenerateRandomId(random), TraceOptions.Builder().SetIsSampled(true).Build(), Tracestate.Empty); notSampledSpanContext = SpanContext.Create(TraceId.GenerateRandomId(random), SpanId.GenerateRandomId(random), TraceOptions.Default, Tracestate.Empty); startEndHandler = new StartEndHandler(spanExporter, runningSpanStore, null, new SimpleEventQueue()); spanExporter.RegisterHandler("test.service", serviceHandler); }
public void StartRemoteChildSpan_WithProbabilitySamplerDefaultSampler() { var configMock = Mock.Get <ITraceConfig>(traceConfig); configMock.Setup((c) => c.ActiveTraceParams).Returns(TraceParams.Default); // This traceId will not be sampled by the ProbabilitySampler because the first 8 bytes as long // is not less than probability * Long.MAX_VALUE; var traceId = TraceId.FromBytes( new byte[] { 0x8F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0, 0, 0, 0, 0, 0, 0, 0, }); // If parent is sampled then the remote child must be sampled. var childSpan = SpanBuilder.Create( SPAN_NAME, SpanKind.Internal, SpanContext.Create( traceId, SpanId.GenerateRandomId(randomHandler), TraceOptions.Builder().SetIsSampled(true).Build(), Tracestate.Empty), spanBuilderOptions) .StartSpan(); Assert.True(childSpan.Context.IsValid); Assert.Equal(traceId, childSpan.Context.TraceId); Assert.True(childSpan.Context.TraceOptions.IsSampled); childSpan.End(); Assert.Equal(TraceParams.Default, traceConfig.ActiveTraceParams); // If parent is not sampled then the remote child must be not sampled. childSpan = SpanBuilder.Create( SPAN_NAME, SpanKind.Internal, SpanContext.Create( traceId, SpanId.GenerateRandomId(randomHandler), TraceOptions.Default, Tracestate.Empty), spanBuilderOptions) .StartSpan(); Assert.True(childSpan.Context.IsValid); Assert.Equal(traceId, childSpan.Context.TraceId); Assert.False(childSpan.Context.TraceOptions.IsSampled); childSpan.End(); }
//// @Rule public readonly ExpectedException exception = ExpectedException.none(); public SpanTest() { spanContext = SpanContext.Create(TraceId.GenerateRandomId(random), SpanId.GenerateRandomId(random), TraceOptions.DEFAULT); parentSpanId = SpanId.GenerateRandomId(random); testClock = TestClock.Create(timestamp); timestampConverter = TimestampConverter.Now(testClock); attributes.Add( "MyStringAttributeKey", AttributeValue.StringAttributeValue("MyStringAttributeValue")); attributes.Add("MyLongAttributeKey", AttributeValue.LongAttributeValue(123L)); attributes.Add("MyBooleanAttributeKey", AttributeValue.BooleanAttributeValue(false)); expectedAttributes = new Dictionary <string, IAttributeValue>(attributes) { { "MySingleStringAttributeKey", AttributeValue.StringAttributeValue("MySingleStringAttributeValue") } }; }
public InProcessSampledSpanStoreTest() { sampledSpanContext = SpanContext.Create(TraceId.GenerateRandomId(random), SpanId.GenerateRandomId(random), TraceOptions.Builder().SetIsSampled(true).Build()); notSampledSpanContext = SpanContext.Create(TraceId.GenerateRandomId(random), SpanId.GenerateRandomId(random), TraceOptions.DEFAULT); parentSpanId = SpanId.GenerateRandomId(random); startEndHandler = new TestStartEndHandler(sampleStore); sampleStore.RegisterSpanNamesForCollection(new List <string>() { REGISTERED_SPAN_NAME }); }