コード例 #1
0
        public void BroadcastProcessor_ShutsDownAll()
        {
            var processor1 = new TestProcessor(null, null);
            var processor2 = new TestProcessor(null, null);

            var broadcastProcessor = new BroadcastProcessor(new[] { processor1, processor2 });

            broadcastProcessor.ShutdownAsync(default);
コード例 #2
0
        public void BroadcastProcessor_OneProcessorThrows()
        {
            bool start1Called = false;
            bool start2Called = false;
            bool end1Called   = false;
            bool end2Called   = false;
            var  processor1   = new TestProcessor(
                ss =>
            {
                start1Called = true;
                Assert.False(start2Called);
                Assert.False(end1Called);
                Assert.False(end2Called);

                throw new Exception("Start exception");
            }, se =>
            {
                end1Called = true;
                Assert.True(start1Called);
                Assert.True(start2Called);
                Assert.False(end2Called);
                throw new Exception("End exception");
            });

            var processor2 = new TestProcessor(
                ss =>
            {
                start2Called = true;
                Assert.True(start1Called);
                Assert.False(end1Called);
                Assert.False(end2Called);
            }, se =>
            {
                end2Called = true;
                Assert.True(start1Called);
                Assert.True(start2Called);
                Assert.True(end1Called);
            });

            var broadcastProcessor = new BroadcastProcessor(new[] { processor1, processor2 });

            var tracer = TracerFactory.Create(_ => { }).GetTracer(null);
            var span   = (SpanSdk)tracer.StartSpan("foo");

            var spanData = new SpanData(span);

            broadcastProcessor.OnStart(spanData);
            Assert.True(start1Called);
            Assert.True(start2Called);

            broadcastProcessor.OnEnd(spanData);
            Assert.True(end1Called);
            Assert.True(end2Called);
        }
        /// <summary>
        /// Builds the chain of linked <see cref="ITelemetryProcessor" /> instances and sets the same in configuration object passed.
        /// A special telemetry processor for handling Transmission is always appended as the last
        /// processor in the chain.
        /// </summary>
        public void Build()
        {
            var telemetryProcessorsList = new List <ITelemetryProcessor>();
            ITelemetryProcessor linkedTelemetryProcessor;

            if (this.telemetrySink == null)
            {
                // We are building the "common" telemetry processor chain.
                if (this.configuration.TelemetrySinks.Count == 1)
                {
                    // We just need to pass the telemetry directly into the (single) sink.
                    linkedTelemetryProcessor = new PassThroughProcessor(this.configuration.DefaultTelemetrySink);
                }
                else
                {
                    linkedTelemetryProcessor = new BroadcastProcessor(this.configuration.TelemetrySinks);
                }
            }
            else
            {
                linkedTelemetryProcessor = new TransmissionProcessor(this.telemetrySink);
            }

            telemetryProcessorsList.Add(linkedTelemetryProcessor);

            foreach (var generator in this.factories.AsEnumerable().Reverse())
            {
                ITelemetryProcessor prevTelemetryProcessor = linkedTelemetryProcessor;
                linkedTelemetryProcessor = generator.Invoke(linkedTelemetryProcessor);

                if (linkedTelemetryProcessor == null)
                {
                    // Loading of a telemetry processor failed, so skip it
                    // Error is logged when telemetry processor loading failed
                    linkedTelemetryProcessor = prevTelemetryProcessor;
                    continue;
                }

                telemetryProcessorsList.Add(linkedTelemetryProcessor);
            }

            var telemetryProcessorChain = new TelemetryProcessorChain(telemetryProcessorsList.AsEnumerable().Reverse());

            if (this.telemetrySink != null)
            {
                this.telemetrySink.TelemetryProcessorChain = telemetryProcessorChain;
            }
            else
            {
                this.configuration.TelemetryProcessorChain = telemetryProcessorChain;
            }
        }
コード例 #4
0
        public void BroadcastProcessor_CallsAllProcessorSequentially()
        {
            bool start1Called = false;
            bool start2Called = false;
            bool end1Called   = false;
            bool end2Called   = false;
            var  processor1   = new TestProcessor(ss =>
            {
                start1Called = true;
                Assert.False(start2Called);
                Assert.False(end1Called);
                Assert.False(end2Called);
            }, se =>
            {
                end1Called = true;
                Assert.True(start1Called);
                Assert.True(start2Called);
                Assert.False(end2Called);
            });
            var processor2 = new TestProcessor(ss =>
            {
                start2Called = true;
                Assert.True(start1Called);
                Assert.False(end1Called);
                Assert.False(end2Called);
            }, se =>
            {
                end2Called = true;
                Assert.True(start1Called);
                Assert.True(start2Called);
                Assert.True(end1Called);
            });

            var broadcastProcessor = new BroadcastProcessor(new [] { processor1, processor2 });

            var tracer = TracerFactory.Create(_ => { }).GetTracer(null);
            var span   = (Span)tracer.StartSpan("foo");

            broadcastProcessor.OnStart(span);
            Assert.True(start1Called);
            Assert.True(start2Called);

            broadcastProcessor.OnEnd(span);
            Assert.True(end1Called);
            Assert.True(end2Called);
        }
        /// <summary>
        /// Builds the chain of linked <see cref="ITelemetryProcessor" /> instances and sets the same in configuration object passed.
        /// A special telemetry processor for handling Transmission is always appended as the last
        /// processor in the chain.
        /// </summary>
        public void Build()
        {
            var telemetryProcessorsList = new List <ITelemetryProcessor>();
            ITelemetryProcessor linkedTelemetryProcessor;

            if (this.telemetrySink == null)
            {
                // We are building the "common" telemetry processor chain.
                if (this.configuration.TelemetrySinks.Count == 1)
                {
                    // We just need to pass the telemetry directly into the (single) sink.
                    linkedTelemetryProcessor = new PassThroughProcessor(this.configuration.DefaultTelemetrySink);
                }
                else
                {
                    linkedTelemetryProcessor = new BroadcastProcessor(this.configuration.TelemetrySinks);
                }
            }
            else
            {
                linkedTelemetryProcessor = new TransmissionProcessor(this.telemetrySink);
            }

            telemetryProcessorsList.Add(linkedTelemetryProcessor);

            foreach (var generator in this.factories.AsEnumerable().Reverse())
            {
                ITelemetryProcessor prevTelemetryProcessor = linkedTelemetryProcessor;
                linkedTelemetryProcessor = generator.Invoke(linkedTelemetryProcessor);

                if (linkedTelemetryProcessor == null)
                {
                    // Loading of a telemetry processor failed, so skip it
                    // Error is logged when telemetry processor loading failed
                    linkedTelemetryProcessor = prevTelemetryProcessor;
                    continue;
                }

                telemetryProcessorsList.Add(linkedTelemetryProcessor);

                // If a Processor also implements ITelemtryModule, We should Initialize that Module
                if (linkedTelemetryProcessor is ITelemetryModule telemetryModule)
                {
                    try
                    {
                        telemetryModule.Initialize(this.configuration);
                    }
                    catch (Exception ex)
                    {
                        CoreEventSource.Log.ComponentInitializationConfigurationError(telemetryModule.ToString(), ex.ToInvariantString());
                    }
                }
            }

            // Save changes to the TelemetryProcessorChain
            var telemetryProcessorChain = new TelemetryProcessorChain(telemetryProcessorsList.AsEnumerable().Reverse());

            if (this.telemetrySink != null)
            {
                this.telemetrySink.TelemetryProcessorChain = telemetryProcessorChain;
            }
            else
            {
                this.configuration.TelemetryProcessorChain = telemetryProcessorChain;
            }
        }