Esempio n. 1
0
        public void StartWithExplicitTimestamp()
        {
            var spanBuilderMock = GetDefaultSpanBuilderMock();
            var shim            = new SpanBuilderShim(GetDefaultTracer(spanBuilderMock), "foo");

            var startTimestamp = DateTimeOffset.UtcNow;

            shim.WithStartTimestamp(startTimestamp);

            shim.Start();
            spanBuilderMock.Verify(x => x.SetStartTimestamp(startTimestamp), Times.Once);
            spanBuilderMock.Verify(x => x.StartSpan(), Times.Once);
        }
Esempio n. 2
0
        public void WithTag_KeyisNullStringValue()
        {
            var spanMock = Defaults.GetOpenTelemetrySpanMock();
            var shim     = new SpanBuilderShim(GetDefaultTracerMock(spanMock).Object, "foo");

            shim.WithTag((string)null, "unused");

            // build
            shim.Start();

            // Null key was ignored
            Assert.Empty(spanMock.Attributes);
        }
Esempio n. 3
0
        public void StartWithExplicitTimestamp()
        {
            var tracerMock = GetDefaultTracerMock();
            var shim       = new SpanBuilderShim(tracerMock.Object, "foo");

            var startTimestamp = DateTimeOffset.UtcNow;

            shim.WithStartTimestamp(startTimestamp);

            shim.Start();
            tracerMock.Verify(o => o.StartSpan("foo", 0,
                                               It.Is <SpanCreationOptions>(so => so.StartTimestamp == startTimestamp && !so.Links.Any())), Times.Once);
        }
Esempio n. 4
0
        public void Start()
        {
            var tracer = TracerProvider.Default.GetTracer(TracerName);
            var shim   = new SpanBuilderShim(tracer, "foo");

            // build
            var span = shim.Start() as SpanShim;

            // Just check the return value is a SpanShim and that the underlying OpenTelemetry Span.
            // There is nothing left to verify because the rest of the tests were already calling .Start() prior to verification.
            Assert.NotNull(span);
            Assert.Equal("foo", span.Span.Activity.OperationName);
        }
Esempio n. 5
0
        public void WithTag_KeyIsNullStringValue()
        {
            var tracer = TracerProvider.Default.GetTracer(TracerName);
            var shim   = new SpanBuilderShim(tracer, "foo");

            shim.WithTag((string)null, "unused");

            // build
            var spanShim = (SpanShim)shim.Start();

            // Null key was ignored
            Assert.Empty(spanShim.Span.Activity.Tags);
        }
Esempio n. 6
0
        public void WithTag_KeyIsErrorBoolValue()
        {
            var tracer = TracerProvider.Default.GetTracer(TracerName);
            var shim   = new SpanBuilderShim(tracer, "foo");

            shim.WithTag(global::OpenTracing.Tag.Tags.Error.Key, true);

            // build
            var spanShim = (SpanShim)shim.Start();

            // Span status should be set
            Assert.Equal(Status.Unknown, spanShim.Span.Activity.GetStatus());
        }
Esempio n. 7
0
        public void AsChildOf_WithNullSpan()
        {
            var tracer = TracerProvider.Default.GetTracer(TracerName);
            var shim   = new SpanBuilderShim(tracer, "foo");

            // Add a null parent
            shim.AsChildOf((global::OpenTracing.ISpan)null);

            // build
            var spanShim = (SpanShim)shim.Start();

            Assert.Equal("foo", spanShim.Span.Activity.OperationName);
            Assert.Null(spanShim.Span.Activity.Parent);
        }
Esempio n. 8
0
        public void StartWithExplicitTimestamp()
        {
            var tracer = TracerProvider.Default.GetTracer(TracerName);
            var shim   = new SpanBuilderShim(tracer, "foo");

            var startTimestamp = DateTimeOffset.Now;

            shim.WithStartTimestamp(startTimestamp);

            // build
            var spanShim = (SpanShim)shim.Start();

            Assert.Equal(startTimestamp, spanShim.Span.Activity.StartTimeUtc);
        }
Esempio n. 9
0
        public void AsChildOf_WithNullSpan()
        {
            var tracerMock = GetDefaultTracerMock();
            var shim       = new SpanBuilderShim(tracerMock.Object, "foo");

            // Add a null parent
            shim.AsChildOf((global::OpenTracing.ISpan)null);

            // build
            shim.Start();

            tracerMock.Verify(o => o.StartSpan("foo", It.IsAny <ISpan>(), 0,
                                               It.Is <SpanCreationOptions>(so => so.StartTimestamp == default && !so.Links.Any())), Times.Once);
        }
Esempio n. 10
0
        public void WithTag_ValueIsNullStringValue()
        {
            var tracer = TracerProvider.Default.GetTracer(TracerName);
            var shim   = new SpanBuilderShim(tracer, "foo");

            shim.WithTag("foo", null);

            // build
            var spanShim = (SpanShim)shim.Start();

            // Null value was turned into string.empty
            Assert.Equal("foo", spanShim.Span.Activity.Tags.First().Key);
            Assert.Equal(string.Empty, spanShim.Span.Activity.Tags.First().Value);
        }
Esempio n. 11
0
        public void AsChildOfWithSpanContext()
        {
            var tracer = TracerProvider.Default.GetTracer(TracerName);
            var shim   = new SpanBuilderShim(tracer, "foo");

            // Add a parent
            var spanContext = SpanContextShimTests.GetSpanContextShim();
            var test        = shim.AsChildOf(spanContext);

            // build
            var spanShim = (SpanShim)shim.Start();

            Assert.NotNull(spanShim.Span.Activity.ParentId);
        }
Esempio n. 12
0
        public void AsChildOf_WithNullSpanContext()
        {
            var tracer = TracerProvider.Default.GetTracer(TracerName);
            var shim   = new SpanBuilderShim(tracer, "foo");

            // Add a null parent
            shim.AsChildOf((global::OpenTracing.ISpanContext)null);

            // build
            var spanShim = (SpanShim)shim.Start();

            // should be no parent.
            Assert.Null(spanShim.Span.Activity.Parent);
        }
        public void WithTag_ValueIsNullStringValue()
        {
            var spanMock = Defaults.GetOpenTelemetrySpanMock();
            var shim     = new SpanBuilderShim(GetDefaultTracerMock(spanMock).Object, "foo");

            shim.WithTag("foo", null);

            // build
            shim.Start();

            // Null value was turned into string.empty
            Assert.Equal("foo", spanMock.Attributes.First().Key);
            Assert.Equal(string.Empty, spanMock.Attributes.First().Value);
        }
Esempio n. 14
0
        public void AsChildOf_WithNullSpan()
        {
            var spanBuilderMock = GetDefaultSpanBuilderMock();
            var shim            = new SpanBuilderShim(GetDefaultTracer(spanBuilderMock), "foo");

            // Add a null parent
            shim.AsChildOf((global::OpenTracing.ISpan)null);

            // build
            shim.Start();

            spanBuilderMock.Verify(o => o.SetParent(It.IsAny <Trace.ISpan>()), Times.Never);
            spanBuilderMock.Verify(o => o.SetParent(It.IsAny <Trace.SpanContext>()), Times.Never);
        }
        public void Start()
        {
            var spanMock   = Defaults.GetOpenTelemetrySpanMock();
            var tracerMock = GetDefaultTracerMock(spanMock);
            var shim       = new SpanBuilderShim(tracerMock.Object, "foo");

            // build
            var span = shim.Start() as SpanShim;

            // Just check the return value is a SpanShim and that the underlying OpenTelemetry Span.
            // There is nothing left to verify because the rest of the tests were already calling .Start() prior to verification.
            Assert.NotNull(span);
            Assert.Equal(spanMock, span.Span);
        }
Esempio n. 16
0
        public void WithTag_KeyIsSpanKindStringValue()
        {
            var tracer = TracerProvider.Default.GetTracer(TracerName);
            var shim   = new SpanBuilderShim(tracer, "foo");

            shim.WithTag(global::OpenTracing.Tag.Tags.SpanKind.Key, global::OpenTracing.Tag.Tags.SpanKindClient);

            // build
            var spanShim = (SpanShim)shim.Start();

            // Not an attribute
            Assert.Empty(spanShim.Span.Activity.Tags);
            Assert.Equal("foo", spanShim.Span.Activity.OperationName);
            Assert.Equal(ActivityKind.Client, spanShim.Span.Activity.Kind);
        }
        public void IgnoreActiveSpan()
        {
            var tracerMock = GetDefaultTracerMock();
            var shim       = new SpanBuilderShim(tracerMock.Object, "foo");

            // Add a parent. The shim requires that the ISpan implementation be a SpanShim
            shim.AsChildOf(new SpanShim(Defaults.GetOpenTelemetryMockSpan().Object));

            // Set to Ignore
            shim.IgnoreActiveSpan();

            // build
            shim.Start();

            tracerMock.Verify(o => o.StartRootSpan("foo", 0,
Esempio n. 18
0
        public void AsChildOf_WithSpan()
        {
            var tracer = TracerProvider.Default.GetTracer(TracerName);
            var shim   = new SpanBuilderShim(tracer, "foo");

            // Add a parent.
            var span = new SpanShim(tracer.StartSpan(SpanName1));

            shim.AsChildOf(span);

            // build
            var spanShim = (SpanShim)shim.Start();

            Assert.Equal("foo", spanShim.Span.Activity.OperationName);
            Assert.NotNull(spanShim.Span.Activity.ParentId);
        }
Esempio n. 19
0
        public void AsChildOfWithSpanContext()
        {
            var spanBuilderMock = GetDefaultSpanBuilderMock();
            var shim            = new SpanBuilderShim(GetDefaultTracer(spanBuilderMock), "foo");

            // Add a parent
            var spanContext = SpanContextShimTests.GetSpanContextShim();

            shim.AsChildOf(spanContext);

            // build
            shim.Start();

            spanBuilderMock.Verify(o => o.SetParent(spanContext.SpanContext), Times.Once);
            spanBuilderMock.Verify(o => o.SetParent(It.IsAny <Trace.ISpan>()), Times.Never);
        }
        public void WithTag_KeyIsErrorBoolValue()
        {
            var spanMock = Defaults.GetOpenTelemetrySpanMock();
            var shim     = new SpanBuilderShim(GetDefaultTracerMock(spanMock).Object, "foo");

            shim.WithTag(global::OpenTracing.Tag.Tags.Error.Key, true);

            // build
            shim.Start();

            // Not an attribute
            Assert.Empty(spanMock.Attributes);

            // Span status should be set
            Assert.Equal(Status.Unknown, spanMock.GetStatus());
        }
Esempio n. 21
0
        public void AsChildOf_WithSpan()
        {
            var tracerMock = GetDefaultTracerMock();
            var shim       = new SpanBuilderShim(tracerMock.Object, "foo");

            // Add a parent.
            var span = new SpanShim(Defaults.GetOpenTelemetryMockSpan().Object);

            shim.AsChildOf(span);

            // build
            shim.Start();

            tracerMock.Verify(o => o.StartSpan("foo", span.Span, 0,
                                               It.Is <SpanCreationOptions>(so => so.StartTimestamp == default && !so.Links.Any())), Times.Once);
        }
        public void WithTag_KeyIsSpanKindStringValue()
        {
            var spanMock   = Defaults.GetOpenTelemetrySpanMock();
            var tracerMock = GetDefaultTracerMock(spanMock);
            var shim       = new SpanBuilderShim(tracerMock.Object, "foo");

            shim.WithTag(global::OpenTracing.Tag.Tags.SpanKind.Key, global::OpenTracing.Tag.Tags.SpanKindClient);

            // build
            shim.Start();

            // Not an attribute
            Assert.Empty(spanMock.Attributes);

            tracerMock.Verify(o => o.StartSpan("foo", It.IsAny <TelemetrySpan>(), SpanKind.Client, It.Is <SpanCreationOptions>(so => so.StartTimestamp == default && !so.Links.Any())), Times.Once);
        }
Esempio n. 23
0
        public void AsChildOfWithSpanContext()
        {
            var tracerMock = GetDefaultTracerMock();
            var shim       = new SpanBuilderShim(tracerMock.Object, "foo");

            // Add a parent
            var spanContext = SpanContextShimTests.GetSpanContextShim();

            shim.AsChildOf(spanContext);

            // build
            shim.Start();

            tracerMock.Verify(o => o.StartSpan("foo", spanContext.SpanContext, 0,
                                               It.Is <SpanCreationOptions>(so => so.StartTimestamp == default && !so.Links.Any())), Times.Once);
        }
Esempio n. 24
0
        public void IgnoreActiveSpan()
        {
            var tracer = TracerProvider.Default.GetTracer(TracerName);
            var shim   = new SpanBuilderShim(tracer, "foo");

            // Add a parent. The shim requires that the ISpan implementation be a SpanShim
            shim.AsChildOf(new SpanShim(tracer.StartSpan(SpanName1)));

            // Set to Ignore
            shim.IgnoreActiveSpan();

            // build
            var spanShim = (SpanShim)shim.Start();

            Assert.Equal("foo", spanShim.Span.Activity.OperationName);
        }
Esempio n. 25
0
        public void AsChildOf_WithSpan()
        {
            var spanBuilderMock = GetDefaultSpanBuilderMock();
            var shim            = new SpanBuilderShim(GetDefaultTracer(spanBuilderMock), "foo");

            // Add a parent.
            var span = new SpanShim(Defaults.GetOpenTelemetryMockSpan().Object);

            shim.AsChildOf(span);

            // build
            shim.Start();

            spanBuilderMock.Verify(o => o.SetParent(span.Span), Times.Once);
            spanBuilderMock.Verify(o => o.SetParent(It.IsAny <Trace.SpanContext>()), Times.Never);
        }
Esempio n. 26
0
        public void WithTag_KeyisSpanKindStringValue()
        {
            var spanMock        = Defaults.GetOpenTelemetrySpanMock();
            var spanBuilderMock = GetDefaultSpanBuilderMock(spanMock);
            var shim            = new SpanBuilderShim(GetDefaultTracer(spanBuilderMock), "foo");

            shim.WithTag(global::OpenTracing.Tag.Tags.SpanKind.Key, global::OpenTracing.Tag.Tags.SpanKindClient);

            // build
            shim.Start();

            // Not an attribute
            Assert.Empty(spanMock.Attributes);

            spanBuilderMock.Verify(o => o.SetSpanKind(Trace.SpanKind.Client), Times.Once);
        }
Esempio n. 27
0
        public void IgnoreActiveSpan()
        {
            var tracerMock = GetDefaultTracerMock();
            var shim       = new SpanBuilderShim(tracerMock.Object, "foo");

            // Add a parent. The shim requires that the ISpan implementation be a SpanShim
            shim.AsChildOf(new SpanShim(Defaults.GetOpenTelemetryMockSpan().Object));

            // Set to Ignore
            shim.IgnoreActiveSpan();

            // build
            shim.Start();

            tracerMock.Verify(o => o.StartRootSpan("foo", 0,
                                                   It.Is <SpanCreationOptions>(so => so.StartTimestamp == default && !so.Links.Any())), Times.Once);
        }
Esempio n. 28
0
        public void WithTag_KeyisErrorStringValue()
        {
            var spanMock        = Defaults.GetOpenTelemetrySpanMock();
            var spanBuilderMock = GetDefaultSpanBuilderMock(spanMock);
            var shim            = new SpanBuilderShim(GetDefaultTracer(spanBuilderMock), "foo");

            shim.WithTag(global::OpenTracing.Tag.Tags.Error.Key, "true");

            // build
            shim.Start();

            // Not an attribute
            Assert.Empty(spanMock.Attributes);

            // Span status should be set
            Assert.Equal(Trace.Status.Unknown, spanMock.Status);
        }
Esempio n. 29
0
        public void AsChildOf_MultipleCallsWithSpanContext()
        {
            var tracerMock = GetDefaultTracerMock();
            var shim       = new SpanBuilderShim(tracerMock.Object, "foo");

            // Multiple calls
            var spanContext1 = SpanContextShimTests.GetSpanContextShim();
            var spanContext2 = SpanContextShimTests.GetSpanContextShim();

            shim.AsChildOf(spanContext1);
            shim.AsChildOf(spanContext2);

            // build
            shim.Start();

            tracerMock.Verify(o => o.StartSpan("foo", spanContext1.SpanContext, 0,
                                               It.Is <SpanCreationOptions>(so => so.StartTimestamp == default && so.Links.Single().Context.Equals(spanContext2.SpanContext))), Times.Once);
        }
        public void WithTag_VariousValueTypes()
        {
            var spanMock = Defaults.GetOpenTelemetrySpanMock();
            var shim     = new SpanBuilderShim(GetDefaultTracerMock(spanMock).Object, "foo");

            shim.WithTag("foo", "unused");
            shim.WithTag("bar", false);
            shim.WithTag("baz", 1);
            shim.WithTag("bizzle", 1D);
            shim.WithTag(new global::OpenTracing.Tag.BooleanTag("shnizzle"), true);
            shim.WithTag(new global::OpenTracing.Tag.IntOrStringTag("febrizzle"), "unused");
            shim.WithTag(new global::OpenTracing.Tag.StringTag("mobizzle"), "unused");

            // build
            shim.Start();

            // Just verify the count
            Assert.Equal(7, spanMock.Attributes.Count);
        }