Skip to content

Commit

Permalink
Remove w3c check HttpClient (#3235)
Browse files Browse the repository at this point in the history
* remove w3c check

* unnecessary usings
  • Loading branch information
vishweshbankwar authored Apr 28, 2022
1 parent 117b70c commit 0741a9d
Showing 1 changed file with 1 addition and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,9 @@

using System;
using System.Diagnostics;
using System.Globalization;
using System.Net.Http;
using System.Net.Sockets;
using System.Reflection;
using System.Runtime.Versioning;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using OpenTelemetry.Context.Propagation;
Expand All @@ -41,27 +39,11 @@ internal sealed class HttpHandlerDiagnosticListener : ListenerHandler
private readonly PropertyFetcher<HttpResponseMessage> stopResponseFetcher = new("Response");
private readonly PropertyFetcher<Exception> stopExceptionFetcher = new("Exception");
private readonly PropertyFetcher<TaskStatus> stopRequestStatusFetcher = new("RequestTaskStatus");
private readonly bool httpClientSupportsW3C;
private readonly HttpClientInstrumentationOptions options;

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;
}

Expand Down Expand Up @@ -98,7 +80,7 @@ public override void OnStartActivity(Activity activity, object payload)

// Propagate context irrespective of sampling decision
var textMapPropagator = Propagators.DefaultTextMapPropagator;
if (!(this.httpClientSupportsW3C && textMapPropagator is TraceContextPropagator))
if (textMapPropagator is not TraceContextPropagator)
{
textMapPropagator.Inject(new PropagationContext(activity.Context, Baggage.Current), request, HttpRequestMessageContextPropagation.HeaderValueSetter);
}
Expand Down

0 comments on commit 0741a9d

Please sign in to comment.