Skip to content

Commit

Permalink
Enable the HttpSocketsHandler behind opt-in flag (#709)
Browse files Browse the repository at this point in the history
Enable the HttpSocketsHandler integration only when `DD_HttpSocketsHandler_ENABLED=true`. Enable this in the CI test as well.
  • Loading branch information
zacharycmontoya authored Apr 17, 2020
1 parent 98343ae commit ba9bced
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"CORECLR_PROFILER": "{846F5F1C-F9AE-4B07-969E-05C26BC060D8}",
"CORECLR_PROFILER_PATH": "$(ProjectDir)$(OutputPath)profiler-lib\\Datadog.Trace.ClrProfiler.Native.dll",

"DD_HttpSocketsHandler_ENABLED": "true",
"DD_DOTNET_TRACER_HOME": "$(ProjectDir)$(OutputPath)profiler-lib",
"DD_INTEGRATIONS": "$(ProjectDir)$(OutputPath)profiler-lib\\integrations.json"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ private static async Task<HttpResponseMessage> SendAsyncInternal(
HttpRequestMessage request,
CancellationToken cancellationToken)
{
if (!(handler is HttpClientHandler || reportedType.FullName.Equals("System.Net.Http.SocketsHttpHandler", StringComparison.OrdinalIgnoreCase)) ||
if (!(handler is HttpClientHandler || IsSocketsHttpHandlerEnabled(reportedType)) ||
!IsTracingEnabled(request))
{
// skip instrumentation
Expand Down Expand Up @@ -205,6 +205,11 @@ private static async Task<HttpResponseMessage> SendAsyncInternal(
}
}

private static bool IsSocketsHttpHandlerEnabled(Type reportedType)
{
return Tracer.Instance.Settings.IsOptInIntegrationEnabled("HttpSocketsHandler") && reportedType.FullName.Equals("System.Net.Http.SocketsHttpHandler", StringComparison.OrdinalIgnoreCase);
}

private static bool IsTracingEnabled(HttpRequestMessage request)
{
if (request.Headers.TryGetValues(HttpHeaderNames.TracingEnabled, out var headerValues))
Expand Down
6 changes: 6 additions & 0 deletions src/Datadog.Trace/Configuration/TracerSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,12 @@ internal bool IsIntegrationEnabled(string name)
return TraceEnabled && !disabled;
}

internal bool IsOptInIntegrationEnabled(string name)
{
bool disabled = Integrations[name].Enabled != true || DisabledIntegrationNames.Contains(name);
return TraceEnabled && !disabled;
}

internal double? GetIntegrationAnalyticsSampleRate(string name, bool enabledWithGlobalSetting)
{
var integrationSettings = Integrations[name];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public HttpClientTests(ITestOutputHelper output)
: base("HttpMessageHandler", output)
{
SetEnvironmentVariable("DD_TRACE_DOMAIN_NEUTRAL_INSTRUMENTATION", "true");
SetEnvironmentVariable("DD_HttpSocketsHandler_ENABLED", "true");
}

[Fact]
Expand Down

0 comments on commit ba9bced

Please sign in to comment.