Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Http Instrumentation] Unify exposed public API #3793

Merged
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,20 @@ OpenTelemetry.Instrumentation.Http.HttpClientInstrumentationOptions.EnrichWithHt
OpenTelemetry.Instrumentation.Http.HttpClientInstrumentationOptions.EnrichWithHttpRequestMessage.set -> void
OpenTelemetry.Instrumentation.Http.HttpClientInstrumentationOptions.EnrichWithHttpResponseMessage.get -> System.Action<System.Diagnostics.Activity, System.Net.Http.HttpResponseMessage>
OpenTelemetry.Instrumentation.Http.HttpClientInstrumentationOptions.EnrichWithHttpResponseMessage.set -> void
OpenTelemetry.Instrumentation.Http.HttpClientInstrumentationOptions.Filter.get -> System.Func<System.Net.Http.HttpRequestMessage, bool>
OpenTelemetry.Instrumentation.Http.HttpClientInstrumentationOptions.Filter.set -> void
OpenTelemetry.Instrumentation.Http.HttpClientInstrumentationOptions.EnrichWithHttpWebRequest.get -> System.Action<System.Diagnostics.Activity, System.Net.HttpWebRequest>
OpenTelemetry.Instrumentation.Http.HttpClientInstrumentationOptions.EnrichWithHttpWebRequest.set -> void
OpenTelemetry.Instrumentation.Http.HttpClientInstrumentationOptions.EnrichWithHttpWebResponse.get -> System.Action<System.Diagnostics.Activity, System.Net.HttpWebResponse>
OpenTelemetry.Instrumentation.Http.HttpClientInstrumentationOptions.EnrichWithHttpWebResponse.set -> void
OpenTelemetry.Instrumentation.Http.HttpClientInstrumentationOptions.FilterHttpRequestMessage.get -> System.Func<System.Net.Http.HttpRequestMessage, bool>
OpenTelemetry.Instrumentation.Http.HttpClientInstrumentationOptions.FilterHttpRequestMessage.set -> void
OpenTelemetry.Instrumentation.Http.HttpClientInstrumentationOptions.FilterHttpWebRequest.get -> System.Func<System.Net.HttpWebRequest, bool>
OpenTelemetry.Instrumentation.Http.HttpClientInstrumentationOptions.FilterHttpWebRequest.set -> void
OpenTelemetry.Instrumentation.Http.HttpClientInstrumentationOptions.HttpClientInstrumentationOptions() -> void
OpenTelemetry.Instrumentation.Http.HttpClientInstrumentationOptions.RecordException.get -> bool
OpenTelemetry.Instrumentation.Http.HttpClientInstrumentationOptions.RecordException.set -> void
OpenTelemetry.Instrumentation.Http.HttpWebRequestInstrumentationOptions
OpenTelemetry.Instrumentation.Http.HttpWebRequestInstrumentationOptions.EnrichWithException.get -> System.Action<System.Diagnostics.Activity, System.Exception>
OpenTelemetry.Instrumentation.Http.HttpWebRequestInstrumentationOptions.EnrichWithException.set -> void
OpenTelemetry.Instrumentation.Http.HttpWebRequestInstrumentationOptions.EnrichWithHttpWebRequest.get -> System.Action<System.Diagnostics.Activity, System.Net.HttpWebRequest>
OpenTelemetry.Instrumentation.Http.HttpWebRequestInstrumentationOptions.EnrichWithHttpWebRequest.set -> void
OpenTelemetry.Instrumentation.Http.HttpWebRequestInstrumentationOptions.EnrichWithHttpWebResponse.get -> System.Action<System.Diagnostics.Activity, System.Net.HttpWebResponse>
OpenTelemetry.Instrumentation.Http.HttpWebRequestInstrumentationOptions.EnrichWithHttpWebResponse.set -> void
OpenTelemetry.Instrumentation.Http.HttpWebRequestInstrumentationOptions.Filter.get -> System.Func<System.Net.HttpWebRequest, bool>
OpenTelemetry.Instrumentation.Http.HttpWebRequestInstrumentationOptions.Filter.set -> void
OpenTelemetry.Instrumentation.Http.HttpWebRequestInstrumentationOptions.HttpWebRequestInstrumentationOptions() -> void
OpenTelemetry.Instrumentation.Http.HttpWebRequestInstrumentationOptions.RecordException.get -> bool
OpenTelemetry.Instrumentation.Http.HttpWebRequestInstrumentationOptions.RecordException.set -> void
OpenTelemetry.Metrics.MeterProviderBuilderExtensions
OpenTelemetry.Trace.TracerProviderBuilderExtensions
static OpenTelemetry.Metrics.MeterProviderBuilderExtensions.AddHttpClientInstrumentation(this OpenTelemetry.Metrics.MeterProviderBuilder builder) -> OpenTelemetry.Metrics.MeterProviderBuilder
static OpenTelemetry.Trace.TracerProviderBuilderExtensions.AddHttpClientInstrumentation(this OpenTelemetry.Trace.TracerProviderBuilder builder) -> OpenTelemetry.Trace.TracerProviderBuilder
static OpenTelemetry.Trace.TracerProviderBuilderExtensions.AddHttpClientInstrumentation(this OpenTelemetry.Trace.TracerProviderBuilder builder, string name, System.Action<OpenTelemetry.Instrumentation.Http.HttpWebRequestInstrumentationOptions> configureHttpWebRequestInstrumentationOptions) -> OpenTelemetry.Trace.TracerProviderBuilder
static OpenTelemetry.Trace.TracerProviderBuilderExtensions.AddHttpClientInstrumentation(this OpenTelemetry.Trace.TracerProviderBuilder builder, System.Action<OpenTelemetry.Instrumentation.Http.HttpWebRequestInstrumentationOptions> configureHttpWebRequestInstrumentationOptions) -> OpenTelemetry.Trace.TracerProviderBuilder
static OpenTelemetry.Trace.TracerProviderBuilderExtensions.AddHttpClientInstrumentation(this OpenTelemetry.Trace.TracerProviderBuilder builder, string name, System.Action<OpenTelemetry.Instrumentation.Http.HttpClientInstrumentationOptions> configureHttpClientInstrumentationOptions) -> OpenTelemetry.Trace.TracerProviderBuilder
static OpenTelemetry.Trace.TracerProviderBuilderExtensions.AddHttpClientInstrumentation(this OpenTelemetry.Trace.TracerProviderBuilder builder, System.Action<OpenTelemetry.Instrumentation.Http.HttpClientInstrumentationOptions> configureHttpClientInstrumentationOptions) -> OpenTelemetry.Trace.TracerProviderBuilder

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,14 @@ OpenTelemetry.Instrumentation.Http.HttpClientInstrumentationOptions.EnrichWithHt
OpenTelemetry.Instrumentation.Http.HttpClientInstrumentationOptions.EnrichWithHttpRequestMessage.set -> void
OpenTelemetry.Instrumentation.Http.HttpClientInstrumentationOptions.EnrichWithHttpResponseMessage.get -> System.Action<System.Diagnostics.Activity, System.Net.Http.HttpResponseMessage>
OpenTelemetry.Instrumentation.Http.HttpClientInstrumentationOptions.EnrichWithHttpResponseMessage.set -> void
OpenTelemetry.Instrumentation.Http.HttpClientInstrumentationOptions.Filter.get -> System.Func<System.Net.Http.HttpRequestMessage, bool>
OpenTelemetry.Instrumentation.Http.HttpClientInstrumentationOptions.Filter.set -> void
OpenTelemetry.Instrumentation.Http.HttpClientInstrumentationOptions.EnrichWithHttpWebRequest.get -> System.Action<System.Diagnostics.Activity, System.Net.HttpWebRequest>
OpenTelemetry.Instrumentation.Http.HttpClientInstrumentationOptions.EnrichWithHttpWebRequest.set -> void
OpenTelemetry.Instrumentation.Http.HttpClientInstrumentationOptions.EnrichWithHttpWebResponse.get -> System.Action<System.Diagnostics.Activity, System.Net.HttpWebResponse>
OpenTelemetry.Instrumentation.Http.HttpClientInstrumentationOptions.EnrichWithHttpWebResponse.set -> void
OpenTelemetry.Instrumentation.Http.HttpClientInstrumentationOptions.FilterHttpRequestMessage.get -> System.Func<System.Net.Http.HttpRequestMessage, bool>
OpenTelemetry.Instrumentation.Http.HttpClientInstrumentationOptions.FilterHttpRequestMessage.set -> void
OpenTelemetry.Instrumentation.Http.HttpClientInstrumentationOptions.FilterHttpWebRequest.get -> System.Func<System.Net.HttpWebRequest, bool>
OpenTelemetry.Instrumentation.Http.HttpClientInstrumentationOptions.FilterHttpWebRequest.set -> void
OpenTelemetry.Instrumentation.Http.HttpClientInstrumentationOptions.HttpClientInstrumentationOptions() -> void
OpenTelemetry.Instrumentation.Http.HttpClientInstrumentationOptions.RecordException.get -> bool
OpenTelemetry.Instrumentation.Http.HttpClientInstrumentationOptions.RecordException.set -> void
Expand Down
6 changes: 6 additions & 0 deletions src/OpenTelemetry.Instrumentation.Http/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@
runtimes for non-sampled outgoing `HttpClient` spans.
([#3828](https://github.com/open-telemetry/opentelemetry-dotnet/pull/3828))

* **Breaking change**: The same API is now exposed for `net462` and
`netstandard2.0` targets. The `Filter` property on options is now exposed as
`FilterHttpRequestMessage` (called for .NET & .NET Core) and
`FilterHttpWebRequest` (called for .NET Framework).
([#3793](https://github.com/open-telemetry/opentelemetry-dotnet/pull/3793))

## 1.0.0-rc9.8

Released 2022-Oct-17
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

using System;
using System.Diagnostics;
using System.Net;
using System.Net.Http;
using System.Runtime.CompilerServices;
using OpenTelemetry.Instrumentation.Http.Implementation;
Expand All @@ -28,17 +29,35 @@ namespace OpenTelemetry.Instrumentation.Http
public class HttpClientInstrumentationOptions
{
/// <summary>
/// Gets or sets a Filter function that determines whether or not to collect telemetry about requests on a per request basis.
/// The Filter gets the HttpRequestMessage, and should return a boolean.
/// If Filter returns true, the request is collected.
/// If Filter returns false or throw exception, the request is filtered out.
/// Gets or sets a filter function that determines whether or not to
/// collect telemetry about requests on a per request basis.
/// </summary>
public Func<HttpRequestMessage, bool> Filter { get; set; }
/// <remarks>
/// Notes:
/// <list type="bullet">
/// <item><b>FilterHttpRequestMessage is only executed on .NET and .NET
/// Core runtimes. <see cref="HttpClient"/> and <see
/// cref="HttpWebRequest"/> on .NET and .NET Core are both implemented
/// using <see cref="HttpRequestMessage"/>.</b></item>
/// <item>The return value for the filter function is interpreted as:
/// <list type="bullet">
/// <item>If filter returns <see langword="true" />, the request is
/// collected.</item>
/// <item>If filter returns <see langword="false" /> or throws an
/// exception the request is NOT collected.</item>
/// </list></item>
/// </list>
/// </remarks>
public Func<HttpRequestMessage, bool> FilterHttpRequestMessage { get; set; }

/// <summary>
/// Gets or sets an action to enrich an Activity with <see cref="HttpRequestMessage"/>.
/// </summary>
/// <remarks>
/// <para><b>EnrichWithHttpRequestMessage is only executed on .NET and .NET
/// Core runtimes. <see cref="HttpClient"/> and <see
/// cref="HttpWebRequest"/> on .NET and .NET Core are both implemented
/// using <see cref="HttpRequestMessage"/>.</b></para>
/// <para><see cref="Activity"/>: the activity being enriched.</para>
/// <para><see cref="HttpRequestMessage"/> object from which additional information can be extracted to enrich the activity.</para>
/// </remarks>
Expand All @@ -48,6 +67,10 @@ public class HttpClientInstrumentationOptions
/// Gets or sets an action to enrich an Activity with <see cref="HttpResponseMessage"/>.
/// </summary>
/// <remarks>
/// <para><b>EnrichWithHttpResponseMessage is only executed on .NET and .NET
/// Core runtimes. <see cref="HttpClient"/> and <see
/// cref="HttpWebRequest"/> on .NET and .NET Core are both implemented
/// using <see cref="HttpRequestMessage"/>.</b></para>
/// <para><see cref="Activity"/>: the activity being enriched.</para>
/// <para><see cref="HttpResponseMessage"/> object from which additional information can be extracted to enrich the activity.</para>
/// </remarks>
Expand All @@ -57,28 +80,90 @@ public class HttpClientInstrumentationOptions
/// Gets or sets an action to enrich an Activity with <see cref="Exception"/>.
/// </summary>
/// <remarks>
/// <para><b>EnrichWithException is called for all runtimes.</b></para>
/// <para><see cref="Activity"/>: the activity being enriched.</para>
/// <para><see cref="Exception"/> object from which additional information can be extracted to enrich the activity.</para>
/// </remarks>
public Action<Activity, Exception> EnrichWithException { get; set; }

/// <summary>
/// Gets or sets a value indicating whether exception will be recorded as ActivityEvent or not.
/// Gets or sets a filter function that determines whether or not to
/// collect telemetry about requests on a per request basis.
/// </summary>
/// <remarks>
/// Notes:
/// <list type="bullet">
/// <item><b>FilterHttpWebRequest is only executed on .NET Framework
/// runtimes. <see cref="HttpClient"/> and <see cref="HttpWebRequest"/>
/// on .NET Framework are both implemented using <see
/// cref="HttpWebRequest"/>.</b></item>
/// <item>The return value for the filter function is interpreted as:
/// <list type="bullet">
/// <item>If filter returns <see langword="true" />, the request is
/// collected.</item>
/// <item>If filter returns <see langword="false" /> or throws an
/// exception the request is NOT collected.</item>
/// </list></item>
/// </list>
/// </remarks>
public Func<HttpWebRequest, bool> FilterHttpWebRequest { get; set; }
cijothomas marked this conversation as resolved.
Show resolved Hide resolved

/// <summary>
/// Gets or sets an action to enrich an Activity with <see cref="HttpWebRequest"/>.
/// </summary>
/// <remarks>
/// <para><b>EnrichWithHttpWebRequest is only executed on .NET Framework
/// runtimes. <see cref="HttpClient"/> and <see cref="HttpWebRequest"/>
/// on .NET Framework are both implemented using <see
/// cref="HttpWebRequest"/>.</b></para>
/// <para><see cref="Activity"/>: the activity being enriched.</para>
/// <para><see cref="HttpWebRequest"/> object from which additional information can be extracted to enrich the activity.</para>
/// </remarks>
public Action<Activity, HttpWebRequest> EnrichWithHttpWebRequest { get; set; }

/// <summary>
/// Gets or sets an action to enrich an Activity with <see cref="HttpWebResponse"/>.
/// </summary>
/// <remarks>
/// <para><b>EnrichWithHttpWebResponse is only executed on .NET Framework
/// runtimes. <see cref="HttpClient"/> and <see cref="HttpWebRequest"/>
/// on .NET Framework are both implemented using <see
/// cref="HttpWebRequest"/>.</b></para>
/// <para><see cref="Activity"/>: the activity being enriched.</para>
/// <para><see cref="HttpWebResponse"/> object from which additional information can be extracted to enrich the activity.</para>
/// </remarks>
public Action<Activity, HttpWebResponse> EnrichWithHttpWebResponse { get; set; }

/// <summary>
/// Gets or sets a value indicating whether exception will be recorded as an <see cref="ActivityEvent"/> or not.
/// </summary>
/// <remarks>
/// https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/semantic_conventions/exceptions.md.
/// See: <see href="https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/semantic_conventions/exceptions.md" />.
/// </remarks>
public bool RecordException { get; set; }

[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal bool EventFilter(string activityName, object arg1)
internal bool EventFilterHttpRequestMessage(string activityName, object arg1)
{
try
{
return
this.Filter == null ||
this.FilterHttpRequestMessage == null ||
!TryParseHttpRequestMessage(activityName, arg1, out HttpRequestMessage requestMessage) ||
this.Filter(requestMessage);
this.FilterHttpRequestMessage(requestMessage);
}
catch (Exception ex)
{
HttpInstrumentationEventSource.Log.RequestFilterException(ex);
return false;
}
}

internal bool EventFilterHttpWebRequest(HttpWebRequest request)
{
try
{
return this.FilterHttpWebRequest?.Invoke(request) ?? true;
}
catch (Exception ex)
{
Expand Down
Loading