Skip to content

Commit

Permalink
stop propagating x-datadog-tags header (#2506)
Browse files Browse the repository at this point in the history
* stop propagating `x-datadog-tags`

* restore some of the validation to ensure we _don't_ set the header

* remove code instead of commenting, we can revert this later

* restore vertical propagation of trace-level tags
  • Loading branch information
lucaspimentel committed Feb 24, 2022
1 parent 3b2d719 commit 88b1947
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 42 deletions.
15 changes: 0 additions & 15 deletions tracer/src/Datadog.Trace/SpanContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ public class SpanContext : ISpanContext, IReadOnlyDictionary<string, string>
HttpHeaderNames.ParentId,
HttpHeaderNames.SamplingPriority,
HttpHeaderNames.Origin,
HttpHeaderNames.DatadogTags,
};

/// <summary>
Expand Down Expand Up @@ -134,16 +133,6 @@ private SpanContext(ulong? traceId, string serviceName)
/// </summary>
internal string Origin { get; set; }

/// <summary>
/// Gets or sets a collection of propagated internal Datadog tags,
/// formatted as "key1=value1,key2=value2".
/// </summary>
/// <remarks>
/// We're keeping this as the string representation to avoid having to parse.
/// For now, it's relatively easy to append new values when needed.
/// </remarks>
internal string DatadogTags { get; set; }

/// <summary>
/// Gets the trace context.
/// Returns null for contexts created from incoming propagated context.
Expand Down Expand Up @@ -241,10 +230,6 @@ bool IReadOnlyDictionary<string, string>.TryGetValue(string key, out string valu
value = Origin;
return true;

case HttpHeaderNames.DatadogTags:
value = DatadogTags;
return true;

default:
value = null;
return false;
Expand Down
13 changes: 1 addition & 12 deletions tracer/src/Datadog.Trace/SpanContextPropagator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,6 @@ public void Inject<TCarrier>(SpanContext context, TCarrier carrier, Action<TCarr
{
setter(carrier, HttpHeaderNames.SamplingPriority, samplingPriority.Value.ToString(_invariantCulture));
}

var datadogTags = context.TraceContext?.Tags?.ToPropagationHeader() ?? context.DatadogTags;

if (datadogTags != null)
{
setter(carrier, HttpHeaderNames.DatadogTags, datadogTags);
}
}

/// <summary>
Expand Down Expand Up @@ -121,12 +114,8 @@ public void Inject<TCarrier>(SpanContext context, TCarrier carrier, Action<TCarr
var parentId = ParseUInt64(carrier, getter, HttpHeaderNames.ParentId) ?? 0;
var samplingPriority = ParseInt32(carrier, getter, HttpHeaderNames.SamplingPriority);
var origin = ParseString(carrier, getter, HttpHeaderNames.Origin);
var datadogTags = ParseString(carrier, getter, HttpHeaderNames.DatadogTags);

return new SpanContext(traceId, parentId, samplingPriority, serviceName: null, origin)
{
DatadogTags = datadogTags
};
return new SpanContext(traceId, parentId, samplingPriority, serviceName: null, origin);
}

public IEnumerable<KeyValuePair<string, string?>> ExtractHeaderTags<T>(T headers, IEnumerable<KeyValuePair<string, string?>> headerToTagMap, string defaultTagPrefix)
Expand Down
5 changes: 2 additions & 3 deletions tracer/src/Datadog.Trace/Tracer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -348,14 +348,13 @@ internal SpanContext CreateSpanContext(ISpanContext parent = null, string servic
traceContext = parentSpanContext.TraceContext;
if (traceContext == null)
{
var traceTags = TraceTagCollection.ParseFromPropagationHeader(parentSpanContext.DatadogTags);
traceContext = new TraceContext(this, traceTags);
traceContext = new TraceContext(this);
traceContext.SetSamplingPriority(parentSpanContext.SamplingPriority ?? DistributedTracer.Instance.GetSamplingPriority());
}
}
else
{
traceContext = new TraceContext(this, tags: null);
traceContext = new TraceContext(this);
traceContext.SetSamplingPriority(DistributedTracer.Instance.GetSamplingPriority());
}

Expand Down
15 changes: 3 additions & 12 deletions tracer/test/Datadog.Trace.Tests/SpanContextPropagatorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ public class SpanContextPropagatorTests
private const ulong SpanId = 2;
private const int SamplingPriority = SamplingPriorityValues.UserReject;
private const string Origin = "origin";
private const string DatadogTags = "key1=value1;key2=value2";

private static readonly CultureInfo InvariantCulture = CultureInfo.InvariantCulture;

Expand All @@ -29,7 +28,6 @@ public class SpanContextPropagatorTests
new(HttpHeaderNames.ParentId, SpanId.ToString(InvariantCulture)),
new(HttpHeaderNames.SamplingPriority, SamplingPriority.ToString(InvariantCulture)),
new(HttpHeaderNames.Origin, Origin),
new(HttpHeaderNames.DatadogTags, DatadogTags),
};

public static TheoryData<string> GetInvalidIds() => new()
Expand All @@ -44,7 +42,7 @@ public class SpanContextPropagatorTests
[Fact]
public void Inject_IHeadersCollection()
{
var context = new SpanContext(TraceId, SpanId, SamplingPriority, serviceName: null, Origin) { DatadogTags = DatadogTags };
var context = new SpanContext(TraceId, SpanId, SamplingPriority, serviceName: null, Origin);
var headers = new Mock<IHeadersCollection>();

SpanContextPropagator.Instance.Inject(context, headers.Object);
Expand All @@ -55,7 +53,7 @@ public void Inject_IHeadersCollection()
[Fact]
public void Inject_CarrierAndDelegate()
{
var context = new SpanContext(TraceId, SpanId, SamplingPriority, serviceName: null, Origin) { DatadogTags = DatadogTags };
var context = new SpanContext(TraceId, SpanId, SamplingPriority, serviceName: null, Origin);

// using IHeadersCollection for convenience, but carrier could be any type
var headers = new Mock<IHeadersCollection>();
Expand All @@ -68,7 +66,7 @@ public void Inject_CarrierAndDelegate()
[Fact]
public void Inject_TraceIdSpanIdOnly()
{
var context = new SpanContext(TraceId, SpanId, samplingPriority: null, serviceName: null, origin: null) { DatadogTags = null };
var context = new SpanContext(TraceId, SpanId, samplingPriority: null, serviceName: null, origin: null);
var headers = new Mock<IHeadersCollection>();

SpanContextPropagator.Instance.Inject(context, headers.Object);
Expand All @@ -95,7 +93,6 @@ public void Extract_IHeadersCollection()
SpanId = SpanId,
Origin = Origin,
SamplingPriority = SamplingPriority,
DatadogTags = DatadogTags,
});
}

Expand All @@ -116,7 +113,6 @@ public void Extract_CarrierAndDelegate()
SpanId = SpanId,
Origin = Origin,
SamplingPriority = SamplingPriority,
DatadogTags = DatadogTags,
});
}

Expand All @@ -136,7 +132,6 @@ public void Extract_ReadOnlyDictionary()
SpanId = SpanId,
Origin = Origin,
SamplingPriority = SamplingPriority,
DatadogTags = DatadogTags,
});
}

Expand Down Expand Up @@ -218,7 +213,6 @@ public void Extract_InvalidSpanId(string spanId)
TraceId = TraceId,
Origin = Origin,
SamplingPriority = SamplingPriority,
DatadogTags = DatadogTags,
});
}

Expand Down Expand Up @@ -249,7 +243,6 @@ public void Extract_InvalidSamplingPriority(string samplingPriority, int? expect
SpanId = SpanId,
Origin = Origin,
SamplingPriority = expectedSamplingPriority,
DatadogTags = DatadogTags,
});
}

Expand Down Expand Up @@ -328,8 +321,6 @@ internal class SpanContextMock

public int? SamplingPriority { get; set; }

public string DatadogTags { get; set; }

public ISpanContext Parent { get; set; }

public ulong? ParentId { get; set; }
Expand Down

0 comments on commit 88b1947

Please sign in to comment.