Skip to content

Commit

Permalink
Maximo/Update Context propagation when using OTEL API is Enabled (#4783)
Browse files Browse the repository at this point in the history
* Not adding the W3CTraceContext propagation when ActivityListenerIsEnabled

* Updating tests to not take into account adding the context

* Adding line back to show outcome despite feature value
  • Loading branch information
link04 authored Nov 1, 2023
1 parent 0e71e90 commit 7014168
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 42 deletions.
25 changes: 3 additions & 22 deletions tracer/src/Datadog.Trace/Configuration/TracerSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -272,29 +272,10 @@ internal TracerSettings(IConfigurationSource? source, IConfigurationTelemetry te
validator: styles => styles is { Length: > 0 }, // invalid individual values are rejected later
converter: style => TrimSplitString(style, commaSeparator));

// If Activity support is enabled, we must enable the W3C Trace Context propagators.
// Take care to not duplicate the W3C propagator so the telemetry obtained from our settings looks okay
if (IsActivityListenerEnabled)
// If Activity support is enabled, we shouldn't enable the W3C Trace Context propagators.
if (!IsActivityListenerEnabled)
{
if (!PropagationStyleInject.Contains(ContextPropagationHeaderStyle.W3CTraceContext, StringComparer.OrdinalIgnoreCase))
{
PropagationStyleInject = PropagationStyleInject.Concat(ContextPropagationHeaderStyle.W3CTraceContext);
// "manually" record the updated value for v2 telemetry using the "unknown" origin, as we
// can't easily tell from here which was the original source (that we're modifying)
telemetry.Record(ConfigurationKeys.PropagationStyleInject, string.Join(",", PropagationStyleInject), recordValue: true, ConfigurationOrigins.Unknown);
}

if (!PropagationStyleExtract.Contains(ContextPropagationHeaderStyle.W3CTraceContext, StringComparer.OrdinalIgnoreCase))
{
PropagationStyleExtract = PropagationStyleExtract.Concat(ContextPropagationHeaderStyle.W3CTraceContext);
// "manually" record the updated value for v2 telemetry using the "unknown" origin, as we
// can't easily tell from here which was the original source (that we're modifying)
telemetry.Record(ConfigurationKeys.PropagationStyleExtract, string.Join(",", PropagationStyleExtract), recordValue: true, ConfigurationOrigins.Unknown);
}
}
else
{
DisabledIntegrationNamesInternal.Add(nameof(Configuration.IntegrationId.OpenTelemetry));
DisabledIntegrationNamesInternal.Add(nameof(IntegrationId.OpenTelemetry));
}

LogSubmissionSettings = new DirectLogSubmissionSettings(source, _telemetry);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -647,7 +647,7 @@ public void PropagationStyleInject(string value, string legacyValue, string fall

var settings = new TracerSettings(source);

settings.PropagationStyleInject.Should().BeEquivalentTo(isActivityListenerEnabled && !expected.Contains("tracecontext") ? expected.Concat("tracecontext") : expected);
settings.PropagationStyleInject.Should().BeEquivalentTo(expected);
}
}

Expand All @@ -671,7 +671,7 @@ public void PropagationStyleExtract(string value, string legacyValue, string fal

var settings = new TracerSettings(source);

settings.PropagationStyleExtract.Should().BeEquivalentTo(isActivityListenerEnabled && !expected.Contains("tracecontext") ? expected.Concat("tracecontext") : expected);
settings.PropagationStyleExtract.Should().BeEquivalentTo(expected);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,26 +210,8 @@ public void ConfigurationDataShouldIncludeExpectedPropagationValues(string propa
(null, null) => (ConfigurationKeys.PropagationStyleInject, "tracecontext,Datadog"),
};

// V2 telemetry will collect an additional ",tracecontext" in each propagator style when the following conditions are met
// It will then record it with the "specific" key,
// - DD_TRACE_OTEL_ENABLED=true
// - "tracecontext" is not already included in the propagation configuration
if (activityListenerEnabled == "true" && !ContainsTraceContext(extractValue))
{
extractKey = ConfigurationKeys.PropagationStyleExtract;
extractValue += ",tracecontext";
}

if (activityListenerEnabled == "true" && !ContainsTraceContext(injectValue))
{
injectKey = ConfigurationKeys.PropagationStyleInject;
injectValue += ",tracecontext";
}

GetLatestValueFromConfig(data, extractKey).Should().Be(extractValue);
GetLatestValueFromConfig(data, injectKey).Should().Be(injectValue);

static bool ContainsTraceContext(string value) => value.Split(',').Contains("tracecontext", StringComparer.OrdinalIgnoreCase);
}

#if NETFRAMEWORK
Expand Down

0 comments on commit 7014168

Please sign in to comment.