Skip to content

Commit

Permalink
[Instrumentation.Http] Nullable (#1941)
Browse files Browse the repository at this point in the history
  • Loading branch information
Kielek authored Jul 9, 2024
1 parent d6aff08 commit 49a01d3
Show file tree
Hide file tree
Showing 21 changed files with 278 additions and 240 deletions.
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
#nullable enable
OpenTelemetry.Instrumentation.Http.HttpClientTraceInstrumentationOptions
OpenTelemetry.Instrumentation.Http.HttpClientTraceInstrumentationOptions.EnrichWithException.get -> System.Action<System.Diagnostics.Activity, System.Exception>
OpenTelemetry.Instrumentation.Http.HttpClientTraceInstrumentationOptions.EnrichWithException.get -> System.Action<System.Diagnostics.Activity!, System.Exception!>?
OpenTelemetry.Instrumentation.Http.HttpClientTraceInstrumentationOptions.EnrichWithException.set -> void
OpenTelemetry.Instrumentation.Http.HttpClientTraceInstrumentationOptions.EnrichWithHttpRequestMessage.get -> System.Action<System.Diagnostics.Activity, System.Net.Http.HttpRequestMessage>
OpenTelemetry.Instrumentation.Http.HttpClientTraceInstrumentationOptions.EnrichWithHttpRequestMessage.get -> System.Action<System.Diagnostics.Activity!, System.Net.Http.HttpRequestMessage!>?
OpenTelemetry.Instrumentation.Http.HttpClientTraceInstrumentationOptions.EnrichWithHttpRequestMessage.set -> void
OpenTelemetry.Instrumentation.Http.HttpClientTraceInstrumentationOptions.EnrichWithHttpResponseMessage.get -> System.Action<System.Diagnostics.Activity, System.Net.Http.HttpResponseMessage>
OpenTelemetry.Instrumentation.Http.HttpClientTraceInstrumentationOptions.EnrichWithHttpResponseMessage.get -> System.Action<System.Diagnostics.Activity!, System.Net.Http.HttpResponseMessage!>?
OpenTelemetry.Instrumentation.Http.HttpClientTraceInstrumentationOptions.EnrichWithHttpResponseMessage.set -> void
OpenTelemetry.Instrumentation.Http.HttpClientTraceInstrumentationOptions.EnrichWithHttpWebRequest.get -> System.Action<System.Diagnostics.Activity, System.Net.HttpWebRequest>
OpenTelemetry.Instrumentation.Http.HttpClientTraceInstrumentationOptions.EnrichWithHttpWebRequest.get -> System.Action<System.Diagnostics.Activity!, System.Net.HttpWebRequest!>?
OpenTelemetry.Instrumentation.Http.HttpClientTraceInstrumentationOptions.EnrichWithHttpWebRequest.set -> void
OpenTelemetry.Instrumentation.Http.HttpClientTraceInstrumentationOptions.EnrichWithHttpWebResponse.get -> System.Action<System.Diagnostics.Activity, System.Net.HttpWebResponse>
OpenTelemetry.Instrumentation.Http.HttpClientTraceInstrumentationOptions.EnrichWithHttpWebResponse.get -> System.Action<System.Diagnostics.Activity!, System.Net.HttpWebResponse!>?
OpenTelemetry.Instrumentation.Http.HttpClientTraceInstrumentationOptions.EnrichWithHttpWebResponse.set -> void
OpenTelemetry.Instrumentation.Http.HttpClientTraceInstrumentationOptions.FilterHttpRequestMessage.get -> System.Func<System.Net.Http.HttpRequestMessage, bool>
OpenTelemetry.Instrumentation.Http.HttpClientTraceInstrumentationOptions.FilterHttpRequestMessage.get -> System.Func<System.Net.Http.HttpRequestMessage!, bool>?
OpenTelemetry.Instrumentation.Http.HttpClientTraceInstrumentationOptions.FilterHttpRequestMessage.set -> void
OpenTelemetry.Instrumentation.Http.HttpClientTraceInstrumentationOptions.FilterHttpWebRequest.get -> System.Func<System.Net.HttpWebRequest, bool>
OpenTelemetry.Instrumentation.Http.HttpClientTraceInstrumentationOptions.FilterHttpWebRequest.get -> System.Func<System.Net.HttpWebRequest!, bool>?
OpenTelemetry.Instrumentation.Http.HttpClientTraceInstrumentationOptions.FilterHttpWebRequest.set -> void
OpenTelemetry.Instrumentation.Http.HttpClientTraceInstrumentationOptions.HttpClientTraceInstrumentationOptions() -> void
OpenTelemetry.Instrumentation.Http.HttpClientTraceInstrumentationOptions.RecordException.get -> bool
OpenTelemetry.Instrumentation.Http.HttpClientTraceInstrumentationOptions.RecordException.set -> void
OpenTelemetry.Metrics.HttpClientInstrumentationMeterProviderBuilderExtensions
OpenTelemetry.Trace.HttpClientInstrumentationTracerProviderBuilderExtensions
static OpenTelemetry.Metrics.HttpClientInstrumentationMeterProviderBuilderExtensions.AddHttpClientInstrumentation(this OpenTelemetry.Metrics.MeterProviderBuilder builder) -> OpenTelemetry.Metrics.MeterProviderBuilder
static OpenTelemetry.Trace.HttpClientInstrumentationTracerProviderBuilderExtensions.AddHttpClientInstrumentation(this OpenTelemetry.Trace.TracerProviderBuilder builder, string name, System.Action<OpenTelemetry.Instrumentation.Http.HttpClientTraceInstrumentationOptions> configureHttpClientTraceInstrumentationOptions) -> OpenTelemetry.Trace.TracerProviderBuilder
static OpenTelemetry.Trace.HttpClientInstrumentationTracerProviderBuilderExtensions.AddHttpClientInstrumentation(this OpenTelemetry.Trace.TracerProviderBuilder builder, System.Action<OpenTelemetry.Instrumentation.Http.HttpClientTraceInstrumentationOptions> configureHttpClientTraceInstrumentationOptions) -> OpenTelemetry.Trace.TracerProviderBuilder
static OpenTelemetry.Trace.HttpClientInstrumentationTracerProviderBuilderExtensions.AddHttpClientInstrumentation(this OpenTelemetry.Trace.TracerProviderBuilder builder) -> OpenTelemetry.Trace.TracerProviderBuilder
static OpenTelemetry.Metrics.HttpClientInstrumentationMeterProviderBuilderExtensions.AddHttpClientInstrumentation(this OpenTelemetry.Metrics.MeterProviderBuilder! builder) -> OpenTelemetry.Metrics.MeterProviderBuilder!
static OpenTelemetry.Trace.HttpClientInstrumentationTracerProviderBuilderExtensions.AddHttpClientInstrumentation(this OpenTelemetry.Trace.TracerProviderBuilder! builder, string? name, System.Action<OpenTelemetry.Instrumentation.Http.HttpClientTraceInstrumentationOptions!>? configureHttpClientTraceInstrumentationOptions) -> OpenTelemetry.Trace.TracerProviderBuilder!
static OpenTelemetry.Trace.HttpClientInstrumentationTracerProviderBuilderExtensions.AddHttpClientInstrumentation(this OpenTelemetry.Trace.TracerProviderBuilder! builder, System.Action<OpenTelemetry.Instrumentation.Http.HttpClientTraceInstrumentationOptions!>? configureHttpClientTraceInstrumentationOptions) -> OpenTelemetry.Trace.TracerProviderBuilder!
static OpenTelemetry.Trace.HttpClientInstrumentationTracerProviderBuilderExtensions.AddHttpClientInstrumentation(this OpenTelemetry.Trace.TracerProviderBuilder! builder) -> OpenTelemetry.Trace.TracerProviderBuilder!
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ internal sealed class HttpClientInstrumentation : IDisposable

private readonly DiagnosticSourceSubscriber diagnosticSourceSubscriber;

private readonly Func<string, object, object, bool> isEnabled = (eventName, _, _)
private readonly Func<string, object?, object?, bool> isEnabled = (eventName, _, _)
=> !ExcludedDiagnosticSourceEvents.Contains(eventName);

private readonly Func<string, object, object, bool> isEnabledNet7OrGreater = (eventName, _, _)
private readonly Func<string, object?, object?, bool> isEnabledNet7OrGreater = (eventName, _, _)
=> !ExcludedDiagnosticSourceEventsNet7OrGreater.Contains(eventName);

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public static TracerProviderBuilder AddHttpClientInstrumentation(this TracerProv
/// <returns>The instance of <see cref="TracerProviderBuilder"/> to chain the calls.</returns>
public static TracerProviderBuilder AddHttpClientInstrumentation(
this TracerProviderBuilder builder,
Action<HttpClientTraceInstrumentationOptions> configureHttpClientTraceInstrumentationOptions)
Action<HttpClientTraceInstrumentationOptions>? configureHttpClientTraceInstrumentationOptions)
=> AddHttpClientInstrumentation(builder, name: null, configureHttpClientTraceInstrumentationOptions);

/// <summary>
Expand All @@ -42,8 +42,8 @@ public static TracerProviderBuilder AddHttpClientInstrumentation(
/// <returns>The instance of <see cref="TracerProviderBuilder"/> to chain the calls.</returns>
public static TracerProviderBuilder AddHttpClientInstrumentation(
this TracerProviderBuilder builder,
string name,
Action<HttpClientTraceInstrumentationOptions> configureHttpClientTraceInstrumentationOptions)
string? name,
Action<HttpClientTraceInstrumentationOptions>? configureHttpClientTraceInstrumentationOptions)
{
Guard.ThrowIfNull(builder);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ internal sealed class HttpClientMetrics : IDisposable

private readonly DiagnosticSourceSubscriber diagnosticSourceSubscriber;

private readonly Func<string, object, object, bool> isEnabled = (activityName, obj1, obj2)
private readonly Func<string, object?, object?, bool> isEnabled = (activityName, _, _)
=> !ExcludedDiagnosticSourceEvents.Contains(activityName);

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// SPDX-License-Identifier: Apache-2.0

using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Net;
using System.Runtime.CompilerServices;
#if NETFRAMEWORK
Expand Down Expand Up @@ -29,7 +30,7 @@ internal HttpClientTraceInstrumentationOptions(IConfiguration configuration)
{
Debug.Assert(configuration != null, "configuration was null");

if (configuration.TryGetBoolValue(
if (configuration!.TryGetBoolValue(
HttpInstrumentationEventSource.Log,
"OTEL_DOTNET_EXPERIMENTAL_HTTPCLIENT_DISABLE_URL_QUERY_REDACTION",
out var disableUrlQueryRedaction))
Expand Down Expand Up @@ -58,7 +59,7 @@ internal HttpClientTraceInstrumentationOptions(IConfiguration configuration)
/// </list></item>
/// </list>
/// </remarks>
public Func<HttpRequestMessage, bool> FilterHttpRequestMessage { get; set; }
public Func<HttpRequestMessage, bool>? FilterHttpRequestMessage { get; set; }

/// <summary>
/// Gets or sets an action to enrich an <see cref="Activity"/> with <see cref="HttpRequestMessage"/>.
Expand All @@ -69,7 +70,7 @@ internal HttpClientTraceInstrumentationOptions(IConfiguration configuration)
/// cref="HttpWebRequest"/> on .NET and .NET Core are both implemented
/// using <see cref="HttpRequestMessage"/>.</b></para>
/// </remarks>
public Action<Activity, HttpRequestMessage> EnrichWithHttpRequestMessage { get; set; }
public Action<Activity, HttpRequestMessage>? EnrichWithHttpRequestMessage { get; set; }

/// <summary>
/// Gets or sets an action to enrich an <see cref="Activity"/> with <see cref="HttpResponseMessage"/>.
Expand All @@ -80,15 +81,15 @@ internal HttpClientTraceInstrumentationOptions(IConfiguration configuration)
/// cref="HttpWebRequest"/> on .NET and .NET Core are both implemented
/// using <see cref="HttpRequestMessage"/>.</b></para>
/// </remarks>
public Action<Activity, HttpResponseMessage> EnrichWithHttpResponseMessage { get; set; }
public Action<Activity, HttpResponseMessage>? EnrichWithHttpResponseMessage { get; set; }

/// <summary>
/// Gets or sets an action to enrich an <see cref="Activity"/> with <see cref="Exception"/>.
/// </summary>
/// <remarks>
/// <para><b>EnrichWithException is called for all runtimes.</b></para>
/// </remarks>
public Action<Activity, Exception> EnrichWithException { get; set; }
public Action<Activity, Exception>? EnrichWithException { get; set; }

/// <summary>
/// Gets or sets a filter function that determines whether or not to
Expand All @@ -110,7 +111,7 @@ internal HttpClientTraceInstrumentationOptions(IConfiguration configuration)
/// </list></item>
/// </list>
/// </remarks>
public Func<HttpWebRequest, bool> FilterHttpWebRequest { get; set; }
public Func<HttpWebRequest, bool>? FilterHttpWebRequest { get; set; }

/// <summary>
/// Gets or sets an action to enrich an <see cref="Activity"/> with <see cref="HttpWebRequest"/>.
Expand All @@ -121,7 +122,7 @@ internal HttpClientTraceInstrumentationOptions(IConfiguration configuration)
/// on .NET Framework are both implemented using <see
/// cref="HttpWebRequest"/>.</b></para>
/// </remarks>
public Action<Activity, HttpWebRequest> EnrichWithHttpWebRequest { get; set; }
public Action<Activity, HttpWebRequest>? EnrichWithHttpWebRequest { get; set; }

/// <summary>
/// Gets or sets an action to enrich an <see cref="Activity"/> with <see cref="HttpWebResponse"/>.
Expand All @@ -132,7 +133,7 @@ internal HttpClientTraceInstrumentationOptions(IConfiguration configuration)
/// on .NET Framework are both implemented using <see
/// cref="HttpWebRequest"/>.</b></para>
/// </remarks>
public Action<Activity, HttpWebResponse> EnrichWithHttpWebResponse { get; set; }
public Action<Activity, HttpWebResponse>? EnrichWithHttpWebResponse { get; set; }

/// <summary>
/// Gets or sets a value indicating whether exception will be recorded
Expand Down Expand Up @@ -164,7 +165,7 @@ internal bool EventFilterHttpRequestMessage(string activityName, object arg1)
{
return
this.FilterHttpRequestMessage == null ||
!TryParseHttpRequestMessage(activityName, arg1, out HttpRequestMessage requestMessage) ||
!TryParseHttpRequestMessage(activityName, arg1, out HttpRequestMessage? requestMessage) ||
this.FilterHttpRequestMessage(requestMessage);
}
catch (Exception ex)
Expand All @@ -188,7 +189,7 @@ internal bool EventFilterHttpWebRequest(HttpWebRequest request)
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static bool TryParseHttpRequestMessage(string activityName, object arg1, out HttpRequestMessage requestMessage)
private static bool TryParseHttpRequestMessage(string activityName, object arg1, [NotNullWhen(true)] out HttpRequestMessage? requestMessage)
{
return (requestMessage = arg1 as HttpRequestMessage) != null && activityName == "System.Net.Http.HttpRequestOut";
}
Expand Down
Loading

0 comments on commit 49a01d3

Please sign in to comment.