예제 #1
0
        private TracerFactory(TracerBuilder builder)
        {
            this.sampler = builder.Sampler ?? Samplers.AlwaysSample;

            // TODO separate sampler from options
            this.configurationOptions =
                builder.TracerConfigurationOptions ?? new TracerConfiguration(this.sampler);

            // TODO log warning (or throw?) if there is no exporter
            this.exporter = builder.SpanExporter ?? new NoopSpanExporter();

            this.spanProcessor = builder.ProcessorFactory != null?
                                 builder.ProcessorFactory(this.exporter) :
                                     new BatchingSpanProcessor(this.exporter);

            this.binaryFormat = builder.BinaryFormat ?? new BinaryFormat();
            this.textFormat   = builder.TextFormat ?? new TraceContextFormat();

            this.defaultTracer = new Tracer(
                this.spanProcessor,
                this.configurationOptions,
                this.binaryFormat,
                this.textFormat,
                Resource.Empty);
        }
        private TracerFactory(TracerBuilder builder)
        {
            this.sampler         = builder.Sampler ?? Samplers.AlwaysSample;
            this.defaultResource = builder.Resource;

            this.configurationOptions =
                builder.TracerConfigurationOptions ?? new TracerConfiguration();

            if (builder.ProcessingPipelines == null || !builder.ProcessingPipelines.Any())
            {
                // if there are no pipelines are configured, use noop processor
                this.spanProcessor = new NoopSpanProcessor();
            }
            else if (builder.ProcessingPipelines.Count == 1)
            {
                // if there is only one pipeline - use it's outer processor as a
                // single processor on the tracer.
                var processorFactory = builder.ProcessingPipelines[0];
                this.spanProcessor = processorFactory.Build();
            }
            else
            {
                // if there are more pipelines, use processor that will broadcast to all pipelines
                var processors = new SpanProcessor[builder.ProcessingPipelines.Count];

                for (int i = 0; i < builder.ProcessingPipelines.Count; i++)
                {
                    processors[i] = builder.ProcessingPipelines[i].Build();
                }

                this.spanProcessor = new BroadcastProcessor(processors);
            }

            this.binaryFormat = builder.BinaryFormat ?? new BinaryFormat();
            this.textFormat   = builder.TextFormat ?? new TraceContextFormat();

            this.defaultTracer = new Tracer(
                this.spanProcessor,
                this.sampler,
                this.configurationOptions,
                this.binaryFormat,
                this.textFormat,
                this.defaultResource);
        }
 /// <summary>
 /// Configures tracing options.
 /// </summary>
 /// <param name="options">Instance of <see cref="TracerConfiguration"/>.</param>
 public TracerBuilder SetTracerOptions(TracerConfiguration options)
 {
     this.TracerConfigurationOptions = options ?? throw new ArgumentNullException(nameof(options));
     return(this);
 }