public void TraceContextFormat_IsBlankIfNoHeader()
        {
            var headers = new Dictionary <string, string>();

            var f   = new TraceContextFormatActivity();
            var ctx = f.Extract(headers, Getter);

            Assert.False(ctx.IsValid());

            // TODO: when ActivityContext supports IsRemote
            // Assert.True(ctx.IsRemote);
        }
        public void TraceContextFormat_TracestateToStringEmpty()
        {
            var headers = new Dictionary <string, string>
            {
                { TraceParent, $"00-{TraceId}-{SpanId}-01" },
            };

            var f   = new TraceContextFormatActivity();
            var ctx = f.Extract(headers, Getter);

            Assert.Empty(ctx.TraceState);
        }
        public void TraceContextFormat_TracestateToString()
        {
            var headers = new Dictionary <string, string>
            {
                { TraceParent, $"00-{TraceId}-{SpanId}-01" },
                { TraceState, "k1=v1,k2=v2,k3=v3" },
            };

            var f   = new TraceContextFormatActivity();
            var ctx = f.Extract(headers, Getter);

            Assert.Equal("k1=v1,k2=v2,k3=v3", ctx.TraceState);
        }
        public void TraceContextFormat_IsBlankIfInvalid()
        {
            var headers = new Dictionary <string, string>
            {
                { TraceParent, $"00-xyz7651916cd43dd8448eb211c80319c-{SpanId}-01" },
            };

            var f   = new TraceContextFormatActivity();
            var ctx = f.Extract(headers, Getter);

            Assert.False(ctx.IsValid());

            // TODO: when ActivityContext supports IsRemote
            // Assert.True(ctx.IsRemote);
        }
        public void TraceContextFormatNotSampled()
        {
            var headers = new Dictionary <string, string>
            {
                { TraceParent, $"00-{TraceId}-{SpanId}-00" },
            };

            var f   = new TraceContextFormatActivity();
            var ctx = f.Extract(headers, Getter);

            Assert.Equal(ActivityTraceId.CreateFromString(TraceId.AsSpan()), ctx.TraceId);
            Assert.Equal(ActivitySpanId.CreateFromString(SpanId.AsSpan()), ctx.SpanId);
            Assert.True((ctx.TraceFlags & ActivityTraceFlags.Recorded) == 0);

            // TODO: when ActivityContext supports IsRemote
            // Assert.True(ctx.IsRemote);
            Assert.True(ctx.IsValid());
        }
        public void TraceContextFormatCanParseExampleFromSpec()
        {
            var headers = new Dictionary <string, string>
            {
                { TraceParent, $"00-{TraceId}-{SpanId}-01" },
                { TraceState, $"congo=lZWRzIHRoNhcm5hbCBwbGVhc3VyZS4,rojo=00-{TraceId}-00f067aa0ba902b7-01" },
            };

            var f   = new TraceContextFormatActivity();
            var ctx = f.Extract(headers, Getter);

            Assert.Equal(ActivityTraceId.CreateFromString(TraceId.AsSpan()), ctx.TraceId);
            Assert.Equal(ActivitySpanId.CreateFromString(SpanId.AsSpan()), ctx.SpanId);

            // TODO: when ActivityContext supports IsRemote
            // Assert.True(ctx.IsRemote);

            Assert.True(ctx.IsValid());
            Assert.True((ctx.TraceFlags & ActivityTraceFlags.Recorded) != 0);

            Assert.Equal($"congo=lZWRzIHRoNhcm5hbCBwbGVhc3VyZS4,rojo=00-{TraceId}-00f067aa0ba902b7-01", ctx.TraceState);
        }