Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
More Feedback
  • Loading branch information
tarekgh committed Jul 10, 2021
commit 5e033b4012399d9bd0da577a5b249d19534887d6
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ private static void GetRootId(out string? parentId, out string? traceState, out

traceState = activity?.TraceStateString;
parentId = activity?.ParentId ?? activity?.Id;
isW3c = activity?.IdFormat == ActivityIdFormat.W3C;
isW3c = parentId is not null ? Activity.TryConvertIdToContext(parentId, traceState, out _) : false;
baggage = activity?.Baggage;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,16 @@
namespace System.Diagnostics
{
/// <summary>
/// Propagator defines the restrictions imposed by a specific transport and is bound to a data type, in order to propagate in-band context data across process boundaries.
/// An implementation of TextMapPropagator 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.
/// </summary>
public abstract class TextMapPropagator
{
private static TextMapPropagator s_current = CreateDefaultPropagator();

/// <summary>
/// Define the callback that can be used with the propagators extract methods. This callback will be invoked for each propagation key to get.
/// The callback that is used in propagators' extract methods. The callback is invoked to lookup the value of a named field.
/// </summary>
/// <param name="carrier">Carrier is the medium used by Propagators to read values from.</param>
/// <param name="fieldName">The propagation field name.</param>
Expand All @@ -26,43 +27,43 @@ public abstract class TextMapPropagator
public delegate void PropagatorGetterCallback(object? carrier, string fieldName, out string? fieldValue, out IEnumerable<string>? fieldValues);

/// <summary>
/// Define the callback that can be used with the propagators inject methods. This callback will be invoked to set a propagation key/value pair.
/// Propagators may invoke it multiple times in order to set multiple pairs.
/// The callback that is used in propagators' inject methods. This callback is invoked to set the value of a named field.
/// Propagators may invoke it multiple times in order to set multiple fields.
/// </summary>
/// <param name="carrier">Carrier is the medium used by Propagators to write values to.</param>
/// <param name="fieldName">The propagation field name.</param>
/// <param name="fieldValue">The value corresponds to the input fieldName. </param>
public delegate void PropagatorSetterCallback(object? carrier, string fieldName, string fieldValue);

/// <summary>
/// The predefined propagation fields
/// The set of field names this propagator is likely to read or write.
/// </summary>
/// <returns>Returns list of fields that will be used by the TextMapPropagator.</returns>
public abstract IReadOnlyCollection<string> Fields { get; }

/// <summary>
/// Injects the trace values stroed in the <see cref="Activity"/> object into a carrier. For example, into the headers of an HTTP request.
/// </summary>
/// <param name="activity">The Activity object has the trace context to inject to the carrier.</param>
/// <param name="carrier">Carrier is the medium used by the propagators to write values to.</param>
/// <param name="setter">The callback will be invoked to set a propagation key/value pair to the carrier.</param>
/// <param name="activity">The Activity object has the distributed context to inject to the carrier.</param>
/// <param name="carrier">Carrier is the medium in which the distributed context will be stored.</param>
/// <param name="setter">The callback will be invoked to set a named key/value pair on the carrier.</param>
public abstract void Inject(Activity? activity, object? carrier, PropagatorSetterCallback? setter);

/// <summary>
/// Extracts the value from an incoming request represented by the carrier. For example, from the headers of an HTTP request.
/// Extracts trace Id and trace state from an incoming request represented by the carrier. For example, from the headers of an HTTP request.
/// </summary>
/// <param name="carrier">Carrier is the medium used by the propagators to read values from.</param>
/// <param name="carrier">Carrier is the medium from which values will be read.</param>
/// <param name="getter">The callback will be invoked to get the propagation trace Id and trace state from carrier.</param>
/// <param name="traceId">The extracted trace Id from the carrier.</param>
/// <param name="traceState">The extracted trace state from the carrier.</param>
public abstract void ExtractTraceIdAndState(object? carrier, PropagatorGetterCallback? getter, out string? traceId, out string? traceState);

/// <summary>
/// Extracts the baggage key-value pairs list from an incoming request represented by the carrier. For example, from the headers of an HTTP request.
/// Extracts the baggage key-value pair list from an incoming request represented by the carrier. For example, from the headers of an HTTP request.
/// </summary>
/// <param name="carrier">Carrier is the medium used by the propagators to read values from.</param>
/// <param name="carrier">Carrier is the medium from which values will be read.</param>
/// <param name="getter">The callback will be invoked to get the propagation baggage list from carrier.</param>
/// <returns>Returns the extracted key-value pair list from teh carrier.</returns>
/// <returns>Returns the extracted key-value pair list from the carrier.</returns>
public abstract IEnumerable<KeyValuePair<string, string?>>? ExtractBaggage(object? carrier, PropagatorGetterCallback? getter);

/// <summary>
Expand All @@ -85,15 +86,21 @@ public static TextMapPropagator Current
/// <summary>
/// returns the default propagator object which Current property will be initialized with.
/// </summary>
/// <remarks>
/// CreateDefaultPropagator will create a propagator instance that can inject and extract the headers with field names "tarcestate",
/// "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".
/// </remarks>
public static TextMapPropagator CreateDefaultPropagator() => LegacyPropagator.Instance;

/// <summary>
/// returns the propagator which can propagate the trace context data using the root Activity and ignore any created child activities.
/// 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.
/// </summary>
public static TextMapPropagator CreatePassThroughPropagator() => PassThroughPropagator.Instance;

/// <summary>
/// returns the propagator which suppress injecting any data to teh carriers.
/// Returns a propagator which does not transmit any distributed context information in outbound network messages.
/// </summary>
public static TextMapPropagator CreateNoOutputPropagator() => NoOutputPropagator.Instance;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is "Output" the right naming to use? Would it be better to keep with the naming used elsewhere in the API, e.g. "NoInjection" or something like that?

Copy link
Member Author

@tarekgh tarekgh Jul 9, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was discussed before. Actually, it was originally proposed with the Inject term instead of Output.

The reason was the terms Inject and Extract are coming from the specs and the APIs has names including these terms will be used in the low-level libraries (e.g. Http Client and asp.net). It is not expected many people call such APIs. While the APIs like CreateNoOutputPropagator will be called for configuration which be done by users who really don't care how the propagators work and even not exposed to Inject/Extract operations. That is why it was preferred to use Output for simplicity for such users.


Expand Down