public void Process_CurrentSpan_ReturnsExpected()
        {
            // Arrange
            using var openTelemetry = Sdk.CreateTracerProviderBuilder().AddSource("tracername").Build();
            var config = TestHelpers.GetConfigurationFromDictionary(new Dictionary <string, string> {
                ["management:tracing:name"] = "foobar"
            });
            var processor = new TracingLogProcessor(new TracingOptions(new ApplicationInstanceInfo(config), config));
            var tracer    = TracerProvider.Default.GetTracer("tracername");
            var span      = tracer.StartActiveSpan("spanName");

            // Act
            var result = processor.Process("InputLogMessage");

            // Assert
            Assert.Contains("InputLogMessage", result);
            Assert.Contains("[", result);
            Assert.Contains("]", result);
            Assert.Contains(span.Context.TraceId.ToHexString(), result);
            Assert.Contains(span.Context.SpanId.ToHexString(), result);
            Assert.Contains("foobar", result);

            var childSpan = tracer.StartActiveSpan("spanName2", SpanKind.Internal, span);

            result = processor.Process("InputLogMessage2");

            Assert.Contains("InputLogMessage2", result);
            Assert.Contains("[", result);
            Assert.Contains("]", result);
            Assert.Contains(childSpan.Context.TraceId.ToHexString(), result);
            Assert.Contains(childSpan.Context.SpanId.ToHexString(), result);

            // Assert.Contains(span.Context.SpanId.ToHexString(), result);  TODO: ParentID not supported
            Assert.Contains("foobar", result);
        }
Beispiel #2
0
        public void Process_CurrentSpan_ReturnsExpected()
        {
            var appsettings = new Dictionary <string, string>()
            {
                ["management:tracing:name"] = "foobar",
                ["management:tracing:ingressIgnorePattern"]     = "pattern",
                ["management:tracing:egressIgnorePattern"]      = "pattern",
                ["management:tracing:maxNumberOfAttributes"]    = "100",
                ["management:tracing:maxNumberOfAnnotations"]   = "100",
                ["management:tracing:maxNumberOfMessageEvents"] = "100",
                ["management:tracing:maxNumberOfLinks"]         = "100",
                ["management:tracing:alwaysSample"]             = "true",
                ["management:tracing:neverSample"]      = "false",
                ["management:tracing:useShortTraceIds"] = "false",
            };

            ConfigurationBuilder builder = new ConfigurationBuilder();

            builder.AddInMemoryCollection(appsettings);
            TracingOptions opts = new TracingOptions(null, builder.Build());

            OpenCensusTracing tracing = new OpenCensusTracing(opts);
            var span = tracing.Tracer.SpanBuilder("spanName").StartSpan();

            AsyncLocalContext.CurrentSpan = span;

            var processor = new TracingLogProcessor(opts, tracing);
            var result    = processor.Process("InputLogMessage");

            Assert.Contains("InputLogMessage", result);
            Assert.Contains("[", result);
            Assert.Contains("]", result);
            Assert.Contains(span.Context.TraceId.ToLowerBase16(), result);
            Assert.Contains(span.Context.SpanId.ToLowerBase16(), result);
            Assert.Contains("foobar", result);

            var childSpan = tracing.Tracer.SpanBuilderWithExplicitParent("spanName2", span).StartSpan();

            AsyncLocalContext.CurrentSpan = childSpan;

            result = processor.Process("InputLogMessage2");

            Assert.Contains("InputLogMessage2", result);
            Assert.Contains("[", result);
            Assert.Contains("]", result);
            Assert.Contains(childSpan.Context.TraceId.ToLowerBase16(), result);
            Assert.Contains(childSpan.Context.SpanId.ToLowerBase16(), result);
            Assert.Contains(span.Context.SpanId.ToLowerBase16(), result);
            Assert.Contains("foobar", result);
        }
Beispiel #3
0
        public void Process_NoCurrentSpan_DoesNothing()
        {
            var appsettings = new Dictionary <string, string>()
            {
                ["management:tracing:name"] = "foobar",
                ["management:tracing:ingressIgnorePattern"]     = "pattern",
                ["management:tracing:egressIgnorePattern"]      = "pattern",
                ["management:tracing:maxNumberOfAttributes"]    = "100",
                ["management:tracing:maxNumberOfAnnotations"]   = "100",
                ["management:tracing:maxNumberOfMessageEvents"] = "100",
                ["management:tracing:maxNumberOfLinks"]         = "100",
                ["management:tracing:alwaysSample"]             = "true",
                ["management:tracing:neverSample"]      = "true",
                ["management:tracing:useShortTraceIds"] = "true",
            };

            var builder = new ConfigurationBuilder();

            builder.AddInMemoryCollection(appsettings);
            var opts = new TracingOptions(null, builder.Build());

            var tracing   = new OpenTelemetryTracing(opts);
            var processor = new TracingLogProcessor(opts, tracing);
            var result    = processor.Process("InputLogMessage");

            Assert.Equal("InputLogMessage", result);
        }
        public void Process_UseShortTraceIds()
        {
            // Arrange
            var appsettings = new Dictionary <string, string>()
            {
                ["management:tracing:name"]             = "foobar",
                ["management:tracing:useShortTraceIds"] = "true",
            };
            var config = TestHelpers.GetConfigurationFromDictionary(appsettings);
            var opts   = new TracingOptions(new ApplicationInstanceInfo(config), config);

            using var openTelemetry = Sdk.CreateTracerProviderBuilder().AddSource("tracername").Build();
            var tracer    = TracerProvider.Default.GetTracer("tracername");
            var span      = tracer.StartActiveSpan("spanName");
            var processor = new TracingLogProcessor(opts);

            // Act
            var result = processor.Process("InputLogMessage");

            Assert.Contains("InputLogMessage", result);
            Assert.Contains("[", result);
            Assert.Contains("]", result);

            var full   = span.Context.TraceId.ToHexString();
            var shorty = full.Substring(full.Length - 16, 16);

            Assert.Contains(shorty, result);
            Assert.DoesNotContain(full, result);

            Assert.Contains(span.Context.SpanId.ToHexString(), result);
            Assert.Contains("foobar", result);
        }
Beispiel #5
0
        public void Process_CurrentSpan_ReturnsExpected()
        {
            var appsettings = new Dictionary <string, string>()
            {
                ["management:tracing:name"] = "foobar",
                ["management:tracing:ingressIgnorePattern"]     = "pattern",
                ["management:tracing:egressIgnorePattern"]      = "pattern",
                ["management:tracing:maxNumberOfAttributes"]    = "100",
                ["management:tracing:maxNumberOfAnnotations"]   = "100",
                ["management:tracing:maxNumberOfMessageEvents"] = "100",
                ["management:tracing:maxNumberOfLinks"]         = "100",
                ["management:tracing:alwaysSample"]             = "true",
                ["management:tracing:neverSample"]      = "false",
                ["management:tracing:useShortTraceIds"] = "false",
            };

            var config = TestHelpers.GetConfigurationFromDictionary(appsettings);
            var opts   = new TracingOptions(new ApplicationInstanceInfo(config), config);

            var tracing = new OpenTelemetryTracing(opts);

            tracing.Tracer.StartActiveSpan("spanName", out var span);

            var processor = new TracingLogProcessor(opts, tracing);
            var result    = processor.Process("InputLogMessage");

            Assert.Contains("InputLogMessage", result);
            Assert.Contains("[", result);
            Assert.Contains("]", result);
            Assert.Contains(span.Context.TraceId.ToHexString(), result);
            Assert.Contains(span.Context.SpanId.ToHexString(), result);
            Assert.Contains("foobar", result);

            tracing.Tracer.StartActiveSpan("spanName2", span, out var childSpan);

            result = processor.Process("InputLogMessage2");

            Assert.Contains("InputLogMessage2", result);
            Assert.Contains("[", result);
            Assert.Contains("]", result);
            Assert.Contains(childSpan.Context.TraceId.ToHexString(), result);
            Assert.Contains(childSpan.Context.SpanId.ToHexString(), result);

            // Assert.Contains(span.Context.SpanId.ToHexString(), result);  TODO: ParentID not supported
            Assert.Contains("foobar", result);
        }
Beispiel #6
0
        public void Process_NoCurrentSpan_DoesNothing()
        {
            using var openTelemetry = Sdk.CreateTracerProviderBuilder().AddSource("tracername").Build();
            var opts      = new TracingOptions(null, new ConfigurationBuilder().Build());
            var processor = new TracingLogProcessor(opts);

            var result = processor.Process("InputLogMessage");

            Assert.Equal("InputLogMessage", result);
        }
        public void Process_UseShortTraceIds()
        {
            var appsettings = new Dictionary <string, string>()
            {
                ["management:tracing:name"] = "foobar",
                ["management:tracing:ingressIgnorePattern"]     = "pattern",
                ["management:tracing:egressIgnorePattern"]      = "pattern",
                ["management:tracing:maxNumberOfAttributes"]    = "100",
                ["management:tracing:maxNumberOfAnnotations"]   = "100",
                ["management:tracing:maxNumberOfMessageEvents"] = "100",
                ["management:tracing:maxNumberOfLinks"]         = "100",
                ["management:tracing:alwaysSample"]             = "true",
                ["management:tracing:neverSample"]      = "false",
                ["management:tracing:useShortTraceIds"] = "true",
            };

            ConfigurationBuilder builder = new ConfigurationBuilder();

            builder.AddInMemoryCollection(appsettings);
            TracingOptions opts = new TracingOptions(null, builder.Build());

            OpenCensusTracing tracing = new OpenCensusTracing(opts);

            tracing.Tracer.SpanBuilder("spanName").StartScopedSpan(out ISpan span);

            var processor = new TracingLogProcessor(opts, tracing);
            var result    = processor.Process("InputLogMessage");

            Assert.Contains("InputLogMessage", result);
            Assert.Contains("[", result);
            Assert.Contains("]", result);

            var full   = span.Context.TraceId.ToLowerBase16();
            var shorty = full.Substring(full.Length - 16, 16);

            Assert.Contains(shorty, result);
            Assert.DoesNotContain(full, result);

            Assert.Contains(span.Context.SpanId.ToLowerBase16(), result);
            Assert.Contains("foobar", result);
        }
Beispiel #8
0
        public void Process_UseShortTraceIds()
        {
            var appsettings = new Dictionary <string, string>()
            {
                ["management:tracing:name"] = "foobar",
                ["management:tracing:ingressIgnorePattern"]     = "pattern",
                ["management:tracing:egressIgnorePattern"]      = "pattern",
                ["management:tracing:maxNumberOfAttributes"]    = "100",
                ["management:tracing:maxNumberOfAnnotations"]   = "100",
                ["management:tracing:maxNumberOfMessageEvents"] = "100",
                ["management:tracing:maxNumberOfLinks"]         = "100",
                ["management:tracing:alwaysSample"]             = "true",
                ["management:tracing:neverSample"]      = "false",
                ["management:tracing:useShortTraceIds"] = "true",
            };

            var config = TestHelpers.GetConfigurationFromDictionary(appsettings);
            var opts   = new TracingOptions(new ApplicationInstanceInfo(config), config);

            var tracing = new OpenTelemetryTracing(opts);

            tracing.Tracer.StartActiveSpan("spanName", out var span);

            var processor = new TracingLogProcessor(opts, tracing);
            var result    = processor.Process("InputLogMessage");

            Assert.Contains("InputLogMessage", result);
            Assert.Contains("[", result);
            Assert.Contains("]", result);

            var full   = span.Context.TraceId.ToHexString();
            var shorty = full.Substring(full.Length - 16, 16);

            Assert.Contains(shorty, result);
            Assert.DoesNotContain(full, result);

            Assert.Contains(span.Context.SpanId.ToHexString(), result);
            Assert.Contains("foobar", result);
        }