Skip to content

Commit c068213

Browse files
vandonrandrewlock
andauthored
Add process tags to client-side stats (#7791)
## Summary of changes adding process tags at the ClientStatsPayload level. See [proto](https://github.com/DataDog/datadog-agent/blob/main/pkg/proto/datadog/trace/stats.proto#L52-L55) in the agent ## Reason for change AIDM-195 ## Implementation details ## Test coverage piggybacked on existing tests ## Other details I realized that dotnet doesn't write the service name at the top level, but only in the buckets. Doesn't seem to be a big issue, but there could be a win here by writing the service in the buckets only when there is an override. <!-- ⚠️ Note: Where possible, please obtain 2 approvals prior to merging. Unless CODEOWNERS specifies otherwise, for external teams it is typically best to have one review from a team member, and one review from apm-dotnet. Trivial changes do not require 2 reviews. MergeQueue is NOT enabled in this repository. If you have write access to the repo, the PR has 1-2 approvals (see above), and all of the required checks have passed, you can use the Squash and Merge button to merge the PR. If you don't have write access, or you need help, reach out in the #apm-dotnet channel in Slack. --> --------- Co-authored-by: Andrew Lock <[email protected]>
1 parent d709346 commit c068213

File tree

6 files changed

+31
-6
lines changed

6 files changed

+31
-6
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ internal class ClientStatsPayload
1717

1818
public string Version { get; set; }
1919

20+
public string ProcessTags { get; set; }
21+
2022
public long GetSequenceNumber() => Interlocked.Increment(ref _sequence);
2123
}
2224
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@ internal StatsAggregator(IApi api, TracerSettings settings, IDiscoveryService di
6767
{
6868
Environment = settings.Environment,
6969
Version = settings.ServiceVersion,
70-
HostName = HostMetadata.Instance.Hostname
70+
HostName = HostMetadata.Instance.Hostname,
71+
ProcessTags = settings.PropagateProcessTags ? ProcessTags.SerializedTags : null
7172
};
7273

7374
for (int i = 0; i < _buffers.Length; i++)

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,13 @@ public void Reset()
5959

6060
public void Serialize(Stream stream, long bucketDuration)
6161
{
62-
MessagePackBinary.WriteMapHeader(stream, 8);
62+
var count = 8;
63+
if (!string.IsNullOrEmpty(_header.ProcessTags))
64+
{
65+
count++;
66+
}
67+
68+
MessagePackBinary.WriteMapHeader(stream, count);
6369

6470
MessagePackBinary.WriteString(stream, "Hostname");
6571
MessagePackBinary.WriteString(stream, _header.HostName ?? string.Empty);
@@ -70,6 +76,12 @@ public void Serialize(Stream stream, long bucketDuration)
7076
MessagePackBinary.WriteString(stream, "Version");
7177
MessagePackBinary.WriteString(stream, _header.Version ?? string.Empty);
7278

79+
if (!string.IsNullOrEmpty(_header.ProcessTags))
80+
{
81+
MessagePackBinary.WriteString(stream, "ProcessTags");
82+
MessagePackBinary.WriteString(stream, _header.ProcessTags);
83+
}
84+
7385
MessagePackBinary.WriteString(stream, "Stats");
7486
MessagePackBinary.WriteArrayHeader(stream, 1);
7587
SerializeBuckets(stream, bucketDuration);

tracer/test/Datadog.Trace.TestHelpers/Stats/MockClientStatsPayload.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ public class MockClientStatsPayload
2020
[Key("Version")]
2121
public string Version { get; set; }
2222

23+
[Key("ProcessTags")]
24+
public string ProcessTags { get; set; }
25+
2326
[Key("Lang")]
2427
public string Lang { get; set; }
2528

tracer/test/Datadog.Trace.Tests/Agent/ApiTests.cs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -165,9 +165,15 @@ public async Task SendStatsAsync_200OK_AllGood()
165165
factoryMock.Setup(x => x.GetEndpoint(It.Is<string>(s => s == TracesPath))).Returns(new Uri("http://localhost/traces"));
166166
factoryMock.Setup(x => x.GetEndpoint(It.Is<string>(s => s == StatsPath))).Returns(new Uri("http://localhost/stats"));
167167

168-
var api = new Api(apiRequestFactory: factoryMock.Object, statsd: null, updateSampleRates: null, partialFlushEnabled: false);
169-
170-
var statsBuffer = new StatsBuffer(new ClientStatsPayload());
168+
var api = new Api(factoryMock.Object, statsd: null, updateSampleRates: null, partialFlushEnabled: false);
169+
170+
var statsBuffer = new StatsBuffer(new ClientStatsPayload
171+
{
172+
Environment = "myEnv",
173+
HostName = "myHost",
174+
ProcessTags = "tag.a:b,tag.c:d",
175+
Version = "myVersion"
176+
});
171177

172178
await api.SendStatsAsync(statsBuffer, 1);
173179

tracer/test/Datadog.Trace.Tests/Agent/StatsBufferTests.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public void Serialization()
2929
{
3030
const long expectedDuration = 42;
3131

32-
var payload = new ClientStatsPayload { Environment = "Env", HostName = "Hostname", Version = "v99.99" };
32+
var payload = new ClientStatsPayload { Environment = "Env", HostName = "Hostname", Version = "v99.99", ProcessTags = "a.b:c_d,x.y:z" };
3333

3434
var buffer = new StatsBuffer(payload);
3535

@@ -52,6 +52,7 @@ public void Serialization()
5252
result.Hostname.Should().Be(payload.HostName);
5353
result.Env.Should().Be(payload.Environment);
5454
result.Version.Should().Be(payload.Version);
55+
result.ProcessTags.Should().Be(payload.ProcessTags);
5556
result.Lang.Should().Be(TracerConstants.Language);
5657
result.TracerVersion.Should().Be(TracerConstants.AssemblyVersion);
5758
result.RuntimeId.Should().Be(Tracer.RuntimeId);

0 commit comments

Comments
 (0)