Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
1605ace
Support W3C Baggage spec.
CodeBlanch Aug 9, 2020
37f6df5
Moved baggage propagation to its own ITextFormat. Removed IsInjected.
CodeBlanch Aug 9, 2020
a34a80c
updating some tests
eddynaka Aug 9, 2020
7483e90
creating nw files
eddynaka Aug 9, 2020
4d7fd7d
updating files
eddynaka Aug 9, 2020
ec65bc0
buildable in release
eddynaka Aug 9, 2020
1964da6
adding baggage tests
eddynaka Aug 10, 2020
685c298
updating tests
eddynaka Aug 10, 2020
a26e2ce
updating default textformat for http instrumentation
eddynaka Aug 10, 2020
de2898e
Removed a few null checks.
CodeBlanch Aug 11, 2020
1ab0969
Removed DistributedContext. Drive CorrelationContext off of Activity.…
CodeBlanch Aug 11, 2020
3a1f65b
Merge branch 'master' into baggage
eddynaka Aug 11, 2020
387406a
Merge branch 'baggage' of https://github.com/CodeBlanch/opentelemetry…
eddynaka Aug 11, 2020
6454533
updating issues after merge
eddynaka Aug 11, 2020
a07482c
updating based on sanity check
eddynaka Aug 11, 2020
0fecef0
updating baggage test
eddynaka Aug 11, 2020
2a02388
updating tests
eddynaka Aug 11, 2020
6f5f2f1
reiley's comments
eddynaka Aug 11, 2020
90ca374
move to using
eddynaka Aug 11, 2020
a5196e7
Merge branch 'master' into baggage
CodeBlanch Aug 12, 2020
9b815e7
Updates for http-in and http-out. Updated CHANGELOGs.
CodeBlanch Aug 12, 2020
0503bbb
Merge branch 'master' into baggage
eddynaka Aug 12, 2020
172dd1b
Adding tests.
CodeBlanch Aug 13, 2020
f48bc05
Merge branch 'master' into baggage
eddynaka Aug 13, 2020
f9a3f8b
updating correlation context
eddynaka Aug 13, 2020
2f6a3ff
Added test for TraceContextFormat + BaggageFormat used together.
CodeBlanch Aug 14, 2020
80c56b8
Merging from master.
CodeBlanch Aug 14, 2020
34c6667
Fixed broken tests.
CodeBlanch Aug 14, 2020
1a8a922
Code review.
CodeBlanch Aug 14, 2020
8c95541
Test fixup.
CodeBlanch Aug 14, 2020
302267f
updating order
eddynaka Aug 14, 2020
bb25ad0
updating tests
eddynaka Aug 14, 2020
374b4b0
updating tests, adding dispose, clearing objects
eddynaka Aug 14, 2020
e913a56
Merge branch 'master' into baggage
CodeBlanch Aug 15, 2020
f8c967b
Merge branch 'master' into baggage
cijothomas Aug 18, 2020
c3f05f8
Merge branch 'master' into baggage
cijothomas Aug 18, 2020
4fb391a
updating changelog
eddynaka Aug 18, 2020
eb85991
Use "Baggage" instead of "baggage" as the header name.
CodeBlanch Aug 18, 2020
1b3b49f
Added some basic support for the Baggage limits specified in the spec.
CodeBlanch Aug 18, 2020
0a283bf
Fixed and improved ITextFormat log messages.
CodeBlanch Aug 18, 2020
3c2e9fd
Rename TextFormatContext -> PropagationContext.
CodeBlanch Aug 18, 2020
07b8b46
Updated ITextFormat implementations so they don't double-extract.
CodeBlanch Aug 18, 2020
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
Next Next commit
Rename TextFormatContext -> PropagationContext.
  • Loading branch information
CodeBlanch committed Aug 18, 2020
commit 3c2e9fdebda26591fedf6ac33b7241af16516425
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public string SendMessage()
if (activity != null)
{
// Inject the ActivityContext into the message headers to propagate trace context to the receiving service.
TextFormat.Inject(new TextFormatContext(activity.Context, activity.Baggage), props, this.InjectTraceContextIntoBasicProperties);
TextFormat.Inject(new PropagationContext(activity.Context, activity.Baggage), props, this.InjectTraceContextIntoBasicProperties);

// The OpenTelemetry messaging specification defines a number of attributes. These attributes are added here.
RabbitMqHelper.AddMessagingTags(activity);
Expand Down
4 changes: 2 additions & 2 deletions src/OpenTelemetry.Api/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

## Unreleased

* `TextFormatContext` is now used instead of `ActivityContext` in the
`ITextFormat`
* `PropagationContext` is now used instead of `ActivityContext` in the
`ITextFormat` API
([#1048](https://github.com/open-telemetry/opentelemetry-dotnet/pull/1048))
* Added `BaggageFormat` an `ITextFormat` implementation for managing Baggage
propagation via the [W3C
Expand Down
6 changes: 3 additions & 3 deletions src/OpenTelemetry.Api/Context/Propagation/BaggageFormat.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public class BaggageFormat : ITextFormat
public ISet<string> Fields => new HashSet<string> { BaggageHeaderName };

/// <inheritdoc/>
public TextFormatContext Extract<T>(TextFormatContext context, T carrier, Func<T, string, IEnumerable<string>> getter)
public PropagationContext Extract<T>(PropagationContext context, T carrier, Func<T, string, IEnumerable<string>> getter)
{
if (carrier == null)
{
Expand All @@ -60,7 +60,7 @@ public TextFormatContext Extract<T>(TextFormatContext context, T carrier, Func<T
TryExtractBaggage(baggageCollection.ToArray(), out baggage);
}

return new TextFormatContext(
return new PropagationContext(
context.ActivityContext,
baggage ?? context.ActivityBaggage);
}
Expand All @@ -73,7 +73,7 @@ public TextFormatContext Extract<T>(TextFormatContext context, T carrier, Func<T
}

/// <inheritdoc/>
public void Inject<T>(TextFormatContext context, T carrier, Action<T, string, string> setter)
public void Inject<T>(PropagationContext context, T carrier, Action<T, string, string> setter)
{
if (carrier == null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public CompositePropagator(IEnumerable<ITextFormat> textFormats)
public ISet<string> Fields => EmptyFields;

/// <inheritdoc/>
public TextFormatContext Extract<T>(TextFormatContext context, T carrier, Func<T, string, IEnumerable<string>> getter)
public PropagationContext Extract<T>(PropagationContext context, T carrier, Func<T, string, IEnumerable<string>> getter)
{
foreach (var textFormat in this.textFormats)
{
Expand All @@ -51,7 +51,7 @@ public TextFormatContext Extract<T>(TextFormatContext context, T carrier, Func<T
}

/// <inheritdoc/>
public void Inject<T>(TextFormatContext context, T carrier, Action<T, string, string> setter)
public void Inject<T>(PropagationContext context, T carrier, Action<T, string, string> setter)
{
foreach (var textFormat in this.textFormats)
{
Expand Down
4 changes: 2 additions & 2 deletions src/OpenTelemetry.Api/Context/Propagation/ITextFormat.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public interface ITextFormat
/// <param name="context">The default context to transmit over the wire.</param>
/// <param name="carrier">Object to set context on. Instance of this object will be passed to setter.</param>
/// <param name="setter">Action that will set name and value pair on the object.</param>
void Inject<T>(TextFormatContext context, T carrier, Action<T, string, string> setter);
void Inject<T>(PropagationContext context, T carrier, Action<T, string, string> setter);

/// <summary>
/// Extracts activity context from textual representation.
Expand All @@ -49,6 +49,6 @@ public interface ITextFormat
/// <param name="carrier">Object to extract context from. Instance of this object will be passed to the getter.</param>
/// <param name="getter">Function that will return string value of a key with the specified name.</param>
/// <returns>Context from it's text representation.</returns>
TextFormatContext Extract<T>(TextFormatContext context, T carrier, Func<T, string, IEnumerable<string>> getter);
PropagationContext Extract<T>(PropagationContext context, T carrier, Func<T, string, IEnumerable<string>> getter);
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// <copyright file="TextFormatContext.cs" company="OpenTelemetry Authors">
// <copyright file="PropagationContext.cs" company="OpenTelemetry Authors">
// Copyright The OpenTelemetry Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -22,16 +22,16 @@
namespace OpenTelemetry.Context.Propagation
{
/// <summary>
/// TextFormat context.
/// Stores propagation data.
/// </summary>
public readonly struct TextFormatContext : IEquatable<TextFormatContext>
public readonly struct PropagationContext : IEquatable<PropagationContext>
{
/// <summary>
/// Initializes a new instance of the <see cref="TextFormatContext"/> struct.
/// Initializes a new instance of the <see cref="PropagationContext"/> struct.
/// </summary>
/// <param name="activityContext">Entries for activity context.</param>
/// <param name="activityBaggage">Entries for activity baggage.</param>
public TextFormatContext(ActivityContext activityContext, IEnumerable<KeyValuePair<string, string>> activityBaggage)
public PropagationContext(ActivityContext activityContext, IEnumerable<KeyValuePair<string, string>> activityBaggage)
{
this.ActivityContext = activityContext;
this.ActivityBaggage = activityBaggage;
Expand All @@ -48,21 +48,21 @@ public TextFormatContext(ActivityContext activityContext, IEnumerable<KeyValuePa
public IEnumerable<KeyValuePair<string, string>> ActivityBaggage { get; }

/// <summary>
/// Compare two entries of <see cref="TextFormatContext"/> for equality.
/// Compare two entries of <see cref="PropagationContext"/> for equality.
/// </summary>
/// <param name="left">First Entry to compare.</param>
/// <param name="right">Second Entry to compare.</param>
public static bool operator ==(TextFormatContext left, TextFormatContext right) => left.Equals(right);
public static bool operator ==(PropagationContext left, PropagationContext right) => left.Equals(right);

/// <summary>
/// Compare two entries of <see cref="TextFormatContext"/> for not equality.
/// Compare two entries of <see cref="PropagationContext"/> for not equality.
/// </summary>
/// <param name="left">First Entry to compare.</param>
/// <param name="right">Second Entry to compare.</param>
public static bool operator !=(TextFormatContext left, TextFormatContext right) => !(left == right);
public static bool operator !=(PropagationContext left, PropagationContext right) => !(left == right);

/// <inheritdoc/>
public bool Equals(TextFormatContext value)
public bool Equals(PropagationContext value)
{
if (this.ActivityContext != value.ActivityContext
|| this.ActivityBaggage is null != value.ActivityBaggage is null)
Expand Down Expand Up @@ -96,7 +96,7 @@ public bool Equals(TextFormatContext value)
}

/// <inheritdoc/>
public override bool Equals(object obj) => (obj is TextFormatContext context) && this.Equals(context);
public override bool Equals(object obj) => (obj is PropagationContext context) && this.Equals(context);

/// <inheritdoc/>
public override int GetHashCode()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public class TraceContextFormat : ITextFormat
public ISet<string> Fields => new HashSet<string> { TraceState, TraceParent };

/// <inheritdoc/>
public TextFormatContext Extract<T>(TextFormatContext context, T carrier, Func<T, string, IEnumerable<string>> getter)
public PropagationContext Extract<T>(PropagationContext context, T carrier, Func<T, string, IEnumerable<string>> getter)
{
if (carrier == null)
{
Expand Down Expand Up @@ -82,7 +82,7 @@ public TextFormatContext Extract<T>(TextFormatContext context, T carrier, Func<T
TryExtractTracestate(tracestateCollection.ToArray(), out tracestate);
}

return new TextFormatContext(
return new PropagationContext(
new ActivityContext(traceId, spanId, traceoptions, tracestate, isRemote: true),
context.ActivityBaggage);
}
Expand All @@ -96,7 +96,7 @@ public TextFormatContext Extract<T>(TextFormatContext context, T carrier, Func<T
}

/// <inheritdoc/>
public void Inject<T>(TextFormatContext context, T carrier, Action<T, string, string> setter)
public void Inject<T>(PropagationContext context, T carrier, Action<T, string, string> setter)
{
if (context.ActivityContext.TraceId == default || context.ActivityContext.SpanId == default)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public override void OnStartActivity(Activity activity, object payload)

if (!(this.httpClientSupportsW3C && this.options.TextFormat is TraceContextFormat))
{
this.options.TextFormat.Inject(new TextFormatContext(activity.Context, activity.Baggage), request, HttpRequestMessageHeaderValueSetter);
this.options.TextFormat.Inject(new PropagationContext(activity.Context, activity.Baggage), request, HttpRequestMessageHeaderValueSetter);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ private static void AddExceptionTags(Exception exception, Activity activity)

[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static void InstrumentRequest(HttpWebRequest request, Activity activity)
=> Options.TextFormat.Inject(new TextFormatContext(activity.Context, activity.Baggage), request, HttpWebRequestHeaderValuesSetter);
=> Options.TextFormat.Inject(new PropagationContext(activity.Context, activity.Baggage), request, HttpWebRequestHeaderValuesSetter);

[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static bool IsRequestInstrumented(HttpWebRequest request)
Expand Down
8 changes: 4 additions & 4 deletions src/OpenTelemetry.Shims.OpenTracing/TracerShim.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public TracerShim(Trace.Tracer tracer, ITextFormat textFormat)
throw new ArgumentNullException(nameof(carrier));
}

TextFormatContext textFormatContext = default;
PropagationContext propagationContext = default;

if ((format == BuiltinFormats.TextMap || format == BuiltinFormats.HttpHeaders) && carrier is ITextMap textMapCarrier)
{
Expand All @@ -81,10 +81,10 @@ static IEnumerable<string> GetCarrierKeyValue(Dictionary<string, IEnumerable<str
return value;
}

textFormatContext = this.textFormat.Extract(textFormatContext, carrierMap, GetCarrierKeyValue);
propagationContext = this.textFormat.Extract(propagationContext, carrierMap, GetCarrierKeyValue);
}

return !textFormatContext.ActivityContext.IsValid() ? null : new SpanContextShim(new Trace.SpanContext(textFormatContext.ActivityContext), textFormatContext.ActivityBaggage);
return !propagationContext.ActivityContext.IsValid() ? null : new SpanContextShim(new Trace.SpanContext(propagationContext.ActivityContext), propagationContext.ActivityBaggage);
}

/// <inheritdoc/>
Expand Down Expand Up @@ -116,7 +116,7 @@ public void Inject<TCarrier>(
if ((format == BuiltinFormats.TextMap || format == BuiltinFormats.HttpHeaders) && carrier is ITextMap textMapCarrier)
{
this.textFormat.Inject(
new TextFormatContext(shim.SpanContext, shim.GetBaggageItems()),
new PropagationContext(shim.SpanContext, shim.GetBaggageItems()),
textMapCarrier,
(instrumentation, key, value) => instrumentation.Set(key, value));
}
Expand Down
12 changes: 6 additions & 6 deletions src/OpenTelemetry/Context/Propagation/B3Format.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public B3Format(bool singleHeader)
public ISet<string> Fields => AllFields;

/// <inheritdoc/>
public TextFormatContext Extract<T>(TextFormatContext context, T carrier, Func<T, string, IEnumerable<string>> getter)
public PropagationContext Extract<T>(PropagationContext context, T carrier, Func<T, string, IEnumerable<string>> getter)
{
if (carrier == null)
{
Expand All @@ -95,7 +95,7 @@ public TextFormatContext Extract<T>(TextFormatContext context, T carrier, Func<T
}

/// <inheritdoc/>
public void Inject<T>(TextFormatContext context, T carrier, Action<T, string, string> setter)
public void Inject<T>(PropagationContext context, T carrier, Action<T, string, string> setter)
{
if (context.ActivityContext.TraceId == default || context.ActivityContext.SpanId == default)
{
Expand Down Expand Up @@ -140,7 +140,7 @@ public void Inject<T>(TextFormatContext context, T carrier, Action<T, string, st
}
}

private static TextFormatContext ExtractFromMultipleHeaders<T>(TextFormatContext context, T carrier, Func<T, string, IEnumerable<string>> getter)
private static PropagationContext ExtractFromMultipleHeaders<T>(PropagationContext context, T carrier, Func<T, string, IEnumerable<string>> getter)
{
try
{
Expand Down Expand Up @@ -179,7 +179,7 @@ private static TextFormatContext ExtractFromMultipleHeaders<T>(TextFormatContext
traceOptions |= ActivityTraceFlags.Recorded;
}

return new TextFormatContext(
return new PropagationContext(
new ActivityContext(traceId, spanId, traceOptions, isRemote: true),
context.ActivityBaggage);
}
Expand All @@ -190,7 +190,7 @@ private static TextFormatContext ExtractFromMultipleHeaders<T>(TextFormatContext
}
}

private static TextFormatContext ExtractFromSingleHeader<T>(TextFormatContext context, T carrier, Func<T, string, IEnumerable<string>> getter)
private static PropagationContext ExtractFromSingleHeader<T>(PropagationContext context, T carrier, Func<T, string, IEnumerable<string>> getter)
{
try
{
Expand Down Expand Up @@ -239,7 +239,7 @@ private static TextFormatContext ExtractFromSingleHeader<T>(TextFormatContext co
}
}

return new TextFormatContext(
return new PropagationContext(
new ActivityContext(traceId, spanId, traceOptions, isRemote: true),
context.ActivityBaggage);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public void AspNetRequestsAreCollectedSuccessfully(
var expectedTraceId = ActivityTraceId.CreateRandom();
var expectedSpanId = ActivitySpanId.CreateRandom();
var textFormat = new Mock<ITextFormat>();
textFormat.Setup(m => m.Extract<HttpRequest>(It.IsAny<TextFormatContext>(), It.IsAny<HttpRequest>(), It.IsAny<Func<HttpRequest, string, IEnumerable<string>>>())).Returns(new TextFormatContext(
textFormat.Setup(m => m.Extract<HttpRequest>(It.IsAny<PropagationContext>(), It.IsAny<HttpRequest>(), It.IsAny<Func<HttpRequest, string, IEnumerable<string>>>())).Returns(new PropagationContext(
new ActivityContext(
expectedTraceId,
expectedSpanId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ public async Task CustomTextFormat()
var expectedSpanId = ActivitySpanId.CreateRandom();

var textFormat = new Mock<ITextFormat>();
textFormat.Setup(m => m.Extract(It.IsAny<TextFormatContext>(), It.IsAny<HttpRequest>(), It.IsAny<Func<HttpRequest, string, IEnumerable<string>>>())).Returns(new TextFormatContext(
textFormat.Setup(m => m.Extract(It.IsAny<PropagationContext>(), It.IsAny<HttpRequest>(), It.IsAny<Func<HttpRequest, string, IEnumerable<string>>>())).Returns(new PropagationContext(
new ActivityContext(
expectedTraceId,
expectedSpanId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,8 @@ public async Task HttpClientInstrumentationInjectsHeadersAsync()
public async Task HttpClientInstrumentationInjectsHeadersAsync_CustomFormat()
{
var textFormat = new Mock<ITextFormat>();
textFormat.Setup(m => m.Inject<HttpRequestMessage>(It.IsAny<TextFormatContext>(), It.IsAny<HttpRequestMessage>(), It.IsAny<Action<HttpRequestMessage, string, string>>()))
.Callback<TextFormatContext, HttpRequestMessage, Action<HttpRequestMessage, string, string>>((context, message, action) =>
textFormat.Setup(m => m.Inject<HttpRequestMessage>(It.IsAny<PropagationContext>(), It.IsAny<HttpRequestMessage>(), It.IsAny<Action<HttpRequestMessage, string, string>>()))
.Callback<PropagationContext, HttpRequestMessage, Action<HttpRequestMessage, string, string>>((context, message, action) =>
{
action(message, "custom_traceparent", $"00/{context.ActivityContext.TraceId}/{context.ActivityContext.SpanId}/01");
action(message, "custom_tracestate", Activity.Current.TraceStateString);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ public async Task HttpWebRequestInstrumentationInjectsHeadersAsync()
public async Task HttpWebRequestInstrumentationInjectsHeadersAsync_CustomFormat()
{
var textFormat = new Mock<ITextFormat>();
textFormat.Setup(m => m.Inject(It.IsAny<TextFormatContext>(), It.IsAny<HttpWebRequest>(), It.IsAny<Action<HttpWebRequest, string, string>>()))
.Callback<TextFormatContext, HttpWebRequest, Action<HttpWebRequest, string, string>>((context, message, action) =>
textFormat.Setup(m => m.Inject(It.IsAny<PropagationContext>(), It.IsAny<HttpWebRequest>(), It.IsAny<Action<HttpWebRequest, string, string>>()))
.Callback<PropagationContext, HttpWebRequest, Action<HttpWebRequest, string, string>>((context, message, action) =>
{
action(message, "custom_traceparent", $"00/{context.ActivityContext.TraceId}/{context.ActivityContext.SpanId}/01");
action(message, "custom_tracestate", Activity.Current.TraceStateString);
Expand Down
Loading