-
Notifications
You must be signed in to change notification settings - Fork 151
Add process tags to DSM #7775
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add process tags to DSM #7775
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,6 +22,7 @@ internal class DataStreamsMessagePackFormatter | |
| private readonly byte[] _serviceBytes = StringEncoding.UTF8.GetBytes("Service"); | ||
| private readonly long _productMask; | ||
| private readonly bool _isInDefaultState; | ||
| private readonly bool _writeProcessTags; | ||
|
|
||
| private readonly byte[] _serviceValueBytes; | ||
|
|
||
|
|
@@ -50,6 +51,7 @@ internal class DataStreamsMessagePackFormatter | |
| private readonly byte[] _backlogTagsBytes = StringEncoding.UTF8.GetBytes("Tags"); | ||
| private readonly byte[] _backlogValueBytes = StringEncoding.UTF8.GetBytes("Value"); | ||
| private readonly byte[] _productMaskBytes = StringEncoding.UTF8.GetBytes("ProductMask"); | ||
| private readonly byte[] _processTagsBytes = StringEncoding.UTF8.GetBytes("ProcessTags"); | ||
| private readonly byte[] _isInDefaultStateBytes = StringEncoding.UTF8.GetBytes("IsInDefaultState"); | ||
|
|
||
| public DataStreamsMessagePackFormatter(TracerSettings tracerSettings, ProfilerSettings profilerSettings, string defaultServiceName) | ||
|
|
@@ -63,6 +65,7 @@ public DataStreamsMessagePackFormatter(TracerSettings tracerSettings, ProfilerSe | |
| _serviceValueBytes = StringEncoding.UTF8.GetBytes(defaultServiceName); | ||
| _productMask = GetProductsMask(tracerSettings, profilerSettings); | ||
| _isInDefaultState = tracerSettings.IsDataStreamsMonitoringInDefaultState; | ||
| _writeProcessTags = tracerSettings.PropagateProcessTags; | ||
| } | ||
|
|
||
| // should be the same across all languages | ||
|
|
@@ -94,13 +97,14 @@ private static long GetProductsMask(TracerSettings tracerSettings, ProfilerSetti | |
|
|
||
| public int Serialize(Stream stream, long bucketDurationNs, List<SerializableStatsBucket> statsBuckets, List<SerializableBacklogBucket> backlogsBuckets) | ||
| { | ||
| var withProcessTags = _writeProcessTags && !string.IsNullOrEmpty(ProcessTags.SerializedTags); | ||
| var bytesWritten = 0; | ||
|
|
||
| // Should be in sync with Java | ||
| // https://github.com/DataDog/dd-trace-java/blob/a4b7a7b177709e6bdfd9261904cb9a777e4febbe/dd-trace-core/src/main/java/datadog/trace/core/datastreams/MsgPackDatastreamsPayloadWriter.java#L35 | ||
| // https://github.com/DataDog/dd-trace-java/blob/master/dd-trace-core/src/main/java/datadog/trace/core/datastreams/MsgPackDatastreamsPayloadWriter.java | ||
| // -1 because we don't have a primary tag | ||
| // -1 because service name override is not supported | ||
| bytesWritten += MessagePackBinary.WriteMapHeader(stream, 7); | ||
| bytesWritten += MessagePackBinary.WriteMapHeader(stream, 7 + (withProcessTags ? 1 : 0)); | ||
|
|
||
| bytesWritten += MessagePackBinary.WriteStringBytes(stream, _environmentBytes); | ||
| bytesWritten += MessagePackBinary.WriteStringBytes(stream, _environmentValueBytes); | ||
|
|
@@ -194,6 +198,12 @@ public int Serialize(Stream stream, long bucketDurationNs, List<SerializableStat | |
| bytesWritten += MessagePackBinary.WriteStringBytes(stream, _productMaskBytes); | ||
| bytesWritten += MessagePackBinary.WriteInt64(stream, _productMask); | ||
|
|
||
| if (withProcessTags) | ||
| { | ||
| bytesWritten += MessagePackBinary.WriteStringBytes(stream, _processTagsBytes); | ||
| bytesWritten += MessagePackBinary.WriteString(stream, ProcessTags.SerializedTags); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: not a fan of the fact that these are static globals, global state is the enemy of testing. Could/should we just pass it in as a parameter?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. hmm yes we can, but at some point we'd query them from the static global anyway. I don't know what would be the alternative for something that's supposed to be a singleton.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's probably not a big deal here, but there's a "correct" answer:
The answer is to only have a thin global static at the "outside" of the app. Everything else uses dependency inversion to inject the values in. Makes everything inherently testable, and removes the implicit dependencies between components you get otherwise. |
||
| } | ||
|
|
||
| bytesWritten += MessagePackBinary.WriteStringBytes(stream, _isInDefaultStateBytes); | ||
| bytesWritten += MessagePackBinary.WriteBoolean(stream, _isInDefaultState); | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -36,10 +36,11 @@ public DataStreamsManager( | |
| string? env, | ||
| string defaultServiceName, | ||
| IDataStreamsWriter? writer, | ||
| bool isInDefaultState) | ||
| bool isInDefaultState, | ||
| string? processTags) | ||
| { | ||
| // We don't yet support primary tag in .NET yet | ||
| _nodeHashBase = HashHelper.CalculateNodeHashBase(defaultServiceName, env, primaryTag: null); | ||
| // We don't support primary tag in .NET yet | ||
| _nodeHashBase = HashHelper.CalculateNodeHashBase(defaultServiceName, env, primaryTag: null, processTags); | ||
| _isEnabled = writer is not null; | ||
| _writer = writer; | ||
| _isInDefaultState = isInDefaultState; | ||
|
|
@@ -59,7 +60,7 @@ public static DataStreamsManager Create( | |
| ? DataStreamsWriter.Create(settings, profilerSettings, discoveryService, defaultServiceName) | ||
| : null; | ||
|
|
||
| return new DataStreamsManager(settings.Environment, defaultServiceName, writer, settings.IsDataStreamsMonitoringInDefaultState); | ||
| return new DataStreamsManager(settings.Environment, defaultServiceName, writer, settings.IsDataStreamsMonitoringInDefaultState, settings.PropagateProcessTags ? ProcessTags.SerializedTags : null); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This calls |
||
| } | ||
|
|
||
| public async Task DisposeAsync() | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: don't use
masterfor github links, because they break 😅There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah hmm well, yes they do if the file moves, but also a link to a fixed sha loses its relevance as time passes (for instance, here it was pointing to code that had changed a lot). This could be especially problematic for a comment that says "keep in sync with ...".