Skip to content

Commit

Permalink
Remove DSM JSON injection
Browse files Browse the repository at this point in the history
This appears to be handled already and doing it
here just dupes the content.

And it didn't add comma's between the JSON
fields which ccause JSON deserialization errors.

Additionally, it was re-encoding the Base64 again.
  • Loading branch information
bouwkast committed Nov 23, 2024
1 parent bec777b commit be18958
Showing 1 changed file with 3 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,32 +17,13 @@ internal static class ContextPropagation
{
internal const string InjectionKey = "_datadog";

private static void Inject(PropagationContext context, IDictionary messageAttributes, DataStreamsManager? dataStreamsManager, IMessageHeadersHelper messageHeadersHelper, bool isLegacyHeaderNamesEnabled)
private static void Inject(PropagationContext context, IDictionary messageAttributes, DataStreamsManager? dataStreamsManager, IMessageHeadersHelper messageHeadersHelper)
{
// Consolidate headers into one JSON object with <header_name>:<value>
var sb = Util.StringBuilderCache.Acquire();
sb.Append('{');
SpanContextPropagator.Instance.Inject(context, sb, default(StringBuilderCarrierSetter));

if (dataStreamsManager != null && dataStreamsManager.IsEnabled && context.SpanContext?.PathwayContext != null)
{
var encodedBytes = PathwayContextEncoder.Encode(context.SpanContext.PathwayContext.Value);
var base64EncodedContext = Convert.ToBase64String(encodedBytes);
const string ddPathwayCtxBase64 = $"\"{DataStreamsPropagationHeaders.PropagationKeyBase64}\":\"";
sb.Append(ddPathwayCtxBase64)
.Append(base64EncodedContext)
.Append('"');

if (isLegacyHeaderNamesEnabled)
{
// Both PropagationKeyBase64 and PropagationKey use the Base64 encoded context
const string ddPathwayCtx = $"\"{DataStreamsPropagationHeaders.PropagationKey}\":\"";
sb.Append(ddPathwayCtx)
.Append(base64EncodedContext)
.Append('"');
}
}

if (context.SpanContext?.PathwayContext is { } pathwayContext)
{
dataStreamsManager?.InjectPathwayContext(pathwayContext, AwsMessageAttributesHeadersAdapters.GetInjectionAdapter(sb));
Expand All @@ -55,11 +36,8 @@ private static void Inject(PropagationContext context, IDictionary messageAttrib
messageAttributes[InjectionKey] = messageHeadersHelper.CreateMessageAttributeValue(resultString);
}

public static void InjectHeadersIntoMessage(IContainsMessageAttributes carrier, SpanContext spanContext, DataStreamsManager? dataStreamsManager, IMessageHeadersHelper messageHeadersHelper)
=> InjectHeadersIntoMessage(carrier, spanContext, dataStreamsManager, messageHeadersHelper, Tracer.Instance.Settings.IsDataStreamsLegacyHeadersEnabled);

// Internal for testing only
internal static void InjectHeadersIntoMessage(IContainsMessageAttributes carrier, SpanContext spanContext, DataStreamsManager? dataStreamsManager, IMessageHeadersHelper messageHeadersHelper, bool isLegacyHeaderNamesEnabled)
internal static void InjectHeadersIntoMessage(IContainsMessageAttributes carrier, SpanContext spanContext, DataStreamsManager? dataStreamsManager, IMessageHeadersHelper messageHeadersHelper)
{
// add distributed tracing headers to the message
if (carrier.MessageAttributes == null)
Expand Down Expand Up @@ -104,7 +82,7 @@ internal static void InjectHeadersIntoMessage(IContainsMessageAttributes carrier
if (carrier.MessageAttributes.Count < 10)
{
var context = new PropagationContext(spanContext, Baggage.Current);
Inject(context, carrier.MessageAttributes, dataStreamsManager, messageHeadersHelper, isLegacyHeaderNamesEnabled);
Inject(context, carrier.MessageAttributes, dataStreamsManager, messageHeadersHelper);
}
}

Expand Down

0 comments on commit be18958

Please sign in to comment.