示例#1
0
        private static MagicOnionOpenTelemetryOptions BindMagicOnionOpenTelemetryOptions(IServiceCollection services, string configurationName)
        {
            var name            = !string.IsNullOrEmpty(configurationName) ? configurationName : "MagicOnion:OpenTelemetry";
            var serviceProvider = services.BuildServiceProvider();
            var config          = serviceProvider.GetService <IConfiguration>();
            var options         = new MagicOnionOpenTelemetryOptions();

            config.GetSection(name).Bind(options);
            return(options);
        }
示例#2
0
        /// <summary>add MagicOnion Telemetry.</summary>
        public static IServiceCollection AddMagicOnionOpenTelemetry(this IServiceCollection services,
                                                                    MagicOnionOpenTelemetryOptions options,
                                                                    Action <MagicOnionOpenTelemetryOptions, MagicOnionOpenTelemetryMeterFactoryOption> configureMeterProvider,
                                                                    Action <MagicOnionOpenTelemetryOptions, IServiceProvider, TracerProviderBuilder> configureTracerProvider)
        {
            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            services.AddSingleton(options);

            // configure MeterFactory
            if (configureMeterProvider != null)
            {
                var meterFactoryOption = new MagicOnionOpenTelemetryMeterFactoryOption();
                configureMeterProvider(options, meterFactoryOption);

                MeterProvider.SetDefault(Sdk.CreateMeterProviderBuilder()
                                         .SetProcessor(meterFactoryOption.MetricProcessor)
                                         .SetExporter(meterFactoryOption.MetricExporter)
                                         .SetPushInterval(meterFactoryOption.MetricPushInterval)
                                         .Build());

                services.AddSingleton(meterFactoryOption.MetricExporter);
                services.AddSingleton(MeterProvider.Default);
            }

            // configure TracerFactory
            if (configureTracerProvider != null)
            {
                if (string.IsNullOrEmpty(options.ActivitySourceName))
                {
                    throw new NullReferenceException(nameof(options.ActivitySourceName));
                }

                var tracerFactory = services.AddOpenTelemetryTracerProvider((provider, builder) =>
                {
                    // ActivitySourceName must match to TracerName.
                    builder.AddSource(options.ActivitySourceName);
                    configureTracerProvider(options, provider, builder);
                });
                services.AddSingleton(tracerFactory);
                services.AddSingleton(new ActivitySource(options.ActivitySourceName));
            }

            return(services);
        }
        /// <summary>add MagicOnion Telemetry.</summary>
        public static IServiceCollection AddMagicOnionOpenTelemetry(this IServiceCollection services,
                                                                    MagicOnionOpenTelemetryOptions options,
                                                                    Action <MagicOnionOpenTelemetryOptions, MagicOnionOpenTelemetryMeterFactoryOption> configureMeterFactory,
                                                                    Action <MagicOnionOpenTelemetryOptions, TracerBuilder> configureTracerFactory)
        {
            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }
            if (string.IsNullOrEmpty(options.ServiceName))
            {
                throw new ArgumentNullException($"{nameof(options)}.{nameof(options.ServiceName)}");
            }

            services.AddSingleton(options);

            // configure MeterFactory
            if (configureMeterFactory != null)
            {
                var meterFactoryOption = new MagicOnionOpenTelemetryMeterFactoryOption();
                configureMeterFactory(options, meterFactoryOption);

                var meterFactory = MeterFactory.Create(mb =>
                {
                    mb.SetMetricProcessor(meterFactoryOption.MetricProcessor);
                    mb.SetMetricExporter(meterFactoryOption.MetricExporter);
                    mb.SetMetricPushInterval(meterFactoryOption.MetricPushInterval);
                });

                services.AddSingleton(meterFactoryOption.MetricExporter);
                services.AddSingleton(meterFactory);
            }

            // configure TracerFactory
            if (configureTracerFactory != null)
            {
                var tracerFactory = TracerFactory.Create(tracerBuilder => configureTracerFactory(options, tracerBuilder));
                services.AddSingleton(tracerFactory);
            }

            return(services);
        }
示例#4
0
 /// <summary>add MagicOnion Telemetry.</summary>
 public static IServiceCollection AddMagicOnionOpenTelemetry(this IServiceCollection services,
                                                             MagicOnionOpenTelemetryOptions options)
 {
     return(AddMagicOnionOpenTelemetry(services, options, null, null));
 }
 public OpenTelemetryCollectorFilter(TracerProvider tracerProvider, MagicOnionOpenTelemetryOptions telemetryOption)
 {
     this.tracerProvider  = tracerProvider;
     this.telemetryOption = telemetryOption;
 }
 public OpenTelemetryHubCollectorFilter(TracerFactory tracerFactory, MagicOnionOpenTelemetryOptions telemetryOption)
 {
     this.tracerFactcory = tracerFactory;
     this.serviceName    = telemetryOption.ServiceName;
 }
示例#7
0
 public OpenTelemetryCollectorFilterAttribute(ActivitySource activitySource, MagicOnionOpenTelemetryOptions telemetryOption)
 {
     this.source          = activitySource;
     this.telemetryOption = telemetryOption;
 }