Skip to content

Commit 9dbe1e8

Browse files
committed
take the responsibility of checking the config away from process tags class
1 parent f252a35 commit 9dbe1e8

File tree

4 files changed

+5
-32
lines changed

4 files changed

+5
-32
lines changed

tracer/src/Datadog.Trace/Agent/MessagePack/SpanMessagePackFormatter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -605,7 +605,7 @@ private int WriteTags(ref byte[] bytes, int offset, in SpanModel model, ITagProc
605605
}
606606

607607
// Process tags will be sent only once per trace
608-
if (model.IsFirstSpanInChunk)
608+
if (model.IsFirstSpanInChunk && model.TraceChunk.ShouldPropagateProcessTags)
609609
{
610610
var processTags = ProcessTags.SerializedTags;
611611
var processTagsRawBytes = MessagePackStringCache.GetProcessTagsBytes(processTags);

tracer/src/Datadog.Trace/Agent/MessagePack/TraceChunkModel.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ internal readonly struct TraceChunkModel
6363

6464
public readonly ImmutableAzureAppServiceSettings? AzureAppServiceSettings = null;
6565

66+
public readonly bool ShouldPropagateProcessTags = true;
67+
6668
public readonly bool IsApmEnabled = true;
6769

6870
/// <summary>
@@ -108,6 +110,7 @@ private TraceChunkModel(in ArraySegment<Span> spans, TraceContext? traceContext,
108110
{
109111
IsRunningInAzureAppService = settings.IsRunningInAzureAppService;
110112
AzureAppServiceSettings = settings.AzureAppServiceMetadata;
113+
ShouldPropagateProcessTags = settings.PropagateProcessTags;
111114
IsApmEnabled = settings.ApmTracingEnabled;
112115
}
113116

tracer/src/Datadog.Trace/ProcessTags.cs

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,6 @@ private static Dictionary<string, string> LoadBaseTags()
3131
{
3232
var tags = new Dictionary<string, string>();
3333

34-
if (!Tracer.Instance.Settings.PropagateProcessTags)
35-
{
36-
// do not collect anything when disabled
37-
return tags;
38-
}
39-
4034
var entrypointFullName = Assembly.GetEntryAssembly()?.EntryPoint?.DeclaringType?.FullName;
4135
if (!string.IsNullOrEmpty(entrypointFullName))
4236
{
@@ -71,9 +65,4 @@ private static string NormalizeTagValue(string tagValue)
7165
// which we don't want because we use it as a key/value separator.
7266
return TraceUtil.NormalizeTag(tagValue).Replace(oldChar: ':', newChar: '_');
7367
}
74-
75-
internal static void ResetForTests()
76-
{
77-
_lazySerializedTags = new Lazy<string>(GetSerializedTags);
78-
}
7968
}

tracer/test/Datadog.Trace.Tests/ProcessTagsTests.cs

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,40 +3,21 @@
33
// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc.
44
// </copyright>
55

6-
using System.Collections.Generic;
76
using System.Linq;
8-
using Datadog.Trace.Configuration;
97
using FluentAssertions;
108
using Xunit;
119

1210
namespace Datadog.Trace.Tests;
1311

1412
public class ProcessTagsTests
1513
{
16-
public ProcessTagsTests()
17-
{
18-
ProcessTags.ResetForTests();
19-
}
20-
21-
[Fact]
22-
public void EmptyIfDisabled()
23-
{
24-
Tracer.Configure(TracerSettings.Create(new Dictionary<string, object>()));
25-
26-
ProcessTags.SerializedTags.Should().BeEmpty();
27-
}
28-
2914
[Fact]
3015
public void TagsPresentWhenEnabled()
3116
{
32-
Tracer.Configure(TracerSettings.Create(new Dictionary<string, object>
33-
{
34-
[ConfigurationKeys.PropagateProcessTags] = "true"
35-
}));
36-
3717
var tags = ProcessTags.SerializedTags;
3818

3919
tags.Should().ContainAll(ProcessTags.EntrypointName, ProcessTags.EntrypointBasedir, ProcessTags.EntrypointWorkdir);
20+
4021
tags.Split(',').Should().BeInAscendingOrder();
4122

4223
// assert on the format, which is key:values in a string, comma separated.

0 commit comments

Comments
 (0)