Skip to content

Commit

Permalink
Updated CustomTextMapPropagator matching open-telemetry#5123
Browse files Browse the repository at this point in the history
  • Loading branch information
ngruson committed Dec 5, 2023
1 parent 651336c commit 70fa741
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions test/OpenTelemetry.Tests/Shared/CustomTextMapPropagator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,30 @@ namespace OpenTelemetry.Tests;

internal sealed class CustomTextMapPropagator : TextMapPropagator
{
#pragma warning disable SA1010
public List<string> ExtractValues = [];
public Dictionary<string, Func<PropagationContext, string>> InjectValues = [];
private static readonly PropagationContext DefaultPropagationContext = default;

public ActivityTraceId TraceId { get; set; }

public ActivitySpanId SpanId { get; set; }

public Action<PropagationContext> Injected { get; set; }

public override ISet<string> Fields => null;

#pragma warning disable SA1201 // Elements should appear in the correct order
#pragma warning disable SA1010 // Opening square brackets should be spaced correctly
public Dictionary<string, Func<PropagationContext, string>> InjectValues = [];
#pragma warning restore SA1010 // Opening square brackets should be spaced correctly
#pragma warning restore SA1201 // Elements should appear in the correct order

public override PropagationContext Extract<T>(PropagationContext context, T carrier, Func<T, string, IEnumerable<string>> getter)
{
if (this.ExtractValues.Count == 2)
if (this.TraceId != default && this.SpanId != default)
{
return new PropagationContext(
new ActivityContext(
ActivityTraceId.CreateFromString(this.ExtractValues[0].ToCharArray()),
ActivitySpanId.CreateFromString(this.ExtractValues[1].ToCharArray()),
this.TraceId,
this.SpanId,
ActivityTraceFlags.Recorded),
default);
}
Expand Down

0 comments on commit 70fa741

Please sign in to comment.