-
Notifications
You must be signed in to change notification settings - Fork 145
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Tracing] Fix WebRequest bug with existing distributed tracing headers (
#4770) When we pre-emptively add distributed tracing headers in `WebRequest.BeginGetRequestStream`, `WebRequest.BeginGetResponse`, and `WebRequest.GetRequestStream`, add the headers to a cache to signal to the later integrations that we had last updated the headers and we are responsible for the distributed tracing headers in the WebRequest object. When we check for the pre-emptively added distributed tracing headers in `WebRequest.EndGetResponse`, `WebRequest.GetResponse` and `WebRequest.GetResponseAsync`, first check a cache to know whether we added distributed tracing headers to the WebRequest object. If present, then continue to use the injected trace context. Otherwise, we create a new context.
- Loading branch information
1 parent
00d32ab
commit 7124515
Showing
10 changed files
with
157 additions
and
10 deletions.
There are no files selected for viewing
31 changes: 31 additions & 0 deletions
31
...src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Http/WebRequest/HeadersInjectedCache.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// <copyright file="HeadersInjectedCache.cs" company="Datadog"> | ||
// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2 License. | ||
// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc. | ||
// </copyright> | ||
|
||
#nullable enable | ||
|
||
using System.Net; | ||
using System.Runtime.CompilerServices; | ||
|
||
namespace Datadog.Trace.ClrProfiler.AutoInstrumentation.Http.WebRequest; | ||
|
||
internal static class HeadersInjectedCache | ||
{ | ||
private static readonly object InjectedValue = new(); | ||
private static readonly ConditionalWeakTable<WebHeaderCollection, object> Cache = new(); | ||
|
||
public static void SetInjectedHeaders(WebHeaderCollection headers) | ||
{ | ||
#if NETCOREAPP3_1_OR_GREATER | ||
Cache.AddOrUpdate(headers, InjectedValue); | ||
#else | ||
Cache.GetValue(headers, _ => InjectedValue); | ||
#endif | ||
} | ||
|
||
public static bool TryGetInjectedHeaders(WebHeaderCollection headers) | ||
{ | ||
return Cache.TryGetValue(headers, out _); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters