/// <summary>
        /// Enables the outgoing requests automatic data collection.
        /// </summary>
        /// <param name="builder">Trace builder to use.</param>
        /// <param name="configureHttpInstrumentationOptions">Http configuration options.</param>
        /// <param name="configureSqlInstrumentationOptions">Sql configuration options.</param>
        /// <returns>The instance of <see cref="TracerBuilder"/> to chain the calls.</returns>
        public static TracerBuilder AddDependencyInstrumentation(
            this TracerBuilder builder,
            Action <HttpClientInstrumentationOptions> configureHttpInstrumentationOptions = null,
            Action <SqlClientInstrumentationOptions> configureSqlInstrumentationOptions   = null)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            var httpOptions = new HttpClientInstrumentationOptions();

            configureHttpInstrumentationOptions?.Invoke(httpOptions);

            var sqlOptions = new SqlClientInstrumentationOptions();

            configureSqlInstrumentationOptions?.Invoke(sqlOptions);

            return(builder
                   .AddInstrumentation((t) => new AzureClientsInstrumentation(t))
                   .AddInstrumentation((t) => new AzurePipelineInstrumentation(t))
                   .AddInstrumentation((t) => new HttpClientInstrumentation(t, httpOptions))
                   .AddInstrumentation((t) => new HttpWebRequestInstrumentation(t, httpOptions))
                   .AddInstrumentation((t) => new SqlClientInstrumentation(t, sqlOptions)));
        }
Esempio n. 2
0
 private static TracerProviderBuilder AddHttpClientInstrumentation(
     TracerProviderBuilder builder,
     HttpClientInstrumentationOptions options,
     Action <HttpClientInstrumentationOptions> configure = null)
 {
     configure?.Invoke(options);
     return(AddHttpClientInstrumentation(
                builder,
                new HttpClientInstrumentation(options)));
 }
Esempio n. 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);
        }
Esempio n. 4
0
        /// <summary>
        /// Enables HttpClient instrumentation.
        /// </summary>
        /// <param name="builder"><see cref="TracerProviderBuilder"/> being configured.</param>
        /// <param name="configureHttpClientInstrumentationOptions">HttpClient configuration options.</param>
        /// <returns>The instance of <see cref="TracerProviderBuilder"/> to chain the calls.</returns>
        public static TracerProviderBuilder AddHttpClientInstrumentation(
            this TracerProviderBuilder builder,
            Action <HttpClientInstrumentationOptions> configureHttpClientInstrumentationOptions = null)
        {
            Guard.ThrowIfNull(builder, nameof(builder));

            var httpClientOptions = new HttpClientInstrumentationOptions();

            configureHttpClientInstrumentationOptions?.Invoke(httpClientOptions);

            builder.AddInstrumentation(() => new HttpClientInstrumentation(httpClientOptions));
            builder.AddSource(HttpHandlerDiagnosticListener.ActivitySourceName);
            builder.AddLegacySource("System.Net.Http.HttpRequestOut");

            return(builder);
        }
Esempio n. 5
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);
        }
Esempio n. 6
0
        public HttpHandlerDiagnosticListener(HttpClientInstrumentationOptions options)
            : base("HttpHandlerDiagnosticListener")
        {
            var framework = Assembly
                            .GetEntryAssembly()?
                            .GetCustomAttribute <TargetFrameworkAttribute>()?
                            .FrameworkName;

            // Depending on the .NET version/flavor this will look like
            // '.NETCoreApp,Version=v3.0', '.NETCoreApp,Version = v2.2' or '.NETFramework,Version = v4.7.1'

            if (framework != null)
            {
                var match = CoreAppMajorVersionCheckRegex.Match(framework);

                this.httpClientSupportsW3C = match.Success && int.Parse(match.Groups[1].Value, CultureInfo.InvariantCulture) >= 3;
            }

            this.options = options;
        }
Esempio n. 7
0
        /// <summary>
        /// Enables HttpClient instrumentation.
        /// </summary>
        /// <param name="builder"><see cref="TracerProviderBuilder"/> being configured.</param>
        /// <param name="configureHttpClientInstrumentationOptions">HttpClient configuration options.</param>
        /// <returns>The instance of <see cref="TracerProviderBuilder"/> to chain the calls.</returns>
        public static TracerProviderBuilder AddHttpClientInstrumentation(
            this TracerProviderBuilder builder,
            Action <HttpClientInstrumentationOptions> configureHttpClientInstrumentationOptions = null)
#endif
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            var httpClientOptions = new HttpClientInstrumentationOptions();

            configureHttpClientInstrumentationOptions?.Invoke(httpClientOptions);

            builder.AddInstrumentation((activitySource) => new HttpClientInstrumentation(activitySource, httpClientOptions));

#if NETFRAMEWORK
            builder.AddHttpWebRequestInstrumentation(configureHttpWebRequestInstrumentationOptions);
#endif
            return(builder);
        }
        /// <summary>
        /// Enables HttpClient instrumentation.
        /// </summary>
        /// <param name="builder"><see cref="TracerProviderBuilder"/> being configured.</param>
        /// <param name="configureHttpClientInstrumentationOptions">HttpClient configuration options.</param>
        /// <returns>The instance of <see cref="TracerProviderBuilder"/> to chain the calls.</returns>
        public static TracerProviderBuilder AddHttpClientInstrumentation(
            this TracerProviderBuilder builder,
            Action <HttpClientInstrumentationOptions> configureHttpClientInstrumentationOptions = null)
#endif
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            var httpClientOptions = new HttpClientInstrumentationOptions();

            configureHttpClientInstrumentationOptions?.Invoke(httpClientOptions);

            builder.AddInstrumentation(() => new HttpClientInstrumentation(httpClientOptions));
            builder.AddSource(HttpHandlerDiagnosticListener.ActivitySourceName);
            builder.AddLegacySource("System.Net.Http.HttpRequestOut");

#if NETFRAMEWORK
            builder.AddHttpWebRequestInstrumentation(configureHttpWebRequestInstrumentationOptions);
#endif
            return(builder);
        }
 public HttpWebRequestDiagnosticListener(Tracer tracer, HttpClientInstrumentationOptions options)
     : base(HttpWebRequestDiagnosticSource.DiagnosticListenerName, tracer)
 {
     this.options = options;
 }