Example #1
0
        public void TestPropagationJaegerAndB3FromConfig()
        {
            TraceId traceId = new TraceId(1234);
            SpanId  spanId  = new SpanId(5678);

            TestTextMap textMap     = new TestTextMap();
            SpanContext spanContext = new SpanContext(traceId, spanId, new SpanId(0), (byte)0);

            CodecConfiguration codecConfiguration = new CodecConfiguration(_loggerFactory)
                                                    .WithPropagation(Configuration.Propagation.Jaeger)
                                                    .WithPropagation(Configuration.Propagation.B3);
            ITracer tracer = new Configuration("Test", _loggerFactory)
                             .WithCodec(codecConfiguration)
                             .GetTracer();

            tracer.Inject(spanContext, BuiltinFormats.TextMap, textMap);

            Assert.NotNull(textMap.Get("uber-trace-id"));
            Assert.NotNull(textMap.Get("X-B3-TraceId"));
            Assert.NotNull(textMap.Get("X-B3-SpanId"));

            SpanContext extractedContext = (SpanContext)tracer.Extract(BuiltinFormats.TextMap, textMap);

            Assert.Equal(traceId, extractedContext.TraceId);
            Assert.Equal(spanId, extractedContext.SpanId);
        }
        public Tracer.Builder GetTracerBuilder()
        {
            if (ReporterConfig == null)
            {
                ReporterConfig = new ReporterConfiguration(_loggerFactory);
            }
            if (SamplerConfig == null)
            {
                SamplerConfig = new SamplerConfiguration(_loggerFactory);
            }
            if (_codecConfig == null)
            {
                _codecConfig = new CodecConfiguration(new Dictionary <IFormat <ITextMap>, List <Codec <ITextMap> > >());
            }
            if (_metricsFactory == null)
            {
                _metricsFactory = NoopMetricsFactory.Instance;
            }
            IMetrics  metrics  = new MetricsImpl(_metricsFactory);
            IReporter reporter = ReporterConfig.GetReporter(metrics);
            ISampler  sampler  = SamplerConfig.CreateSampler(_serviceName, metrics);

            Tracer.Builder builder = new Tracer.Builder(_serviceName)
                                     .WithLoggerFactory(_loggerFactory)
                                     .WithSampler(sampler)
                                     .WithReporter(reporter)
                                     .WithMetrics(metrics)
                                     .WithTags(_tracerTags);

            _codecConfig.Apply(builder);

            return(builder);
        }
        /// <summary>
        /// Returns <see cref="Configuration"/> object from environmental variables.
        /// </summary>
        public static Configuration FromEnv(ILoggerFactory loggerFactory)
        {
            ILogger logger = loggerFactory.CreateLogger <Configuration>();

            return(new Configuration(GetProperty(JaegerServiceName), loggerFactory)
                   .WithTracerTags(TracerTagsFromEnv(logger))
                   .WithReporter(ReporterConfiguration.FromEnv(loggerFactory))
                   .WithSampler(SamplerConfiguration.FromEnv(loggerFactory))
                   .WithCodec(CodecConfiguration.FromEnv(loggerFactory)));
        }
        /// <summary>
        /// Returns <see cref="Configuration"/> object from a Configuration.
        /// </summary>
        public static Configuration FromIConfiguration(ILoggerFactory loggerFactory, IConfiguration configuration)
        {
            ILogger logger = loggerFactory.CreateLogger <Configuration>();

            return(new Configuration(GetProperty(JaegerServiceName, logger, configuration), loggerFactory)
                   .WithTracerTags(TracerTagsFromIConfiguration(logger, configuration))
                   .WithTraceId128Bit(GetPropertyAsBool(JaegerTraceId128Bit, logger, configuration).GetValueOrDefault(false))
                   .WithReporter(ReporterConfiguration.FromIConfiguration(loggerFactory, configuration))
                   .WithSampler(SamplerConfiguration.FromIConfiguration(loggerFactory, configuration))
                   .WithCodec(CodecConfiguration.FromIConfiguration(loggerFactory, configuration)));
        }
        /// <summary>
        /// Creates a stream which binds an input file to a codec configuration.
        /// The stream is used for muxings later on.<para />
        ///
        /// API endpoint:
        /// https://bitmovin.com/docs/encoding/api-reference/sections/encodings#/Encoding/PostEncodingEncodingsStreamsByEncodingId
        /// </summary>
        /// <param name="encoding">The encoding to add the stream onto</param>
        /// <param name="inputStreams">The list of inputStream resources providing the input file, to be merged</param>
        /// <param name="configuration">The codec configuration to be applied to the stream</param>
        private Task <Stream> CreateStream(Models.Encoding encoding, List <InputStream> inputStreams,
                                           CodecConfiguration configuration)
        {
            var stream = new Stream()
            {
                CodecConfigId = configuration.Id,
                Mode          = StreamMode.STANDARD
            };

            foreach (var inputStream in inputStreams)
            {
                stream.InputStreams.Add(new StreamInput {
                    InputStreamId = inputStream.Id
                });
            }

            return(_bitmovinApi.Encoding.Encodings.Streams.CreateAsync(encoding.Id, stream));
        }
Example #6
0
        /// <summary>
        /// Creates a stream which binds an input file to a codec configuration.
        /// The stream is used for muxings later on.<para />
        ///
        /// API endpoint:
        /// https://bitmovin.com/docs/encoding/api-reference/sections/encodings#/Encoding/PostEncodingEncodingsStreamsByEncodingId
        /// </summary>
        /// <param name="encoding">The encoding to add the stream onto</param>
        /// <param name="inputStream">The inputStream resource providing the input file</param>
        /// <param name="configuration">The codec configuration to be applied to the stream</param>
        private Task <Stream> CreateStream(Models.Encoding encoding, InputStream inputStream,
                                           CodecConfiguration configuration)
        {
            var streamInput = new StreamInput()
            {
                InputStreamId = inputStream.Id
            };

            var stream = new Stream()
            {
                InputStreams = new List <StreamInput>()
                {
                    streamInput
                },
                CodecConfigId = configuration.Id,
                Mode          = StreamMode.STANDARD
            };

            return(_bitmovinApi.Encoding.Encodings.Streams.CreateAsync(encoding.Id, stream));
        }
        /// <summary>
        /// Adds an audio mix input stream to an encoding
        ///
        /// API endpoint:
        /// https://bitmovin.com/docs/encoding/api-reference/sections/encodings#/Encoding/PostEncodingEncodingsStreamsByEncodingId
        /// </summary>
        /// <param name="encoding">The encoding to which the stream will be added</param>
        /// <param name="concatenationInputStream">The input resource providing the input file</param>
        /// <param name="codecConfiguration">The codec configuration to be applied to the stream</param>
        private Task <Stream> CreateStreamWithConcatenationInputStream(Models.Encoding encoding, ConcatenationInputStream concatenationInputStream,
                                                                       CodecConfiguration codecConfiguration)
        {
            var streamInput = new StreamInput()
            {
                InputStreamId = concatenationInputStream.Id
            };

            var inputStreams = new List <StreamInput>()
            {
                streamInput
            };
            var stream = new Stream()
            {
                InputStreams  = inputStreams,
                CodecConfigId = codecConfiguration.Id
            };

            return(_bitmovinApi.Encoding.Encodings.Streams.CreateAsync(encoding.Id, stream));
        }
        /// <summary>
        /// Creates a stream which binds an input file to a codec configuration.
        /// The stream is used for muxings later on.<para />
        ///
        /// API endpoint:
        /// https://bitmovin.com/docs/encoding/api-reference/sections/encodings#/Encoding/PostEncodingEncodingsStreamsByEncodingId
        /// </summary>
        /// <param name="encoding">The encoding to add the stream onto</param>
        /// <param name="input">The input that should be used</param>
        /// <param name="inputPath">The path to the input file</param>
        /// <param name="configuration">The codec configuration to be applied to the stream</param>
        private Task <Stream> CreateStream(Models.Encoding encoding, Input input, string inputPath,
                                           CodecConfiguration configuration)
        {
            var streamInput = new StreamInput()
            {
                InputId       = input.Id,
                InputPath     = inputPath,
                SelectionMode = StreamSelectionMode.AUTO
            };

            var stream = new Stream()
            {
                InputStreams = new List <StreamInput>()
                {
                    streamInput
                },
                CodecConfigId = configuration.Id
            };

            return(_bitmovinApi.Encoding.Encodings.Streams.CreateAsync(encoding.Id, stream));
        }
        public Tracer.Builder GetTracerBuilder()
        {
            if (ReporterConfig == null)
            {
                ReporterConfig = new ReporterConfiguration(_loggerFactory);
            }
            if (SamplerConfig == null)
            {
                SamplerConfig = new SamplerConfiguration(_loggerFactory);
            }
            if (CodecConfig == null)
            {
                CodecConfig = new CodecConfiguration(_loggerFactory);
            }
            if (_metricsFactory == null)
            {
                _metricsFactory = NoopMetricsFactory.Instance;
            }
            IMetrics  metrics  = new MetricsImpl(_metricsFactory);
            IReporter reporter = ReporterConfig.GetReporter(metrics);
            ISampler  sampler  = SamplerConfig.GetSampler(ServiceName, metrics);

            Tracer.Builder builder = new Tracer.Builder(ServiceName)
                                     .WithLoggerFactory(_loggerFactory)
                                     .WithSampler(sampler)
                                     .WithReporter(reporter)
                                     .WithMetrics(metrics)
                                     .WithTags(_tracerTags);

            if (UseTraceId128Bit)
            {
                builder = builder.WithTraceId128Bit();
            }

            CodecConfig.Apply(builder);

            return(builder);
        }
            /// <summary>
            /// Attempts to create a new <see cref="CodecConfiguration"/> based on an IConfiguration.
            /// </summary>
            public static CodecConfiguration FromIConfiguration(ILoggerFactory loggerFactory, IConfiguration configuration)
            {
                ILogger logger = loggerFactory.CreateLogger <Configuration>();

                CodecConfiguration codecConfiguration = new CodecConfiguration(loggerFactory);
                string             propagation        = GetProperty(JaegerPropagation, logger, configuration);

                if (propagation != null)
                {
                    foreach (string format in propagation.Split(','))
                    {
                        if (Enum.TryParse <Propagation>(format, true, out var propagationEnum))
                        {
                            codecConfiguration.WithPropagation(propagationEnum);
                        }
                        else
                        {
                            logger.LogError("Unknown propagation format {format}", format);
                        }
                    }
                }
                return(codecConfiguration);
            }
 public Configuration WithCodec(CodecConfiguration codecConfig)
 {
     CodecConfig = codecConfig;
     return(this);
 }