Esempio n. 1
0
        private Action <TracerBuilder> ConfigureOptions(ITracingOptions options, Action <TracerBuilder> configureTracer)
        {
            return(builder =>
            {
                Sampler sampler = null;
                if (options.AlwaysSample)
                {
                    sampler = new AlwaysOnSampler();
                }
                else if (options.NeverSample)
                {
                    sampler = new AlwaysOffSampler();
                }

                builder.SetTracerOptions(TracerConfiguration);

                if (sampler != null)
                {
                    ConfiguredSampler = sampler;
                    builder.SetSampler(sampler);
                }

                configureTracer?.Invoke(builder);
            });
        }
Esempio n. 2
0
        public void ExportProcessorIgnoresActivityWhenDropped()
        {
            var sampler   = new AlwaysOffSampler();
            var processor = new TestActivityExportProcessor(new TestExporter <Activity>(_ => { }));

            using var activitySource = new ActivitySource(ActivitySourceName);
            using var sdk            = OpenTelemetrySdk.CreateTracerProviderBuilder()
                                       .AddSource(ActivitySourceName)
                                       .SetSampler(sampler)
                                       .AddProcessor(processor)
                                       .Build();

            using (var activity = activitySource.StartActivity("Activity"))
            {
                Assert.False(activity.IsAllDataRequested);
                Assert.Equal(ActivityTraceFlags.None, activity.ActivityTraceFlags);
            }

            Assert.Empty(processor.ExportedItems);
        }