From 1904cfcbe436e73b3aef7f83bc36ee4c262b3196 Mon Sep 17 00:00:00 2001 From: Tarek Mahmoud Sayed Date: Tue, 13 Jul 2021 09:00:40 -0700 Subject: [PATCH] Rename TextMapPropagator to DistributedContextPropagator (#55539) --- ...em.Diagnostics.DiagnosticSourceActivity.cs | 10 +-- ...System.Diagnostics.DiagnosticSource.csproj | 2 +- ...tor.cs => DistributedContextPropagator.cs} | 18 ++--- .../System/Diagnostics/LegacyPropagator.cs | 4 +- .../System/Diagnostics/NoOutputPropagator.cs | 4 +- .../Diagnostics/PassThroughPropagator.cs | 4 +- .../tests/PropagatorTests.cs | 74 +++++++++---------- 7 files changed, 58 insertions(+), 58 deletions(-) rename src/libraries/System.Diagnostics.DiagnosticSource/src/System/Diagnostics/{TextMapPropagator.cs => DistributedContextPropagator.cs} (89%) diff --git a/src/libraries/System.Diagnostics.DiagnosticSource/ref/System.Diagnostics.DiagnosticSourceActivity.cs b/src/libraries/System.Diagnostics.DiagnosticSource/ref/System.Diagnostics.DiagnosticSourceActivity.cs index 7e50f732e4217..68fa62b8be9be 100644 --- a/src/libraries/System.Diagnostics.DiagnosticSource/ref/System.Diagnostics.DiagnosticSourceActivity.cs +++ b/src/libraries/System.Diagnostics.DiagnosticSource/ref/System.Diagnostics.DiagnosticSourceActivity.cs @@ -254,7 +254,7 @@ public sealed class ActivityListener : IDisposable public System.Diagnostics.SampleActivity? Sample { get { throw null; } set { throw null; } } public void Dispose() { throw null; } } - public abstract class TextMapPropagator + public abstract class DistributedContextPropagator { public delegate void PropagatorGetterCallback(object? carrier, string fieldName, out string? fieldValue, out System.Collections.Generic.IEnumerable? fieldValues); public delegate void PropagatorSetterCallback(object? carrier, string fieldName, string fieldValue); @@ -262,10 +262,10 @@ public abstract class TextMapPropagator public abstract void Inject(Activity? activity, object? carrier, PropagatorSetterCallback? setter); public abstract void ExtractTraceIdAndState(object? carrier, PropagatorGetterCallback? getter, out string? traceId, out string? traceState); public abstract System.Collections.Generic.IEnumerable>? ExtractBaggage(object? carrier, PropagatorGetterCallback? getter); - public static TextMapPropagator Current { get; set; } - public static TextMapPropagator CreateDefaultPropagator() { throw null; } - public static TextMapPropagator CreatePassThroughPropagator() { throw null; } - public static TextMapPropagator CreateNoOutputPropagator() { throw null; } + public static DistributedContextPropagator Current { get; set; } + public static DistributedContextPropagator CreateDefaultPropagator() { throw null; } + public static DistributedContextPropagator CreatePassThroughPropagator() { throw null; } + public static DistributedContextPropagator CreateNoOutputPropagator() { throw null; } } } diff --git a/src/libraries/System.Diagnostics.DiagnosticSource/src/System.Diagnostics.DiagnosticSource.csproj b/src/libraries/System.Diagnostics.DiagnosticSource/src/System.Diagnostics.DiagnosticSource.csproj index e4a9cbd28d7ff..dab222792b1bb 100644 --- a/src/libraries/System.Diagnostics.DiagnosticSource/src/System.Diagnostics.DiagnosticSource.csproj +++ b/src/libraries/System.Diagnostics.DiagnosticSource/src/System.Diagnostics.DiagnosticSource.csproj @@ -39,11 +39,11 @@ + - diff --git a/src/libraries/System.Diagnostics.DiagnosticSource/src/System/Diagnostics/TextMapPropagator.cs b/src/libraries/System.Diagnostics.DiagnosticSource/src/System/Diagnostics/DistributedContextPropagator.cs similarity index 89% rename from src/libraries/System.Diagnostics.DiagnosticSource/src/System/Diagnostics/TextMapPropagator.cs rename to src/libraries/System.Diagnostics.DiagnosticSource/src/System/Diagnostics/DistributedContextPropagator.cs index 0dab622a29833..9c54baf9c251c 100644 --- a/src/libraries/System.Diagnostics.DiagnosticSource/src/System/Diagnostics/TextMapPropagator.cs +++ b/src/libraries/System.Diagnostics.DiagnosticSource/src/System/Diagnostics/DistributedContextPropagator.cs @@ -9,13 +9,13 @@ namespace System.Diagnostics { /// - /// An implementation of TextMapPropagator determines if and how distributed context information is encoded and decoded as it traverses the network. + /// An implementation of DistributedContextPropagator determines if and how distributed context information is encoded and decoded as it traverses the network. /// The encoding can be transported over any network protocol that supports string key-value pairs. For example when using HTTP, each key value pair is an HTTP header. - /// TextMapPropagator inject values into and extracts values from carriers as string key/value pairs. + /// DistributedContextPropagator inject values into and extracts values from carriers as string key/value pairs. /// - public abstract class TextMapPropagator + public abstract class DistributedContextPropagator { - private static TextMapPropagator s_current = CreateDefaultPropagator(); + private static DistributedContextPropagator s_current = CreateDefaultPropagator(); /// /// The callback that is used in propagators' extract methods. The callback is invoked to lookup the value of a named field. @@ -38,7 +38,7 @@ public abstract class TextMapPropagator /// /// The set of field names this propagator is likely to read or write. /// - /// Returns list of fields that will be used by the TextMapPropagator. + /// Returns list of fields that will be used by the DistributedContextPropagator. public abstract IReadOnlyCollection Fields { get; } /// @@ -69,7 +69,7 @@ public abstract class TextMapPropagator /// /// Get or set the process wide propagator object which used as the current selected propagator. /// - public static TextMapPropagator Current + public static DistributedContextPropagator Current { get { @@ -91,18 +91,18 @@ public static TextMapPropagator Current /// "traceparent" of the identifiers which are formatted as W3C trace parent, "Request-Id" of the identifiers which are formatted as a hierarchical identifier. /// The returned propagator can inject the baggage key-value pair list with header name "Correlation-Context" and it can extract the baggage values mapped to header names "Correlation-Context" and "baggage". /// - public static TextMapPropagator CreateDefaultPropagator() => LegacyPropagator.Instance; + public static DistributedContextPropagator CreateDefaultPropagator() => LegacyPropagator.Instance; /// /// Returns a propagator which attempts to act transparently, emitting the same data on outbound network requests that was received on the in-bound request. /// When encoding the outbound message, this propagator uses information from the request's root Activity, ignoring any intermediate Activities that may have been created while processing the request. /// - public static TextMapPropagator CreatePassThroughPropagator() => PassThroughPropagator.Instance; + public static DistributedContextPropagator CreatePassThroughPropagator() => PassThroughPropagator.Instance; /// /// Returns a propagator which does not transmit any distributed context information in outbound network messages. /// - public static TextMapPropagator CreateNoOutputPropagator() => NoOutputPropagator.Instance; + public static DistributedContextPropagator CreateNoOutputPropagator() => NoOutputPropagator.Instance; // internal stuff diff --git a/src/libraries/System.Diagnostics.DiagnosticSource/src/System/Diagnostics/LegacyPropagator.cs b/src/libraries/System.Diagnostics.DiagnosticSource/src/System/Diagnostics/LegacyPropagator.cs index a469dd5b56b6b..9a3c909bb177b 100644 --- a/src/libraries/System.Diagnostics.DiagnosticSource/src/System/Diagnostics/LegacyPropagator.cs +++ b/src/libraries/System.Diagnostics.DiagnosticSource/src/System/Diagnostics/LegacyPropagator.cs @@ -7,9 +7,9 @@ namespace System.Diagnostics { - internal sealed class LegacyPropagator : TextMapPropagator + internal sealed class LegacyPropagator : DistributedContextPropagator { - internal static TextMapPropagator Instance { get; } = new LegacyPropagator(); + internal static DistributedContextPropagator Instance { get; } = new LegacyPropagator(); public override IReadOnlyCollection Fields { get; } = new ReadOnlyCollection(new[] { TraceParent, RequestId, TraceState, Baggage, CorrelationContext }); diff --git a/src/libraries/System.Diagnostics.DiagnosticSource/src/System/Diagnostics/NoOutputPropagator.cs b/src/libraries/System.Diagnostics.DiagnosticSource/src/System/Diagnostics/NoOutputPropagator.cs index f9d503a8f1c9a..1655ef466e000 100644 --- a/src/libraries/System.Diagnostics.DiagnosticSource/src/System/Diagnostics/NoOutputPropagator.cs +++ b/src/libraries/System.Diagnostics.DiagnosticSource/src/System/Diagnostics/NoOutputPropagator.cs @@ -5,9 +5,9 @@ namespace System.Diagnostics { - internal sealed class NoOutputPropagator : TextMapPropagator + internal sealed class NoOutputPropagator : DistributedContextPropagator { - internal static TextMapPropagator Instance { get; } = new NoOutputPropagator(); + internal static DistributedContextPropagator Instance { get; } = new NoOutputPropagator(); public override IReadOnlyCollection Fields { get; } = LegacyPropagator.Instance.Fields; diff --git a/src/libraries/System.Diagnostics.DiagnosticSource/src/System/Diagnostics/PassThroughPropagator.cs b/src/libraries/System.Diagnostics.DiagnosticSource/src/System/Diagnostics/PassThroughPropagator.cs index 01bf821a5cbc9..12515555fcf46 100644 --- a/src/libraries/System.Diagnostics.DiagnosticSource/src/System/Diagnostics/PassThroughPropagator.cs +++ b/src/libraries/System.Diagnostics.DiagnosticSource/src/System/Diagnostics/PassThroughPropagator.cs @@ -5,9 +5,9 @@ namespace System.Diagnostics { - internal sealed class PassThroughPropagator : TextMapPropagator + internal sealed class PassThroughPropagator : DistributedContextPropagator { - internal static TextMapPropagator Instance { get; } = new PassThroughPropagator(); + internal static DistributedContextPropagator Instance { get; } = new PassThroughPropagator(); public override IReadOnlyCollection Fields { get; } = LegacyPropagator.Instance.Fields; diff --git a/src/libraries/System.Diagnostics.DiagnosticSource/tests/PropagatorTests.cs b/src/libraries/System.Diagnostics.DiagnosticSource/tests/PropagatorTests.cs index a0ade495467da..2a914f62ad530 100644 --- a/src/libraries/System.Diagnostics.DiagnosticSource/tests/PropagatorTests.cs +++ b/src/libraries/System.Diagnostics.DiagnosticSource/tests/PropagatorTests.cs @@ -21,89 +21,89 @@ public class PropagatorTests public void TestAllPropagators() { RemoteExecutor.Invoke(() => { - Assert.NotNull(TextMapPropagator.Current); + Assert.NotNull(DistributedContextPropagator.Current); // // Default Propagator // - Assert.Same(TextMapPropagator.CreateDefaultPropagator(), TextMapPropagator.Current); + Assert.Same(DistributedContextPropagator.CreateDefaultPropagator(), DistributedContextPropagator.Current); TestDefaultPropagatorUsingW3CActivity( - TextMapPropagator.Current, + DistributedContextPropagator.Current, "Legacy1=true", new List>() { new KeyValuePair(" LegacyKey1 ", " LegacyValue1 ") }); TestDefaultPropagatorUsingHierarchicalActivity( - TextMapPropagator.Current, + DistributedContextPropagator.Current, "Legacy2=true", new List>() { new KeyValuePair("LegacyKey2", "LegacyValue2") }); - TestFields(TextMapPropagator.Current); + TestFields(DistributedContextPropagator.Current); // // NoOutput Propagator // - TextMapPropagator.Current = TextMapPropagator.CreateNoOutputPropagator(); - Assert.NotNull(TextMapPropagator.Current); + DistributedContextPropagator.Current = DistributedContextPropagator.CreateNoOutputPropagator(); + Assert.NotNull(DistributedContextPropagator.Current); TestNoOutputPropagatorUsingHierarchicalActivity( - TextMapPropagator.Current, + DistributedContextPropagator.Current, "ActivityState=1", new List>() { new KeyValuePair("B1", "V1"), new KeyValuePair(" B2 ", " V2 ")}); TestNoOutputPropagatorUsingHierarchicalActivity( - TextMapPropagator.Current, + DistributedContextPropagator.Current, "ActivityState=2", null); TestNoOutputPropagatorUsingW3CActivity( - TextMapPropagator.Current, + DistributedContextPropagator.Current, "ActivityState=1", new List>() { new KeyValuePair(" B3 ", " V3"), new KeyValuePair(" B4 ", " V4 "), new KeyValuePair("B5", "V5")}); TestNoOutputPropagatorUsingW3CActivity( - TextMapPropagator.Current, + DistributedContextPropagator.Current, "ActivityState=2", null); - TestFields(TextMapPropagator.Current); + TestFields(DistributedContextPropagator.Current); // // Pass Through Propagator // - TextMapPropagator.Current = TextMapPropagator.CreatePassThroughPropagator(); - Assert.NotNull(TextMapPropagator.Current); + DistributedContextPropagator.Current = DistributedContextPropagator.CreatePassThroughPropagator(); + Assert.NotNull(DistributedContextPropagator.Current); TestPassThroughPropagatorUsingHierarchicalActivityWithParentChain( - TextMapPropagator.Current, + DistributedContextPropagator.Current, "PassThrough=true", new List>() { new KeyValuePair("PassThroughKey1", "PassThroughValue1"), new KeyValuePair("PassThroughKey2", "PassThroughValue2")}); TestPassThroughPropagatorUsingHierarchicalActivityWithParentId( - TextMapPropagator.Current, + DistributedContextPropagator.Current, "PassThrough1=true", new List>() { new KeyValuePair("PassThroughKey3", "PassThroughValue3"), new KeyValuePair(" PassThroughKey4 ", " PassThroughValue4 ")}); TestPassThroughPropagatorUsingW3CActivity( - TextMapPropagator.Current, + DistributedContextPropagator.Current, "PassThrough2=1", new List>() { new KeyValuePair(" PassThroughKey4 ", " PassThroughValue4 ") }); - TestPassThroughPropagatorWithNullCurrent(TextMapPropagator.Current); + TestPassThroughPropagatorWithNullCurrent(DistributedContextPropagator.Current); - TestFields(TextMapPropagator.Current); + TestFields(DistributedContextPropagator.Current); // // Test Current // - Assert.Throws(() => TextMapPropagator.Current = null); + Assert.Throws(() => DistributedContextPropagator.Current = null); }).Dispose(); } - private void TestDefaultPropagatorUsingW3CActivity(TextMapPropagator propagator, string state, IEnumerable> baggage) + private void TestDefaultPropagatorUsingW3CActivity(DistributedContextPropagator propagator, string state, IEnumerable> baggage) { using Activity a = CreateW3CActivity("LegacyW3C1", "LegacyW3CState=1", baggage); using Activity b = CreateW3CActivity("LegacyW3C2", "LegacyW3CState=2", baggage); @@ -117,7 +117,7 @@ private void TestDefaultPropagatorUsingW3CActivity(TextMapPropagator propagator, TestDefaultPropagatorUsing(Activity.Current, propagator, state, baggage); } - private void TestDefaultPropagatorUsingHierarchicalActivity(TextMapPropagator propagator, string state, IEnumerable> baggage) + private void TestDefaultPropagatorUsingHierarchicalActivity(DistributedContextPropagator propagator, string state, IEnumerable> baggage) { using Activity a = CreateHierarchicalActivity("LegacyHierarchical1", null, "LegacyHierarchicalState=1", baggage); using Activity b = CreateHierarchicalActivity("LegacyHierarchical2", null, "LegacyHierarchicalState=2", baggage); @@ -131,7 +131,7 @@ private void TestDefaultPropagatorUsingHierarchicalActivity(TextMapPropagator pr TestDefaultPropagatorUsing(Activity.Current, propagator, state, baggage); } - private void TestDefaultPropagatorUsing(Activity a, TextMapPropagator propagator, string state, IEnumerable> baggage) + private void TestDefaultPropagatorUsing(Activity a, DistributedContextPropagator propagator, string state, IEnumerable> baggage) { // Test with non-current propagator.Inject(a, null, (object carrier, string fieldName, string value) => @@ -167,7 +167,7 @@ private void TestDefaultPropagatorUsing(Activity a, TextMapPropagator propagator TestBaggageExtraction(propagator, a); } - private void TestNoOutputPropagatorUsingHierarchicalActivity(TextMapPropagator propagator, string state, IEnumerable> baggage) + private void TestNoOutputPropagatorUsingHierarchicalActivity(DistributedContextPropagator propagator, string state, IEnumerable> baggage) { using Activity a = CreateHierarchicalActivity("NoOutputHierarchical", null, state, baggage); @@ -181,7 +181,7 @@ private void TestNoOutputPropagatorUsingHierarchicalActivity(TextMapPropagator p TestBaggageExtraction(propagator, a); } - private void TestNoOutputPropagatorUsingW3CActivity(TextMapPropagator propagator, string state, IEnumerable> baggage) + private void TestNoOutputPropagatorUsingW3CActivity(DistributedContextPropagator propagator, string state, IEnumerable> baggage) { using Activity a = CreateW3CActivity("NoOutputW3C", state, baggage); @@ -195,7 +195,7 @@ private void TestNoOutputPropagatorUsingW3CActivity(TextMapPropagator propagator TestBaggageExtraction(propagator, a); } - private void TestPassThroughPropagatorUsingHierarchicalActivityWithParentChain(TextMapPropagator propagator, string state, IEnumerable> baggage) + private void TestPassThroughPropagatorUsingHierarchicalActivityWithParentChain(DistributedContextPropagator propagator, string state, IEnumerable> baggage) { using Activity a = CreateHierarchicalActivity("PassThrough", null, state, baggage); using Activity b = CreateHierarchicalActivity("PassThroughChild1", null, state + "1", new List>() { new KeyValuePair("Child1Key", "Child1Value") } ); @@ -239,7 +239,7 @@ private void TestPassThroughPropagatorUsingHierarchicalActivityWithParentChain(T TestBaggageExtraction(propagator, c); } - private void TestPassThroughPropagatorUsingHierarchicalActivityWithParentId(TextMapPropagator propagator, string state, IEnumerable> baggage) + private void TestPassThroughPropagatorUsingHierarchicalActivityWithParentId(DistributedContextPropagator propagator, string state, IEnumerable> baggage) { using Activity a = CreateHierarchicalActivity("PassThrough", "Parent1", state, baggage); using Activity b = CreateHierarchicalActivity("PassThroughChild1", "Parent2", state + "1", new List>() { new KeyValuePair("Child1Key", "Child1Value") } ); @@ -283,7 +283,7 @@ private void TestPassThroughPropagatorUsingHierarchicalActivityWithParentId(Text TestBaggageExtraction(propagator, c); } - private void TestPassThroughPropagatorUsingW3CActivity(TextMapPropagator propagator, string state, IEnumerable> baggage) + private void TestPassThroughPropagatorUsingW3CActivity(DistributedContextPropagator propagator, string state, IEnumerable> baggage) { using Activity a = CreateW3CActivity("PassThroughW3C", "PassThroughW3CState=1", baggage); @@ -314,7 +314,7 @@ private void TestPassThroughPropagatorUsingW3CActivity(TextMapPropagator propaga TestBaggageExtraction(propagator, a); } - private void TestPassThroughPropagatorWithNullCurrent(TextMapPropagator propagator) + private void TestPassThroughPropagatorWithNullCurrent(DistributedContextPropagator propagator) { Activity.Current = null; @@ -337,7 +337,7 @@ private void TestPassThroughPropagatorWithNullCurrent(TextMapPropagator propagat }); } - private void TestDefaultExtraction(TextMapPropagator propagator, Activity a) + private void TestDefaultExtraction(DistributedContextPropagator propagator, Activity a) { bool traceParentEncountered = false; @@ -388,7 +388,7 @@ private void TestDefaultExtraction(TextMapPropagator propagator, Activity a) Assert.Equal(a.TraceStateString, traceState); } - private void TestBaggageExtraction(TextMapPropagator propagator, Activity a) + private void TestBaggageExtraction(DistributedContextPropagator propagator, Activity a) { bool baggageEncountered = false; @@ -425,7 +425,7 @@ private void TestBaggageExtraction(TextMapPropagator propagator, Activity a) Assert.Equal(GetFormattedBaggage(a.Baggage, false, true), GetFormattedBaggage(b, true)); } - private void TestFields(TextMapPropagator propagator) + private void TestFields(DistributedContextPropagator propagator) { Assert.True(propagator.Fields.Contains(TraceParent)); Assert.True(propagator.Fields.Contains(RequestId)); @@ -532,14 +532,14 @@ public void TestCustomPropagator() { RemoteExecutor.Invoke(() => { - TextMapPropagator.Current = new CustomPropagator(); + DistributedContextPropagator.Current = new CustomPropagator(); using Activity a = CreateW3CActivity("CustomW3C1", "CustomW3CState=1", new List>() { new KeyValuePair(" CustomKey1 ", " CustomValue1 ") }); string traceParent = "x-" + a.Id ; string traceState = "x-" + a.TraceStateString; string baggageString = "x=y, " + GetFormattedBaggage(a.Baggage); - TextMapPropagator.Current.Inject(a, null, (object carrier, string fieldName, string value) => + DistributedContextPropagator.Current.Inject(a, null, (object carrier, string fieldName, string value) => { if (fieldName == CustomPropagator.XTraceParent) { @@ -562,7 +562,7 @@ public void TestCustomPropagator() Assert.False(true, $"Encountered wrong header name '{fieldName}' in the Custom Propagator"); }); - TextMapPropagator.Current.ExtractTraceIdAndState(null, (object carrier, string fieldName, out string? fieldValue, out IEnumerable? fieldValues) => + DistributedContextPropagator.Current.ExtractTraceIdAndState(null, (object carrier, string fieldName, out string? fieldValue, out IEnumerable? fieldValues) => { fieldValues = null; fieldValue = null; @@ -585,7 +585,7 @@ public void TestCustomPropagator() Assert.Equal(traceParent, traceId); Assert.Equal(traceState, state); - IEnumerable>? b = TextMapPropagator.Current.ExtractBaggage(null, (object carrier, string fieldName, out string? fieldValue, out IEnumerable? fieldValues) => + IEnumerable>? b = DistributedContextPropagator.Current.ExtractBaggage(null, (object carrier, string fieldName, out string? fieldValue, out IEnumerable? fieldValues) => { Assert.Null(carrier); fieldValue = null; @@ -607,7 +607,7 @@ public void TestCustomPropagator() }).Dispose(); } - internal class CustomPropagator : TextMapPropagator + internal class CustomPropagator : DistributedContextPropagator { internal const string XTraceParent = "x-traceparent"; internal const string XTraceState = "x-tracestate";