diff --git a/build/Common.props b/build/Common.props
index bbbe345136..ff82b6647f 100644
--- a/build/Common.props
+++ b/build/Common.props
@@ -44,7 +44,7 @@
[8.0.0,9.0)
[1.9.0-beta.2]
[1.9.0,2.0)
- [1.10.0-beta.1]
+ [1.10.0-rc.1]
[2.6.122,3.0)
[2.4.0,3.0)
[3.16.0,4.0)
diff --git a/src/OpenTelemetry.Exporter.Geneva/CHANGELOG.md b/src/OpenTelemetry.Exporter.Geneva/CHANGELOG.md
index 7ca97b842c..317de4751a 100644
--- a/src/OpenTelemetry.Exporter.Geneva/CHANGELOG.md
+++ b/src/OpenTelemetry.Exporter.Geneva/CHANGELOG.md
@@ -19,6 +19,9 @@
For configuration details see:
[OtlpProtobufEncoding](./README.md#otlpprotobufencoding).
+* Update OpenTelemetry SDK version to `1.10.0-rc.1`.
+ ([#2294](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/pull/2294))
+
## 1.9.0
Released 2024-Jun-21
diff --git a/src/OpenTelemetry.Exporter.Geneva/Common.GenevaExporter.props b/src/OpenTelemetry.Exporter.Geneva/Common.GenevaExporter.props
index 5570a7a1fe..78181066e1 100644
--- a/src/OpenTelemetry.Exporter.Geneva/Common.GenevaExporter.props
+++ b/src/OpenTelemetry.Exporter.Geneva/Common.GenevaExporter.props
@@ -1,6 +1,6 @@
- $(OpenTelemetryCoreLatestVersion)
+ $(OpenTelemetryCoreLatestPrereleaseVersion)
diff --git a/src/OpenTelemetry.Exporter.Geneva/Internal/ReentrantExportProcessor.cs b/src/OpenTelemetry.Exporter.Geneva/Internal/ReentrantExportProcessor.cs
index b0da2159fc..71ac6bbb6e 100644
--- a/src/OpenTelemetry.Exporter.Geneva/Internal/ReentrantExportProcessor.cs
+++ b/src/OpenTelemetry.Exporter.Geneva/Internal/ReentrantExportProcessor.cs
@@ -1,21 +1,11 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
-using System.Linq.Expressions;
-using System.Reflection;
-
namespace OpenTelemetry.Exporter.Geneva;
-// This export processor exports without synchronization.
-// Once OpenTelemetry .NET officially support this,
-// we can get rid of this class.
-// This is currently only used in ETW export, where we know
-// that the underlying system is safe under concurrent calls.
internal class ReentrantExportProcessor : BaseExportProcessor
where T : class
{
- private static readonly Func> CreateBatch = BuildCreateBatchDelegate();
-
public ReentrantExportProcessor(BaseExporter exporter)
: base(exporter)
{
@@ -23,16 +13,6 @@ public ReentrantExportProcessor(BaseExporter exporter)
protected override void OnExport(T data)
{
- this.exporter.Export(CreateBatch(data));
- }
-
- private static Func> BuildCreateBatchDelegate()
- {
- var flags = BindingFlags.Instance | BindingFlags.NonPublic;
- var ctor = typeof(Batch).GetConstructor(flags, null, new Type[] { typeof(T) }, null)
- ?? throw new InvalidOperationException("Batch ctor accepting a single item could not be found reflectively");
- var value = Expression.Parameter(typeof(T), null);
- var lambda = Expression.Lambda>>(Expression.New(ctor, value), value);
- return lambda.Compile();
+ this.exporter.Export(new(data));
}
}
diff --git a/src/OpenTelemetry.Exporter.OneCollector/CHANGELOG.md b/src/OpenTelemetry.Exporter.OneCollector/CHANGELOG.md
index 0803ff2ac5..b4f4b438cc 100644
--- a/src/OpenTelemetry.Exporter.OneCollector/CHANGELOG.md
+++ b/src/OpenTelemetry.Exporter.OneCollector/CHANGELOG.md
@@ -15,6 +15,10 @@
also be applied to subsequent `LogRecord`s in the same batch.
([#2205](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/pull/2205))
+* Update OpenTelemetry SDK version to `1.10.0-rc.1` and removed the direct
+ reference to `Microsoft.Extensions.Configuration.Binder`.
+ ([#2295](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/pull/2295))
+
## 1.9.3
Released 2024-Oct-11
diff --git a/src/OpenTelemetry.Exporter.OneCollector/OpenTelemetry.Exporter.OneCollector.csproj b/src/OpenTelemetry.Exporter.OneCollector/OpenTelemetry.Exporter.OneCollector.csproj
index dfb5f27c1d..c8d10cef7d 100644
--- a/src/OpenTelemetry.Exporter.OneCollector/OpenTelemetry.Exporter.OneCollector.csproj
+++ b/src/OpenTelemetry.Exporter.OneCollector/OpenTelemetry.Exporter.OneCollector.csproj
@@ -18,13 +18,12 @@
- $(OpenTelemetryCoreLatestVersion)
+ $(OpenTelemetryCoreLatestPrereleaseVersion)
$(DefineConstants);EXPOSE_EXPERIMENTAL_FEATURES
-
diff --git a/src/OpenTelemetry.Instrumentation.ElasticsearchClient/Implementation/ElasticsearchRequestPipelineDiagnosticListener.cs b/src/OpenTelemetry.Instrumentation.ElasticsearchClient/Implementation/ElasticsearchRequestPipelineDiagnosticListener.cs
index 0687bd2582..5f57879521 100644
--- a/src/OpenTelemetry.Instrumentation.ElasticsearchClient/Implementation/ElasticsearchRequestPipelineDiagnosticListener.cs
+++ b/src/OpenTelemetry.Instrumentation.ElasticsearchClient/Implementation/ElasticsearchRequestPipelineDiagnosticListener.cs
@@ -57,6 +57,8 @@ public override void OnEventWritten(string name, object? payload)
case "CallElasticsearch.Stop":
this.OnStopActivity(activity, payload);
break;
+ default:
+ break;
}
}
@@ -69,12 +71,7 @@ private static string GetDisplayName(Activity activity, object? method, string?
case "CallElasticsearch" when method != null:
{
var methodName = MethodNameCache.GetOrAdd(method, $"Elasticsearch {method}");
- if (elasticType == null)
- {
- return methodName;
- }
-
- return $"{methodName} {elasticType}";
+ return elasticType == null ? methodName : $"{methodName} {elasticType}";
}
default:
@@ -122,7 +119,7 @@ private string ParseAndFormatRequest(string debugInformation)
var request = ParseRequest.Match(debugInformation);
if (request.Success)
{
- string? body = request.Groups[1]?.Value?.Trim();
+ var body = request.Groups[1]?.Value?.Trim();
if (body == null)
{
return debugInformation;
@@ -193,7 +190,7 @@ private void OnStartActivity(Activity activity, object? payload)
}
var uriHostNameType = Uri.CheckHostName(uri.Host);
- if (uriHostNameType == UriHostNameType.IPv4 || uriHostNameType == UriHostNameType.IPv6)
+ if (uriHostNameType is UriHostNameType.IPv4 or UriHostNameType.IPv6)
{
activity.SetTag(SemanticConventions.AttributeNetPeerIp, uri.Host);
}
@@ -269,14 +266,10 @@ private void OnStopActivity(Activity activity, object? payload)
if (originalException is HttpRequestException)
{
- if (originalException.InnerException is SocketException exception)
+ if (originalException.InnerException is SocketException { SocketErrorCode: SocketError.HostNotFound })
{
- switch (exception.SocketErrorCode)
- {
- case SocketError.HostNotFound:
- activity.SetStatus(Status.Error.WithDescription(originalException.Message));
- return;
- }
+ activity.SetStatus(Status.Error.WithDescription(originalException.Message));
+ return;
}
if (originalException.InnerException != null)
diff --git a/src/OpenTelemetry.Instrumentation.EventCounters/EventCountersInstrumentationOptions.cs b/src/OpenTelemetry.Instrumentation.EventCounters/EventCountersInstrumentationOptions.cs
index 7fdc25d72b..8e4df4cc81 100644
--- a/src/OpenTelemetry.Instrumentation.EventCounters/EventCountersInstrumentationOptions.cs
+++ b/src/OpenTelemetry.Instrumentation.EventCounters/EventCountersInstrumentationOptions.cs
@@ -8,7 +8,7 @@ namespace OpenTelemetry.Instrumentation.EventCounters;
///
public class EventCountersInstrumentationOptions
{
- internal readonly HashSet EventSourceNames = new();
+ internal readonly HashSet EventSourceNames = [];
///
/// Gets or sets the subscription interval in seconds for reading values
diff --git a/src/OpenTelemetry.Instrumentation.EventCounters/EventCountersMetrics.cs b/src/OpenTelemetry.Instrumentation.EventCounters/EventCountersMetrics.cs
index 8b42388883..4cb8444f76 100644
--- a/src/OpenTelemetry.Instrumentation.EventCounters/EventCountersMetrics.cs
+++ b/src/OpenTelemetry.Instrumentation.EventCounters/EventCountersMetrics.cs
@@ -18,8 +18,8 @@ internal sealed class EventCountersMetrics : EventListener
private const int MaxInstrumentNameLength = 63;
private readonly EventCountersInstrumentationOptions options;
- private readonly List preInitEventSources = new();
- private readonly List enabledEventSources = new();
+ private readonly List preInitEventSources = [];
+ private readonly List enabledEventSources = [];
private readonly ConcurrentDictionary<(string, string), Instrument> instruments = new();
private readonly ConcurrentDictionary<(string, string), double> values = new();
private bool isDisposed;
@@ -45,7 +45,7 @@ public EventCountersMetrics(EventCountersInstrumentationOptions options)
{
this.options = options;
- foreach (EventSource eventSource in this.preInitEventSources)
+ foreach (var eventSource in this.preInitEventSources)
{
if (this.options.ShouldListenToSource(eventSource.Name))
{
@@ -167,7 +167,7 @@ private static Dictionary GetEnableEventsArguments(EventCounters
///
private static string GetInstrumentName(string sourceName, string eventName)
{
- int totalLength = Prefix.Length + 1 + sourceName.Length + 1 + eventName.Length;
+ var totalLength = Prefix.Length + 1 + sourceName.Length + 1 + eventName.Length;
if (totalLength <= MaxInstrumentNameLength)
{
return string.Concat(Prefix, ".", sourceName, ".", eventName);
diff --git a/src/OpenTelemetry.Instrumentation.Hangfire/Implementation/HangfireInstrumentationJobFilterAttribute.cs b/src/OpenTelemetry.Instrumentation.Hangfire/Implementation/HangfireInstrumentationJobFilterAttribute.cs
index f793e52a62..0f0afaaa2a 100644
--- a/src/OpenTelemetry.Instrumentation.Hangfire/Implementation/HangfireInstrumentationJobFilterAttribute.cs
+++ b/src/OpenTelemetry.Instrumentation.Hangfire/Implementation/HangfireInstrumentationJobFilterAttribute.cs
@@ -122,7 +122,7 @@ private static void InjectActivityProperties(IDictionary jobPara
private static IEnumerable ExtractActivityProperties(Dictionary telemetryData, string key)
{
- return telemetryData.TryGetValue(key, out var value) ? new[] { value } : Enumerable.Empty();
+ return telemetryData.TryGetValue(key, out var value) ? [value] : [];
}
private void SetStatusAndRecordException(Activity activity, Exception exception)
diff --git a/src/OpenTelemetry.Instrumentation.Http/HttpClientInstrumentation.cs b/src/OpenTelemetry.Instrumentation.Http/HttpClientInstrumentation.cs
index 40daae9660..4400a15f5b 100644
--- a/src/OpenTelemetry.Instrumentation.Http/HttpClientInstrumentation.cs
+++ b/src/OpenTelemetry.Instrumentation.Http/HttpClientInstrumentation.cs
@@ -10,18 +10,18 @@ namespace OpenTelemetry.Instrumentation.Http;
///
internal sealed class HttpClientInstrumentation : IDisposable
{
- private static readonly HashSet ExcludedDiagnosticSourceEventsNet7OrGreater = new()
- {
+ private static readonly HashSet ExcludedDiagnosticSourceEventsNet7OrGreater =
+ [
"System.Net.Http.Request",
"System.Net.Http.Response",
- "System.Net.Http.HttpRequestOut",
- };
+ "System.Net.Http.HttpRequestOut"
+ ];
- private static readonly HashSet ExcludedDiagnosticSourceEvents = new()
- {
+ private static readonly HashSet ExcludedDiagnosticSourceEvents =
+ [
"System.Net.Http.Request",
- "System.Net.Http.Response",
- };
+ "System.Net.Http.Response"
+ ];
private readonly DiagnosticSourceSubscriber diagnosticSourceSubscriber;
@@ -43,14 +43,9 @@ public HttpClientInstrumentation(HttpClientTraceInstrumentationOptions options)
// the framework will fall back to creating activity anyways due to active diagnostic source listener
// To prevent this, isEnabled is implemented which will return false always
// so that the sampler's decision is respected.
- if (HttpHandlerDiagnosticListener.IsNet7OrGreater)
- {
- this.diagnosticSourceSubscriber = new DiagnosticSourceSubscriber(new HttpHandlerDiagnosticListener(options), this.isEnabledNet7OrGreater, HttpInstrumentationEventSource.Log.UnknownErrorProcessingEvent);
- }
- else
- {
- this.diagnosticSourceSubscriber = new DiagnosticSourceSubscriber(new HttpHandlerDiagnosticListener(options), this.isEnabled, HttpInstrumentationEventSource.Log.UnknownErrorProcessingEvent);
- }
+ this.diagnosticSourceSubscriber = HttpHandlerDiagnosticListener.IsNet7OrGreater
+ ? new DiagnosticSourceSubscriber(new HttpHandlerDiagnosticListener(options), this.isEnabledNet7OrGreater, HttpInstrumentationEventSource.Log.UnknownErrorProcessingEvent)
+ : new DiagnosticSourceSubscriber(new HttpHandlerDiagnosticListener(options), this.isEnabled, HttpInstrumentationEventSource.Log.UnknownErrorProcessingEvent);
this.diagnosticSourceSubscriber.Subscribe();
}
diff --git a/src/OpenTelemetry.Instrumentation.Http/HttpClientMetrics.cs b/src/OpenTelemetry.Instrumentation.Http/HttpClientMetrics.cs
index e03cd6a46a..8913f8daf7 100644
--- a/src/OpenTelemetry.Instrumentation.Http/HttpClientMetrics.cs
+++ b/src/OpenTelemetry.Instrumentation.Http/HttpClientMetrics.cs
@@ -10,11 +10,11 @@ namespace OpenTelemetry.Instrumentation.Http;
///
internal sealed class HttpClientMetrics : IDisposable
{
- private static readonly HashSet ExcludedDiagnosticSourceEvents = new()
- {
+ private static readonly HashSet ExcludedDiagnosticSourceEvents =
+ [
"System.Net.Http.Request",
- "System.Net.Http.Response",
- };
+ "System.Net.Http.Response"
+ ];
private readonly DiagnosticSourceSubscriber diagnosticSourceSubscriber;
diff --git a/src/OpenTelemetry.Instrumentation.Http/HttpClientTraceInstrumentationOptions.cs b/src/OpenTelemetry.Instrumentation.Http/HttpClientTraceInstrumentationOptions.cs
index e63f77bae3..cba754cc9f 100644
--- a/src/OpenTelemetry.Instrumentation.Http/HttpClientTraceInstrumentationOptions.cs
+++ b/src/OpenTelemetry.Instrumentation.Http/HttpClientTraceInstrumentationOptions.cs
@@ -165,7 +165,7 @@ internal bool EventFilterHttpRequestMessage(string activityName, object arg1)
{
return
this.FilterHttpRequestMessage == null ||
- !TryParseHttpRequestMessage(activityName, arg1, out HttpRequestMessage? requestMessage) ||
+ !TryParseHttpRequestMessage(activityName, arg1, out var requestMessage) ||
this.FilterHttpRequestMessage(requestMessage);
}
catch (Exception ex)
diff --git a/src/OpenTelemetry.Instrumentation.Http/Implementation/HttpHandlerDiagnosticListener.cs b/src/OpenTelemetry.Instrumentation.Http/Implementation/HttpHandlerDiagnosticListener.cs
index 14e2ebbec7..5b65c673d0 100644
--- a/src/OpenTelemetry.Instrumentation.Http/Implementation/HttpHandlerDiagnosticListener.cs
+++ b/src/OpenTelemetry.Instrumentation.Http/Implementation/HttpHandlerDiagnosticListener.cs
@@ -65,6 +65,8 @@ public override void OnEventWritten(string name, object? payload)
this.OnException(activity, payload);
}
+ break;
+ default:
break;
}
}
@@ -81,7 +83,7 @@ public void OnStartActivity(Activity activity, object? payload)
// By this time, samplers have already run and
// activity.IsAllDataRequested populated accordingly.
- if (!TryFetchRequest(payload, out HttpRequestMessage? request))
+ if (!TryFetchRequest(payload, out var request))
{
HttpInstrumentationEventSource.Log.NullPayload(nameof(HttpHandlerDiagnosticListener), nameof(this.OnStartActivity));
return;
@@ -109,7 +111,7 @@ public void OnStartActivity(Activity activity, object? payload)
{
try
{
- if (this.options.EventFilterHttpRequestMessage(activity.OperationName, request) == false)
+ if (!this.options.EventFilterHttpRequestMessage(activity.OperationName, request))
{
HttpInstrumentationEventSource.Log.RequestIsFilteredOut(activity.OperationName);
activity.IsAllDataRequested = false;
@@ -161,12 +163,7 @@ public void OnStartActivity(Activity activity, object? payload)
#endif
static bool TryFetchRequest(object? payload, [NotNullWhen(true)] out HttpRequestMessage? request)
{
- if (!StartRequestFetcher.TryFetch(payload, out request) || request == null)
- {
- return false;
- }
-
- return true;
+ return StartRequestFetcher.TryFetch(payload, out request) && request != null;
}
}
@@ -176,7 +173,7 @@ public void OnStopActivity(Activity activity, object? payload)
{
var requestTaskStatus = GetRequestStatus(payload);
- ActivityStatusCode currentStatusCode = activity.Status;
+ var currentStatusCode = activity.Status;
if (requestTaskStatus != TaskStatus.RanToCompletion)
{
if (requestTaskStatus == TaskStatus.Canceled)
@@ -200,7 +197,7 @@ public void OnStopActivity(Activity activity, object? payload)
}
}
- if (TryFetchResponse(payload, out HttpResponseMessage? response))
+ if (TryFetchResponse(payload, out var response))
{
if (currentStatusCode == ActivityStatusCode.Unset)
{
@@ -246,12 +243,7 @@ static TaskStatus GetRequestStatus(object? payload)
#endif
static bool TryFetchResponse(object? payload, [NotNullWhen(true)] out HttpResponseMessage? response)
{
- if (StopResponseFetcher.TryFetch(payload, out response) && response != null)
- {
- return true;
- }
-
- return false;
+ return StopResponseFetcher.TryFetch(payload, out response) && response != null;
}
}
@@ -259,7 +251,7 @@ public void OnException(Activity activity, object? payload)
{
if (activity.IsAllDataRequested)
{
- if (!TryFetchException(payload, out Exception? exc))
+ if (!TryFetchException(payload, out var exc))
{
HttpInstrumentationEventSource.Log.NullPayload(nameof(HttpHandlerDiagnosticListener), nameof(this.OnException));
return;
@@ -299,12 +291,7 @@ public void OnException(Activity activity, object? payload)
#endif
static bool TryFetchException(object? payload, [NotNullWhen(true)] out Exception? exc)
{
- if (!StopExceptionFetcher.TryFetch(payload, out exc) || exc == null)
- {
- return false;
- }
-
- return true;
+ return StopExceptionFetcher.TryFetch(payload, out exc) && exc != null;
}
}
diff --git a/src/OpenTelemetry.Instrumentation.Http/Implementation/HttpHandlerMetricsDiagnosticListener.cs b/src/OpenTelemetry.Instrumentation.Http/Implementation/HttpHandlerMetricsDiagnosticListener.cs
index 7a841bf654..dd3dc6970c 100644
--- a/src/OpenTelemetry.Instrumentation.Http/Implementation/HttpHandlerMetricsDiagnosticListener.cs
+++ b/src/OpenTelemetry.Instrumentation.Http/Implementation/HttpHandlerMetricsDiagnosticListener.cs
@@ -39,7 +39,7 @@ public HttpHandlerMetricsDiagnosticListener(string name)
public static void OnStopEventWritten(Activity activity, object? payload)
{
- if (TryFetchRequest(payload, out HttpRequestMessage? request))
+ if (TryFetchRequest(payload, out var request))
{
// see the spec https://github.com/open-telemetry/semantic-conventions/blob/v1.23.0/docs/http/http-metrics.md
TagList tags = default;
@@ -58,7 +58,7 @@ public static void OnStopEventWritten(Activity activity, object? payload)
}
}
- if (TryFetchResponse(payload, out HttpResponseMessage? response))
+ if (TryFetchResponse(payload, out var response))
{
tags.Add(new KeyValuePair(SemanticConventions.AttributeNetworkProtocolVersion, RequestDataHelper.GetHttpProtocolVersion(response.Version)));
tags.Add(new KeyValuePair(SemanticConventions.AttributeHttpResponseStatusCode, TelemetryHelper.GetBoxedStatusCode(response.StatusCode)));
@@ -98,21 +98,25 @@ public static void OnStopEventWritten(Activity activity, object? payload)
#if NET
[UnconditionalSuppressMessage("Trimming", "IL2026", Justification = "The System.Net.Http library guarantees that top-level properties are preserved")]
#endif
- static bool TryFetchRequest(object? payload, [NotNullWhen(true)] out HttpRequestMessage? request) =>
- StopRequestFetcher.TryFetch(payload, out request) && request != null;
+ static bool TryFetchRequest(object? payload, [NotNullWhen(true)] out HttpRequestMessage? request)
+ {
+ return StopRequestFetcher.TryFetch(payload, out request) && request != null;
+ }
// The AOT-annotation DynamicallyAccessedMembers in System.Net.Http library ensures that top-level properties on the payload object are always preserved.
// see https://github.com/dotnet/runtime/blob/f9246538e3d49b90b0e9128d7b1defef57cd6911/src/libraries/System.Net.Http/src/System/Net/Http/DiagnosticsHandler.cs#L325
#if NET
[UnconditionalSuppressMessage("Trimming", "IL2026", Justification = "The System.Net.Http library guarantees that top-level properties are preserved")]
#endif
- static bool TryFetchResponse(object? payload, [NotNullWhen(true)] out HttpResponseMessage? response) =>
- StopResponseFetcher.TryFetch(payload, out response) && response != null;
+ static bool TryFetchResponse(object? payload, [NotNullWhen(true)] out HttpResponseMessage? response)
+ {
+ return StopResponseFetcher.TryFetch(payload, out response) && response != null;
+ }
}
public static void OnExceptionEventWritten(Activity activity, object? payload)
{
- if (!TryFetchException(payload, out Exception? exc) || !TryFetchRequest(payload, out HttpRequestMessage? request))
+ if (!TryFetchException(payload, out var exc) || !TryFetchRequest(payload, out var request))
{
HttpInstrumentationEventSource.Log.NullPayload(nameof(HttpHandlerMetricsDiagnosticListener), nameof(OnExceptionEventWritten));
return;
@@ -131,12 +135,7 @@ public static void OnExceptionEventWritten(Activity activity, object? payload)
#endif
static bool TryFetchException(object? payload, [NotNullWhen(true)] out Exception? exc)
{
- if (!StopExceptionFetcher.TryFetch(payload, out exc) || exc == null)
- {
- return false;
- }
-
- return true;
+ return StopExceptionFetcher.TryFetch(payload, out exc) && exc != null;
}
// The AOT-annotation DynamicallyAccessedMembers in System.Net.Http library ensures that top-level properties on the payload object are always preserved.
@@ -146,12 +145,7 @@ static bool TryFetchException(object? payload, [NotNullWhen(true)] out Exception
#endif
static bool TryFetchRequest(object? payload, [NotNullWhen(true)] out HttpRequestMessage? request)
{
- if (!RequestFetcher.TryFetch(payload, out request) || request == null)
- {
- return false;
- }
-
- return true;
+ return RequestFetcher.TryFetch(payload, out request) && request != null;
}
}
diff --git a/src/OpenTelemetry.Instrumentation.Http/Implementation/HttpWebRequestActivitySource.netfx.cs b/src/OpenTelemetry.Instrumentation.Http/Implementation/HttpWebRequestActivitySource.netfx.cs
index c99639639d..7f8ba01066 100644
--- a/src/OpenTelemetry.Instrumentation.Http/Implementation/HttpWebRequestActivitySource.netfx.cs
+++ b/src/OpenTelemetry.Instrumentation.Http/Implementation/HttpWebRequestActivitySource.netfx.cs
@@ -40,8 +40,6 @@ internal static class HttpWebRequestActivitySource
private static readonly Meter WebRequestMeter = new(MeterName, Version);
private static readonly Histogram HttpClientRequestDuration = WebRequestMeter.CreateHistogram("http.client.request.duration", "s", "Duration of HTTP client requests.");
- private static HttpClientTraceInstrumentationOptions tracingOptions;
-
// Fields for reflection
private static FieldInfo connectionGroupListField;
private static Type connectionGroupType;
@@ -86,14 +84,7 @@ static HttpWebRequestActivitySource()
}
}
- internal static HttpClientTraceInstrumentationOptions TracingOptions
- {
- get => tracingOptions;
- set
- {
- tracingOptions = value;
- }
- }
+ internal static HttpClientTraceInstrumentationOptions TracingOptions { get; set; }
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static void AddRequestTagsAndInstrumentRequest(HttpWebRequest request, Activity activity)
@@ -108,7 +99,7 @@ private static void AddRequestTagsAndInstrumentRequest(HttpWebRequest request, A
activity.SetTag(SemanticConventions.AttributeServerAddress, request.RequestUri.Host);
activity.SetTag(SemanticConventions.AttributeServerPort, request.RequestUri.Port);
- activity.SetTag(SemanticConventions.AttributeUrlFull, HttpTagHelper.GetUriTagValueFromRequestUri(request.RequestUri, tracingOptions.DisableUrlQueryRedaction));
+ activity.SetTag(SemanticConventions.AttributeUrlFull, HttpTagHelper.GetUriTagValueFromRequestUri(request.RequestUri, TracingOptions.DisableUrlQueryRedaction));
try
{
@@ -232,7 +223,7 @@ private static void ProcessRequest(HttpWebRequest request)
return;
}
- Activity activity = enableTracing
+ var activity = enableTracing
? WebRequestActivitySource.StartActivity(ActivityName, ActivityKind.Client)
: null;
@@ -243,12 +234,12 @@ private static void ProcessRequest(HttpWebRequest request)
// Eg: Parent could be the Asp.Net activity.
InstrumentRequest(request, activityContext);
- IAsyncResult asyncContext = writeAResultAccessor(request);
+ var asyncContext = writeAResultAccessor(request);
if (asyncContext != null)
{
// Flow here is for [Begin]GetRequestStream[Async].
- AsyncCallbackWrapper callback = new AsyncCallbackWrapper(request, activity, asyncCallbackAccessor(asyncContext), Stopwatch.GetTimestamp());
+ var callback = new AsyncCallbackWrapper(request, activity, asyncCallbackAccessor(asyncContext), Stopwatch.GetTimestamp());
asyncCallbackModifier(asyncContext, callback.AsyncCallback);
}
else
@@ -256,7 +247,7 @@ private static void ProcessRequest(HttpWebRequest request)
// Flow here is for [Begin]GetResponse[Async] without a prior call to [Begin]GetRequestStream[Async].
asyncContext = readAResultAccessor(request);
- AsyncCallbackWrapper callback = new AsyncCallbackWrapper(request, activity, asyncCallbackAccessor(asyncContext), Stopwatch.GetTimestamp());
+ var callback = new AsyncCallbackWrapper(request, activity, asyncCallbackAccessor(asyncContext), Stopwatch.GetTimestamp());
asyncCallbackModifier(asyncContext, callback.AsyncCallback);
}
@@ -268,7 +259,7 @@ private static void ProcessRequest(HttpWebRequest request)
private static void HookOrProcessResult(HttpWebRequest request)
{
- IAsyncResult writeAsyncContext = writeAResultAccessor(request);
+ var writeAsyncContext = writeAResultAccessor(request);
if (writeAsyncContext == null || asyncCallbackAccessor(writeAsyncContext)?.Target is not AsyncCallbackWrapper writeAsyncContextCallback)
{
// If we already hooked into the read result during ProcessRequest or we hooked up after the fact already we don't need to do anything here.
@@ -277,7 +268,7 @@ private static void HookOrProcessResult(HttpWebRequest request)
// If we got here it means the user called [Begin]GetRequestStream[Async] and we have to hook the read result after the fact.
- IAsyncResult readAsyncContext = readAResultAccessor(request);
+ var readAsyncContext = readAResultAccessor(request);
if (readAsyncContext == null)
{
// We're still trying to establish the connection (no read has started).
@@ -295,7 +286,7 @@ private static void HookOrProcessResult(HttpWebRequest request)
}
// Hook into the result callback if it hasn't already fired.
- AsyncCallbackWrapper callback = new AsyncCallbackWrapper(writeAsyncContextCallback.Request, writeAsyncContextCallback.Activity, asyncCallbackAccessor(readAsyncContext), Stopwatch.GetTimestamp());
+ var callback = new AsyncCallbackWrapper(writeAsyncContextCallback.Request, writeAsyncContextCallback.Activity, asyncCallbackAccessor(readAsyncContext), Stopwatch.GetTimestamp());
asyncCallbackModifier(readAsyncContext, callback.AsyncCallback);
}
@@ -304,7 +295,7 @@ private static void ProcessResult(IAsyncResult asyncResult, AsyncCallback asyncC
HttpStatusCode? httpStatusCode = null;
string errorType = null;
Version protocolVersion = null;
- ActivityStatusCode activityStatus = ActivityStatusCode.Unset;
+ var activityStatus = ActivityStatusCode.Unset;
// Activity may be null if we are not tracing in these cases:
// 1. No listeners
@@ -349,7 +340,7 @@ private static void ProcessResult(IAsyncResult asyncResult, AsyncCallback asyncC
}
else
{
- HttpWebResponse response = (HttpWebResponse)result;
+ var response = (HttpWebResponse)result;
if (forceResponseCopy || (asyncCallback == null && isContextAwareResultChecker(asyncResult)))
{
@@ -358,13 +349,12 @@ private static void ProcessResult(IAsyncResult asyncResult, AsyncCallback asyncC
// in which case they could dispose the HttpWebResponse before our listeners have a chance to work with it.
// Disposed HttpWebResponse throws when accessing properties, so let's make a copy of the data to ensure that doesn't happen.
- HttpWebResponse responseCopy = httpWebResponseCtor(
- new object[]
- {
- uriAccessor(response), verbAccessor(response), coreResponseDataAccessor(response), mediaTypeAccessor(response),
+ var responseCopy = httpWebResponseCtor(
+ [
+ uriAccessor(response), verbAccessor(response), coreResponseDataAccessor(response), mediaTypeAccessor(response),
usesProxySemanticsAccessor(response), DecompressionMethods.None,
- isWebSocketResponseAccessor(response), connectionGroupNameAccessor(response),
- });
+ isWebSocketResponseAccessor(response), connectionGroupNameAccessor(response)
+ ]);
if (activity != null)
{
@@ -458,8 +448,8 @@ private static void PrepareReflectionObjects()
{
// At any point, if the operation failed, it should just throw. The caller should catch all exceptions and swallow.
- Type servicePointType = typeof(ServicePoint);
- Assembly systemNetHttpAssembly = servicePointType.Assembly;
+ var servicePointType = typeof(ServicePoint);
+ var systemNetHttpAssembly = servicePointType.Assembly;
connectionGroupListField = servicePointType.GetField("m_ConnectionGroupList", BindingFlags.Instance | BindingFlags.NonPublic);
connectionGroupType = systemNetHttpAssembly?.GetType("System.Net.ConnectionGroup");
connectionListField = connectionGroupType?.GetField("m_ConnectionList", BindingFlags.Instance | BindingFlags.NonPublic);
@@ -489,7 +479,7 @@ private static void PrepareReflectionObjects()
private static bool PrepareAsyncResultReflectionObjects(Assembly systemNetHttpAssembly)
{
- Type lazyAsyncResultType = systemNetHttpAssembly?.GetType("System.Net.LazyAsyncResult");
+ var lazyAsyncResultType = systemNetHttpAssembly?.GetType("System.Net.LazyAsyncResult");
if (lazyAsyncResultType != null)
{
asyncCallbackAccessor = CreateFieldGetter(lazyAsyncResultType, "m_AsyncCallback", BindingFlags.NonPublic | BindingFlags.Instance);
@@ -500,7 +490,7 @@ private static bool PrepareAsyncResultReflectionObjects(Assembly systemNetHttpAs
resultAccessor = CreateFieldGetter