Skip to content
Closed
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
Next Next commit
Propagators Support
  • Loading branch information
tarekgh committed Jun 20, 2021
commit 7c5d554822d96686dfc1a6191ca31a6276a1800e
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,25 @@ public sealed class ActivityListener : IDisposable
public System.Diagnostics.SampleActivity<string>? SampleUsingParentId { get { throw null; } set { throw null; } }
public System.Diagnostics.SampleActivity<ActivityContext>? Sample { get { throw null; } set { throw null; } }
public void Dispose() { throw null; }
}
}

public delegate bool PropagatorGetterCallback(object carrier, string fieldName, out string? value);

public abstract class TextMapPropagator
{
public abstract System.Collections.Generic.IEnumerable<string> Fields { get; }
public abstract bool Inject(System.Diagnostics.Activity activity, object carrier, Action<object, string, string> setter);
public abstract bool Inject(System.Diagnostics.ActivityContext context, object carrier, Action<object, string, string> setter);
public abstract bool Inject(System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<string, string?>> baggage, object carrier, Action<object, string, string> setter);
public abstract bool Extract(object carrier, string fieldName, PropagatorGetterCallback getter, out string? value);
Copy link
Member

Choose a reason for hiding this comment

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

When would this overload be used?

Copy link
Member Author

Choose a reason for hiding this comment

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

This is needed for asp.net when reading hierarchical ids with the header name Request-Id. The other Extract overloads will not be able to read such Id.

Copy link
Member

Choose a reason for hiding this comment

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

Thanks. I assume it's not needed for the inject since it can be represented by the Activity?

Copy link
Member Author

Choose a reason for hiding this comment

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

That is right. I am trying to discourage the usage of the hierarchical ids so I wouldn't expose Inject overload for that. I expose the overload that takes Activity object only to support the usage in http client so you don't need to carry any logic there and can just use the propagator as a black box.

public abstract bool Extract(object carrier, PropagatorGetterCallback getter, out System.Diagnostics.ActivityContext context);
public abstract bool Extract(object carrier, PropagatorGetterCallback getter, out System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<string, string?>>? baggage);
Copy link
Member

@MihaZupan MihaZupan Jun 21, 2021

Choose a reason for hiding this comment

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

Overriding 6 methods seems like a lot if a simple use case might be

public sealed class SkipOneActivityLayerPropagator : TextMapPropagator
{
    public override bool Inject(Activity activity, object carrier, Action<object, string, string> setter) =>
        TextMapPropagator.CreateW3CPropagator().Inject(activity.Parent, carrier, setter);
}

Maybe this isn't a problem if it won't be common for users to implement these?

As a side note, such a propagator is how one could solve #41072.

Copy link
Member Author

Choose a reason for hiding this comment

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

I am not sure if we need to force the default implementation here as whoever subclass TextMapPropagator should be aware about this implementation to decide if need to override it or not.

public static TextMapPropagator DefaultPropagator { get; set; }
public static TextMapPropagator CreateLegacyPropagator() { throw null; }
public static TextMapPropagator CreatePassThroughPropagator() { throw null; }
public static TextMapPropagator CreateOutputSuppressionPropagator() { throw null; }
public static TextMapPropagator CreateW3CPropagator() { throw null; }
Copy link
Member

Choose a reason for hiding this comment

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

As an implementation detail, these should be caching a single instance IMO (each is allocating a HashSet internally so it's not just an empty object)

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, this is implementation details. We can cache the instances we return if needed. I didn't bother in the protype to go to that level.

}
}

namespace System.Diagnostics.Metrics
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
<Compile Include="System\Diagnostics\Metrics\ObservableCounter.cs" />
<Compile Include="System\Diagnostics\Metrics\ObservableGauge.cs" />
<Compile Include="System\Diagnostics\Metrics\ObservableInstrument.cs" />
<Compile Include="System\Diagnostics\TextMapPropagator.cs" />
<None Include="ActivityUserGuide.md" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFrameworkIdentifier)' == '.NETCoreApp'">
Expand Down
Loading