Skip to content

Commit c18fc65

Browse files
committed
add container ID header to MinimalAgentHeaderHelper
1 parent a5f3f8d commit c18fc65

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

tracer/src/Datadog.Trace/Agent/DiscoveryService/DiscoveryService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,7 @@ private static IApiRequestFactory CreateApiRequestFactory(ExporterSettings expor
415415
productName: "discovery",
416416
tcpTimeout: tcpTimeout,
417417
BuildHeaders(containerId),
418-
() => new MinimalAgentHeaderHelper(),
418+
() => new MinimalAgentHeaderHelper(containerId),
419419
uri => uri);
420420
}
421421
}

tracer/src/Datadog.Trace/HttpOverStreams/MinimalAgentHeaderHelper.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,13 @@ namespace Datadog.Trace.HttpOverStreams;
1111
internal class MinimalAgentHeaderHelper : HttpHeaderHelperBase
1212
{
1313
private static string? _metadataHeaders = null;
14+
private static string? _metadataHeadersWithContainerId = null;
15+
private readonly string? _containerId;
16+
17+
public MinimalAgentHeaderHelper(string? containerId = null)
18+
{
19+
_containerId = containerId;
20+
}
1421

1522
protected override string MetadataHeaders
1623
{
@@ -22,6 +29,18 @@ protected override string MetadataHeaders
2229
_metadataHeaders = string.Concat(headers);
2330
}
2431

32+
if (_containerId != null)
33+
{
34+
if (_metadataHeadersWithContainerId == null)
35+
{
36+
// Assuming we'd always get the same container ID. The first time, we use its value to build the header,
37+
// then it's just a marker that we want the header with the containerID in it, and we don't look at its value.
38+
_metadataHeadersWithContainerId = _metadataHeaders + $"{AgentHttpHeaderNames.ContainerId}: {_containerId}{DatadogHttpValues.CrLf}";
39+
}
40+
41+
return _metadataHeadersWithContainerId;
42+
}
43+
2544
return _metadataHeaders;
2645
}
2746
}

0 commit comments

Comments
 (0)