Beispiel #1
0
 public RabbitMQClient(IConfiguration configuration,
                       ILogger <RabbitMQClient> logger,
                       TracerFactoryBase tracerFactoryBase)
 {
     this.configuration = configuration ?? throw new ArgumentNullException(nameof(configuration));
     this.logger        = logger ?? throw new ArgumentNullException(nameof(logger));
     tracer             = tracerFactoryBase.GetApplicationTracer();
 }
        public void DefaultTracerFactory()
        {
            Assert.Equal(typeof(TracerFactoryBase), TracerFactoryBase.Default.GetType());
            Assert.Equal(typeof(ProxyTracer), TracerFactoryBase.Default.GetTracer(null).GetType());

            var newFactory = TracerFactory.Create(_ => { });

            TracerFactoryBase.SetDefault(newFactory);
            Assert.IsAssignableFrom <TracerFactory>(TracerFactoryBase.Default);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="DependenciesCollector"/> class.
        /// </summary>
        /// <param name="options">Configuraiton options.</param>
        /// <param name="tracerFactory">Tracer factory to get a tracer from.</param>
        public DependenciesCollector(HttpClientCollectorOptions options, TracerFactoryBase tracerFactory)
        {
            var assemblyVersion       = typeof(DependenciesCollector).Assembly.GetName().Version;
            var httpClientListener    = new HttpClientCollector(tracerFactory.GetTracer(nameof(HttpClientCollector), "semver:" + assemblyVersion), options);
            var azureClientsListener  = new AzureClientsCollector(tracerFactory.GetTracer(nameof(AzureClientsCollector), "semver:" + assemblyVersion));
            var azurePipelineListener = new AzurePipelineCollector(tracerFactory.GetTracer(nameof(AzurePipelineCollector), "semver:" + assemblyVersion));

            this.collectors.Add(httpClientListener);
            this.collectors.Add(azureClientsListener);
            this.collectors.Add(azurePipelineListener);
        }
        public void TraceFactory_UpdateDefault_CachedTracer()
        {
            var defaultTracer = TracerFactoryBase.Default.GetTracer(string.Empty);
            var noopSpan      = defaultTracer.StartSpan("foo");

            Assert.IsType <BlankSpan>(noopSpan);

            TracerFactoryBase.SetDefault(TracerFactory.Create(b => { }));
            var span = defaultTracer.StartSpan("foo");

            Assert.IsType <SpanSdk>(span);

            var newDefaultTracer = TracerFactoryBase.Default.GetTracer(string.Empty);

            Assert.NotSame(defaultTracer, newDefaultTracer);
            Assert.IsType <TracerSdk>(newDefaultTracer);
        }
        public void TraceFactory_SetDefault()
        {
            var factory = TracerFactory.Create(b => { });

            TracerFactoryBase.SetDefault(factory);

            var defaultTracer = TracerFactoryBase.Default.GetTracer(string.Empty);

            Assert.NotNull(defaultTracer);
            Assert.IsType <TracerSdk>(defaultTracer);

            Assert.NotSame(defaultTracer, TracerFactoryBase.Default.GetTracer("named tracerSdk"));

            var span = defaultTracer.StartSpan("foo");

            Assert.IsType <SpanSdk>(span);
        }
Beispiel #6
0
        private static async Task Foo(TracerFactoryBase tracerFactory)
        {
            var tracer = tracerFactory.GetTracer("ConsoleApp", "semver:1.0.0");

            using (tracer.WithSpan(tracer.StartSpan("Main")))
            {
                using (tracer.WithSpan(tracer.StartSpan("Main (span1)")))
                {
                    await Task.Delay(100);

                    using (tracer.WithSpan(tracer.StartSpan("Foo (span2)")))
                    {
                        tracer.CurrentSpan.SetAttribute("myattribute", "mvalue");
                        await Task.Delay(100);
                    }
                }
            }
        }
Beispiel #7
0
        /// <summary>
        /// Initializes a new instance of the <see cref="DependenciesCollector"/> class.
        /// </summary>
        /// <param name="tracerFactory">Tracer factory to get a tracer from.</param>
        /// <param name="httpOptions">Http configuration options.</param>
        /// <param name="sqlOptions">Sql configuration options.</param>
        public DependenciesCollector(TracerFactoryBase tracerFactory, HttpClientCollectorOptions httpOptions = null, SqlClientCollectorOptions sqlOptions = null)
        {
            if (tracerFactory == null)
            {
                throw new ArgumentNullException(nameof(tracerFactory));
            }

            var assemblyVersion = typeof(DependenciesCollector).Assembly.GetName().Version;

            var httpClientListener    = new HttpClientCollector(tracerFactory.GetTracer(nameof(HttpClientCollector), "semver:" + assemblyVersion), httpOptions ?? new HttpClientCollectorOptions());
            var azureClientsListener  = new AzureClientsCollector(tracerFactory.GetTracer(nameof(AzureClientsCollector), "semver:" + assemblyVersion));
            var azurePipelineListener = new AzurePipelineCollector(tracerFactory.GetTracer(nameof(AzurePipelineCollector), "semver:" + assemblyVersion));
            var sqlClientListener     = new SqlClientCollector(tracerFactory.GetTracer(nameof(AzurePipelineCollector), "semver:" + assemblyVersion), sqlOptions ?? new SqlClientCollectorOptions());

            this.collectors.Add(httpClientListener);
            this.collectors.Add(azureClientsListener);
            this.collectors.Add(azurePipelineListener);
            this.collectors.Add(sqlClientListener);
        }
Beispiel #8
0
        /// <summary>
        /// Initializes a new instance of the <see cref="DependenciesInstrumentation"/> class.
        /// </summary>
        /// <param name="tracerFactory">Tracer factory to get a tracer from.</param>
        /// <param name="httpOptions">Http configuration options.</param>
        /// <param name="sqlOptions">Sql configuration options.</param>
        public DependenciesInstrumentation(TracerFactoryBase tracerFactory, HttpClientInstrumentationOptions httpOptions = null, SqlClientInstrumentationOptions sqlOptions = null)
        {
            if (tracerFactory == null)
            {
                throw new ArgumentNullException(nameof(tracerFactory));
            }

            var assemblyVersion = typeof(DependenciesInstrumentation).Assembly.GetName().Version;

            var httpClientListener            = new HttpClientInstrumentation(tracerFactory.GetTracer(nameof(HttpClientInstrumentation), "semver:" + assemblyVersion), httpOptions ?? new HttpClientInstrumentationOptions());
            var httpWebRequestInstrumentation = new HttpWebRequestInstrumentation(tracerFactory.GetTracer(nameof(HttpWebRequestInstrumentation), "semver:" + assemblyVersion), httpOptions ?? new HttpClientInstrumentationOptions());
            var azureClientsListener          = new AzureClientsInstrumentation(tracerFactory.GetTracer(nameof(AzureClientsInstrumentation), "semver:" + assemblyVersion));
            var azurePipelineListener         = new AzurePipelineInstrumentation(tracerFactory.GetTracer(nameof(AzurePipelineInstrumentation), "semver:" + assemblyVersion));
            var sqlClientListener             = new SqlClientInstrumentation(tracerFactory.GetTracer(nameof(SqlClientInstrumentation), "semver:" + assemblyVersion), sqlOptions ?? new SqlClientInstrumentationOptions());

            this.instrumentations.Add(httpClientListener);
            this.instrumentations.Add(httpWebRequestInstrumentation);
            this.instrumentations.Add(azureClientsListener);
            this.instrumentations.Add(azurePipelineListener);
            this.instrumentations.Add(sqlClientListener);
        }
 public WeatherForecastController(ILogger <WeatherForecastController> logger, TracerFactoryBase tracerFactory)
 {
     _logger = logger;
     _tracer = tracerFactory.GetTracer("custom");
 }
 public static Tracer GetApplicationTracer(this TracerFactoryBase tracerFactory)
 {
     return(tracerFactory.GetTracer(TracerServiceName, appTracerVersion));
 }
 public void TraceFactory_SetDefaultTwice_Throws()
 {
     TracerFactoryBase.SetDefault(TracerFactory.Create(b => { }));
     Assert.Throws <InvalidOperationException>(() => TracerFactoryBase.SetDefault(TracerFactory.Create(b => { })));
 }
 public void TraceFactory_SetDefaultNull()
 {
     Assert.Throws <ArgumentNullException>(() => TracerFactoryBase.SetDefault(null));
 }
Beispiel #13
0
 public OpenTelemetryCollectingDeviceRepository(TDeviceRepository repository, TracerFactoryBase tracerFactory)
 {
     this.tracer     = tracerFactory.GetTracer("sql");
     this.repository = repository;
 }
 public Program(TracerFactoryBase tracerFactory)
 {
     _tracer = tracerFactory.GetTracer("mytracername", "semver:1.0.0");
 }