예제 #1
0
        public void CheckForceFlushExport(int timeout)
        {
            var exportedItems = new List <Activity>();

            using var exporter  = new InMemoryExporter <Activity>(exportedItems);
            using var processor = new SimpleActivityExportProcessor(exporter);

            var activity1 = new Activity("start1");

            activity1.ActivityTraceFlags = ActivityTraceFlags.Recorded;

            var activity2 = new Activity("start2");

            activity2.ActivityTraceFlags = ActivityTraceFlags.Recorded;

            processor.OnEnd(activity1);
            processor.OnEnd(activity2);

            // checking before force flush
            Assert.Equal(2, exportedItems.Count);

            // forcing flush
            processor.ForceFlush(timeout);
            Assert.Equal(2, exportedItems.Count);
        }
        public void ExportResultIsSuccess()
        {
#if NETCOREAPP3_1
            // Adding the OtlpExporter creates a GrpcChannel.
            // This switch must be set before creating a GrpcChannel/HttpClient when calling an insecure gRPC service.
            // See: https://docs.microsoft.com/aspnet/core/grpc/troubleshoot#call-insecure-grpc-services-with-net-core-client
            AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport", true);
#endif

            var exporterOptions = new OtlpExporterOptions
            {
                Endpoint = new System.Uri($"http://{CollectorEndpoint}"),
            };

            var otlpExporter            = new OtlpTraceExporter(exporterOptions);
            var delegatingExporter      = new DelegatingTestExporter <Activity>(otlpExporter);
            var exportActivityProcessor = new SimpleActivityExportProcessor(delegatingExporter);

            var activitySourceName = "otlp.collector.test";

            var builder = Sdk.CreateTracerProviderBuilder()
                          .AddSource(activitySourceName)
                          .AddProcessor(exportActivityProcessor);

            using var tracerProvider = builder.Build();

            var source   = new ActivitySource(activitySourceName);
            var activity = source.StartActivity("Test Activity");
            activity?.Stop();

            Assert.Single(delegatingExporter.ExportResults);
            Assert.Equal(ExportResult.Success, delegatingExporter.ExportResults[0]);
        }
예제 #3
0
        public void CheckExportForRecordingButNotSampledActivity()
        {
            var exportedItems = new List <Activity>();

            using var exporter  = new InMemoryExporter <Activity>(exportedItems);
            using var processor = new SimpleActivityExportProcessor(exporter);

            var activity = new Activity("start");

            activity.ActivityTraceFlags = ActivityTraceFlags.None;

            processor.OnEnd(activity);
            Assert.Empty(exportedItems);
        }
예제 #4
0
        public void CheckShutdownExport(int timeout)
        {
            var exportedItems = new List <Activity>();

            using var exporter  = new InMemoryExporter <Activity>(exportedItems);
            using var processor = new SimpleActivityExportProcessor(exporter);

            var activity = new Activity("start");

            activity.ActivityTraceFlags = ActivityTraceFlags.Recorded;

            processor.OnEnd(activity);

            // checking before shutdown
            Assert.Single(exportedItems);

            processor.Shutdown(timeout);
            Assert.Single(exportedItems);
        }
예제 #5
0
        public void CheckExportedOnEnd()
        {
            var exportedItems = new List <Activity>();

            using var exporter  = new InMemoryExporter <Activity>(exportedItems);
            using var processor = new SimpleActivityExportProcessor(exporter);

            var activity1 = new Activity("start1");

            activity1.ActivityTraceFlags = ActivityTraceFlags.Recorded;

            processor.OnEnd(activity1);
            Assert.Single(exportedItems);

            var activity2 = new Activity("start2");

            activity2.ActivityTraceFlags = ActivityTraceFlags.Recorded;

            processor.OnEnd(activity2);
            Assert.Equal(2, exportedItems.Count);
        }