コード例 #1
0
        /// <summary>
        /// Enables the outgoing requests automatic data collection for GrpcClient.
        /// </summary>
        /// <param name="builder"><see cref="OpenTelemetryBuilder"/> being configured.</param>
        /// <returns>The instance of <see cref="OpenTelemetryBuilder"/> to chain the calls.</returns>
        public static OpenTelemetryBuilder AddGrpcClientDependencyInstrumentation(
            this OpenTelemetryBuilder builder)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            builder.AddInstrumentation((activitySource) => new GrpcClientInstrumentation(activitySource));
            return(builder);
        }
コード例 #2
0
        /// <summary>
        /// Enables instrumentation for Azure clients.
        /// </summary>
        /// <param name="builder"><see cref="OpenTelemetryBuilder"/> being configured.</param>
        /// <returns>The instance of <see cref="OpenTelemetryBuilder"/> to chain the calls.</returns>
        public static OpenTelemetryBuilder AddAzureClientsDependencyInstrumentation(
            this OpenTelemetryBuilder builder)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            builder.AddActivitySource(AzureSdkDiagnosticListener.ActivitySourceName);
            builder.AddInstrumentation(() => new AzureClientsInstrumentation());
            return(builder);
        }
コード例 #3
0
        /// <summary>
        /// Enables the outgoing requests automatic data collection for HttpClient.
        /// </summary>
        /// <param name="builder"><see cref="OpenTelemetryBuilder"/> being configured.</param>
        /// <param name="configureHttpClientInstrumentationOptions">HttpClient configuration options.</param>
        /// <returns>The instance of <see cref="OpenTelemetryBuilder"/> to chain the calls.</returns>
        public static OpenTelemetryBuilder AddHttpClientDependencyInstrumentation(
            this OpenTelemetryBuilder builder,
            Action <HttpClientInstrumentationOptions> configureHttpClientInstrumentationOptions = null)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            var httpClientOptions = new HttpClientInstrumentationOptions();

            configureHttpClientInstrumentationOptions?.Invoke(httpClientOptions);

            builder.AddInstrumentation((activitySource) => new HttpClientInstrumentation(activitySource, httpClientOptions));
            return(builder);
        }
コード例 #4
0
        /// <summary>
        /// Enables the incoming requests automatic data collection for Asp.Net Core.
        /// </summary>
        /// <param name="builder"><see cref="OpenTelemetryBuilder"/> being configured.</param>
        /// <param name="configureAspNetCoreInstrumentationOptions">ASP.NET Core Request configuration options.</param>
        /// <returns>The instance of <see cref="OpenTelemetryBuilder"/> to chain the calls.</returns>
        public static OpenTelemetryBuilder AddRequestInstrumentation(
            this OpenTelemetryBuilder builder,
            Action <AspNetCoreInstrumentationOptions> configureAspNetCoreInstrumentationOptions = null)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            var aspnetCoreOptions = new AspNetCoreInstrumentationOptions();

            configureAspNetCoreInstrumentationOptions?.Invoke(aspnetCoreOptions);
            builder.AddInstrumentation((activitySource) => new AspNetCoreInstrumentation(activitySource, aspnetCoreOptions));

            return(builder);
        }
コード例 #5
0
        /// <summary>
        /// Enables the outgoing requests automatic data collection for SqlClient.
        /// </summary>
        /// <param name="builder"><see cref="OpenTelemetryBuilder"/> being configured.</param>
        /// <param name="configureSqlClientInstrumentationOptions">SqlClient configuration options.</param>
        /// <returns>The instance of <see cref="OpenTelemetryBuilder"/> to chain the calls.</returns>
        public static OpenTelemetryBuilder AddSqlClientDependencyInstrumentation(
            this OpenTelemetryBuilder builder,
            Action <SqlClientInstrumentationOptions> configureSqlClientInstrumentationOptions = null)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            var sqlOptions = new SqlClientInstrumentationOptions();

            configureSqlClientInstrumentationOptions?.Invoke(sqlOptions);

            builder.AddInstrumentation((activitySource) => new SqlClientInstrumentation(sqlOptions));
            builder.AddActivitySource(SqlClientDiagnosticListener.ActivitySourceName);

            return(builder);
        }
コード例 #6
0
        /// <summary>
        /// Enables the outgoing requests automatic data collection for Redis.
        /// </summary>
        /// <param name="builder"><see cref="OpenTelemetryBuilder"/> being configured.</param>
        /// <param name="connection"><see cref="ConnectionMultiplexer"/> to instrument.</param>
        /// <param name="configureOptions">Redis configuration options.</param>
        /// <returns>The instance of <see cref="OpenTelemetryBuilder"/> to chain the calls.</returns>
        public static OpenTelemetryBuilder AddRedisInstrumentation(
            this OpenTelemetryBuilder builder,
            ConnectionMultiplexer connection,
            Action <StackExchangeRedisCallsInstrumentationOptions> configureOptions = null)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            StackExchangeRedisCallsInstrumentationOptions options = new StackExchangeRedisCallsInstrumentationOptions();

            configureOptions?.Invoke(options);

            return(builder
                   .AddInstrumentation((activitySourceAdapter) => new StackExchangeRedisCallsInstrumentation(connection, options))
                   .AddActivitySource(StackExchangeRedisCallsInstrumentation.ActivitySourceName));
        }
コード例 #7
0
        /// <summary>
        /// Enables the outgoing requests automatic data collection for HttpClient.
        /// </summary>
        /// <param name="builder"><see cref="OpenTelemetryBuilder"/> being configured.</param>
        /// <param name="configureHttpClientInstrumentationOptions">HttpClient configuration options.</param>
        /// <returns>The instance of <see cref="OpenTelemetryBuilder"/> to chain the calls.</returns>
        public static OpenTelemetryBuilder AddHttpClientDependencyInstrumentation(
            this OpenTelemetryBuilder builder,
            Action <HttpClientInstrumentationOptions> configureHttpClientInstrumentationOptions)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            // HttpClient is not instrumented with ActivitySource, hence
            // it'll have a default ActivitySource with name string.Empty.
            builder.AddActivitySource(string.Empty);
            var httpClientOptions = new HttpClientInstrumentationOptions();

            configureHttpClientInstrumentationOptions?.Invoke(httpClientOptions);

            builder.AddInstrumentation(() => new HttpClientInstrumentation(httpClientOptions));
            return(builder);
        }
コード例 #8
0
        /// <summary>
        /// Enables the incoming requests automatic data collection for Asp.Net.
        /// </summary>
        /// <param name="builder"><see cref="OpenTelemetryBuilder"/> being configured.</param>
        /// <param name="configureAspNetInstrumentationOptions">ASP.NET Request configuration options.</param>
        /// <returns>The instance of <see cref="OpenTelemetryBuilder"/> to chain the calls.</returns>
        public static OpenTelemetryBuilder AddRequestInstrumentation(
            this OpenTelemetryBuilder builder,
            Action <AspNetInstrumentationOptions> configureAspNetInstrumentationOptions = null)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            // Asp.Net is not instrumented with ActivitySource, hence
            // it'll have a default ActivitySource with name string.Empty.
            builder.AddActivitySource(string.Empty);
            var aspnetOptions = new AspNetInstrumentationOptions();

            configureAspNetInstrumentationOptions?.Invoke(aspnetOptions);

            builder.AddInstrumentation(() => new AspNetInstrumentation(aspnetOptions));

            return(builder);
        }