Esempio n. 1
0
        internal static object Run(string host, int port)
        {
            // Configure exporter to export traces to Jaeger
            var jaegerOptions = new JaegerExporterOptions()
            {
                ServiceName = "tracing-to-jaeger-service",
                AgentHost   = host,
                AgentPort   = port,
            };

            var exporter = new JaegerTraceExporter(
                jaegerOptions);

            // Create a tracer. You may also need to register it as a global instance to make auto-collectors work..
            var tracerFactory = new TracerFactory(new BatchingSpanProcessor(exporter));
            var tracer        = tracerFactory.GetTracer(string.Empty);

            // Create a scoped span. It will end automatically when using statement ends
            using (tracer.WithSpan(tracer.SpanBuilder("Main").StartSpan()))
            {
                tracer.CurrentSpan.SetAttribute("custom-attribute", 55);
                Console.WriteLine("About to do a busy work");
                for (int i = 0; i < 10; i++)
                {
                    DoWork(i, tracer);
                }
            }

            // Gracefully shutdown the exporter so it'll flush queued traces to Jaeger.
            exporter.ShutdownAsync(CancellationToken.None).GetAwaiter().GetResult();
            return(null);
        }
 public void JaegerTraceExporter_ctor_NullServiceNameAllowed()
 {
     using var jaegerTraceExporter = new JaegerTraceExporter(new JaegerExporterOptions
     {
         ServiceName = null,
     });
     Assert.NotNull(jaegerTraceExporter);
 }
        public void Constructor_ValidOptions_ReturnsInstance()
        {
            // Arrange
            var options = new JaegerExporterOptions {
                ServiceName = "test_service"
            };

            // Act
            var exporter = new JaegerTraceExporter(options);

            // Assert
            Assert.NotNull(exporter);
        }
        public void JaegerTraceExporter_ApplyLibraryResource_IgnoreLibraryResources()
        {
            using var jaegerTraceExporter = new JaegerTraceExporter(new JaegerExporterOptions());
            var process = jaegerTraceExporter.JaegerAgentUdpBatcher.Process;

            jaegerTraceExporter.ApplyLibraryResource(new Resource(new Dictionary <string, object>
            {
                [Resource.LibraryNameKey]    = "libname",
                [Resource.LibraryVersionKey] = "libversion",
            }));

            Assert.Null(process.Tags);
        }
        public void JaegerTraceExporter_ApplyLibraryResource_CreatesTags()
        {
            using var jaegerTraceExporter = new JaegerTraceExporter(new JaegerExporterOptions());
            var process = jaegerTraceExporter.JaegerAgentUdpBatcher.Process;

            jaegerTraceExporter.ApplyLibraryResource(new Resource(new Dictionary <string, object>
            {
                ["Tag"] = "value",
            }));

            Assert.NotNull(process.Tags);
            Assert.Single(process.Tags);
            Assert.Equal("value", process.Tags["Tag"].VStr);
        }
        public void JaegerTraceExporter_ApplyLibraryResource_CombinesTags()
        {
            using var jaegerTraceExporter = new JaegerTraceExporter(new JaegerExporterOptions());
            var process = jaegerTraceExporter.JaegerAgentUdpBatcher.Process;

            process.Tags = new Dictionary <string, JaegerTag> {
                ["Tag1"] = new KeyValuePair <string, object>("Tag1", "value1").ToJaegerTag()
            };

            jaegerTraceExporter.ApplyLibraryResource(new Resource(new Dictionary <string, object>
            {
                ["Tag2"] = "value2",
            }));

            Assert.NotNull(process.Tags);
            Assert.Equal(2, process.Tags.Count);
            Assert.Equal("value1", process.Tags["Tag1"].VStr);
            Assert.Equal("value2", process.Tags["Tag2"].VStr);
        }
        public void JaegerTraceExporter_ApplyLibraryResource_UpdatesServiceName()
        {
            using var jaegerTraceExporter = new JaegerTraceExporter(new JaegerExporterOptions());
            var process = jaegerTraceExporter.JaegerAgentUdpBatcher.Process;

            process.ServiceName = "TestService";

            jaegerTraceExporter.ApplyLibraryResource(Resource.Empty);

            Assert.Equal("TestService", process.ServiceName);

            jaegerTraceExporter.ApplyLibraryResource(Resources.Resources.CreateServiceResource("MyService"));

            Assert.Equal("MyService", process.ServiceName);

            jaegerTraceExporter.ApplyLibraryResource(Resources.Resources.CreateServiceResource("MyService", serviceNamespace: "MyNamespace"));

            Assert.Equal("MyNamespace.MyService", process.ServiceName);
        }