Renaming TraceContextFormat/B3Format/BaggageFormat (#1175)
* Renaming TraceContextFormat to TextMapPropagator updating changelog renaming b3Format to B3PRopagator renaming BaggageFormat to BaggagePropagator renaming file * renaming variables after merge Co-authored-by: Cijo Thomas <cithomas@microsoft.com>
This commit is contained in:
parent
d11dc0a962
commit
da72b13b72
|
|
@ -40,7 +40,7 @@ namespace Examples.Console
|
||||||
|
|
||||||
// Following shows how to use the OpenTracing shim
|
// Following shows how to use the OpenTracing shim
|
||||||
|
|
||||||
var tracer = new TracerShim(TracerProvider.Default.GetTracer("MyCompany.MyProduct.MyWebServer"), new TraceContextFormat());
|
var tracer = new TracerShim(TracerProvider.Default.GetTracer("MyCompany.MyProduct.MyWebServer"), new TextMapPropagator());
|
||||||
|
|
||||||
using (IScope parentScope = tracer.BuildSpan("Parent").StartActive(finishSpanOnDispose: true))
|
using (IScope parentScope = tracer.BuildSpan("Parent").StartActive(finishSpanOnDispose: true))
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,7 @@ namespace Utils.Messaging
|
||||||
public class MessageReceiver : IDisposable
|
public class MessageReceiver : IDisposable
|
||||||
{
|
{
|
||||||
private static readonly ActivitySource ActivitySource = new ActivitySource(nameof(MessageReceiver));
|
private static readonly ActivitySource ActivitySource = new ActivitySource(nameof(MessageReceiver));
|
||||||
private static readonly ITextFormat TextFormat = new TraceContextFormat();
|
private static readonly ITextFormat TextFormat = new TextMapPropagator();
|
||||||
|
|
||||||
private readonly ILogger<MessageReceiver> logger;
|
private readonly ILogger<MessageReceiver> logger;
|
||||||
private readonly IConnection connection;
|
private readonly IConnection connection;
|
||||||
|
|
|
||||||
|
|
@ -28,7 +28,7 @@ namespace Utils.Messaging
|
||||||
public class MessageSender : IDisposable
|
public class MessageSender : IDisposable
|
||||||
{
|
{
|
||||||
private static readonly ActivitySource ActivitySource = new ActivitySource(nameof(MessageSender));
|
private static readonly ActivitySource ActivitySource = new ActivitySource(nameof(MessageSender));
|
||||||
private static readonly ITextFormat TextFormat = new TraceContextFormat();
|
private static readonly ITextFormat TextFormat = new TextMapPropagator();
|
||||||
|
|
||||||
private readonly ILogger<MessageSender> logger;
|
private readonly ILogger<MessageSender> logger;
|
||||||
private readonly IConnection connection;
|
private readonly IConnection connection;
|
||||||
|
|
|
||||||
|
|
@ -49,6 +49,9 @@
|
||||||
API`](https://github.com/open-telemetry/opentelemetry-specification/blob/master/specification/baggage/api.md)
|
API`](https://github.com/open-telemetry/opentelemetry-specification/blob/master/specification/baggage/api.md)
|
||||||
spec
|
spec
|
||||||
([#1106](https://github.com/open-telemetry/opentelemetry-dotnet/pull/1106))
|
([#1106](https://github.com/open-telemetry/opentelemetry-dotnet/pull/1106))
|
||||||
|
* Renamed `TraceContextFormat` to `TextMapPropagator`, `BaggageFormat` to
|
||||||
|
`BaggagePropagator`, and `B3Format` to `B3Propagator`
|
||||||
|
([#1175](https://github.com/open-telemetry/opentelemetry-dotnet/pull/1175))
|
||||||
|
|
||||||
## 0.4.0-beta.2
|
## 0.4.0-beta.2
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
// <copyright file="B3Format.cs" company="OpenTelemetry Authors">
|
// <copyright file="B3Propagator.cs" company="OpenTelemetry Authors">
|
||||||
// Copyright The OpenTelemetry Authors
|
// Copyright The OpenTelemetry Authors
|
||||||
//
|
//
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
|
@ -26,7 +26,7 @@ namespace OpenTelemetry.Context.Propagation
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// B3 text propagator. See https://github.com/openzipkin/b3-propagation for the specification.
|
/// B3 text propagator. See https://github.com/openzipkin/b3-propagation for the specification.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public sealed class B3Format : ITextFormat
|
public sealed class B3Propagator : ITextFormat
|
||||||
{
|
{
|
||||||
internal const string XB3TraceId = "X-B3-TraceId";
|
internal const string XB3TraceId = "X-B3-TraceId";
|
||||||
internal const string XB3SpanId = "X-B3-SpanId";
|
internal const string XB3SpanId = "X-B3-SpanId";
|
||||||
|
|
@ -51,18 +51,18 @@ namespace OpenTelemetry.Context.Propagation
|
||||||
private readonly bool singleHeader;
|
private readonly bool singleHeader;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="B3Format"/> class.
|
/// Initializes a new instance of the <see cref="B3Propagator"/> class.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public B3Format()
|
public B3Propagator()
|
||||||
: this(false)
|
: this(false)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="B3Format"/> class.
|
/// Initializes a new instance of the <see cref="B3Propagator"/> class.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="singleHeader">Determines whether to use single or multiple headers when extracting or injecting span context.</param>
|
/// <param name="singleHeader">Determines whether to use single or multiple headers when extracting or injecting span context.</param>
|
||||||
public B3Format(bool singleHeader)
|
public B3Propagator(bool singleHeader)
|
||||||
{
|
{
|
||||||
this.singleHeader = singleHeader;
|
this.singleHeader = singleHeader;
|
||||||
}
|
}
|
||||||
|
|
@ -81,13 +81,13 @@ namespace OpenTelemetry.Context.Propagation
|
||||||
|
|
||||||
if (carrier == null)
|
if (carrier == null)
|
||||||
{
|
{
|
||||||
OpenTelemetryApiEventSource.Log.FailedToExtractActivityContext(nameof(B3Format), "null carrier");
|
OpenTelemetryApiEventSource.Log.FailedToExtractActivityContext(nameof(B3Propagator), "null carrier");
|
||||||
return context;
|
return context;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (getter == null)
|
if (getter == null)
|
||||||
{
|
{
|
||||||
OpenTelemetryApiEventSource.Log.FailedToExtractActivityContext(nameof(B3Format), "null getter");
|
OpenTelemetryApiEventSource.Log.FailedToExtractActivityContext(nameof(B3Propagator), "null getter");
|
||||||
return context;
|
return context;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -106,19 +106,19 @@ namespace OpenTelemetry.Context.Propagation
|
||||||
{
|
{
|
||||||
if (context.ActivityContext.TraceId == default || context.ActivityContext.SpanId == default)
|
if (context.ActivityContext.TraceId == default || context.ActivityContext.SpanId == default)
|
||||||
{
|
{
|
||||||
OpenTelemetryApiEventSource.Log.FailedToInjectActivityContext(nameof(B3Format), "invalid context");
|
OpenTelemetryApiEventSource.Log.FailedToInjectActivityContext(nameof(B3Propagator), "invalid context");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (carrier == null)
|
if (carrier == null)
|
||||||
{
|
{
|
||||||
OpenTelemetryApiEventSource.Log.FailedToInjectActivityContext(nameof(B3Format), "null carrier");
|
OpenTelemetryApiEventSource.Log.FailedToInjectActivityContext(nameof(B3Propagator), "null carrier");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (setter == null)
|
if (setter == null)
|
||||||
{
|
{
|
||||||
OpenTelemetryApiEventSource.Log.FailedToInjectActivityContext(nameof(B3Format), "null setter");
|
OpenTelemetryApiEventSource.Log.FailedToInjectActivityContext(nameof(B3Propagator), "null setter");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -192,7 +192,7 @@ namespace OpenTelemetry.Context.Propagation
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
OpenTelemetryApiEventSource.Log.ActivityContextExtractException(nameof(B3Format), e);
|
OpenTelemetryApiEventSource.Log.ActivityContextExtractException(nameof(B3Propagator), e);
|
||||||
return context;
|
return context;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -252,7 +252,7 @@ namespace OpenTelemetry.Context.Propagation
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
OpenTelemetryApiEventSource.Log.ActivityContextExtractException(nameof(B3Format), e);
|
OpenTelemetryApiEventSource.Log.ActivityContextExtractException(nameof(B3Propagator), e);
|
||||||
return context;
|
return context;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
// <copyright file="BaggageFormat.cs" company="OpenTelemetry Authors">
|
// <copyright file="BaggagePropagator.cs" company="OpenTelemetry Authors">
|
||||||
// Copyright The OpenTelemetry Authors
|
// Copyright The OpenTelemetry Authors
|
||||||
//
|
//
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
|
@ -26,7 +26,7 @@ namespace OpenTelemetry.Context.Propagation
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// W3C baggage: https://github.com/w3c/baggage/blob/master/baggage/HTTP_HEADER_FORMAT.md.
|
/// W3C baggage: https://github.com/w3c/baggage/blob/master/baggage/HTTP_HEADER_FORMAT.md.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class BaggageFormat : ITextFormat
|
public class BaggagePropagator : ITextFormat
|
||||||
{
|
{
|
||||||
internal const string BaggageHeaderName = "Baggage";
|
internal const string BaggageHeaderName = "Baggage";
|
||||||
|
|
||||||
|
|
@ -47,13 +47,13 @@ namespace OpenTelemetry.Context.Propagation
|
||||||
|
|
||||||
if (carrier == null)
|
if (carrier == null)
|
||||||
{
|
{
|
||||||
OpenTelemetryApiEventSource.Log.FailedToExtractBaggage(nameof(BaggageFormat), "null carrier");
|
OpenTelemetryApiEventSource.Log.FailedToExtractBaggage(nameof(BaggagePropagator), "null carrier");
|
||||||
return context;
|
return context;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (getter == null)
|
if (getter == null)
|
||||||
{
|
{
|
||||||
OpenTelemetryApiEventSource.Log.FailedToExtractBaggage(nameof(BaggageFormat), "null getter");
|
OpenTelemetryApiEventSource.Log.FailedToExtractBaggage(nameof(BaggagePropagator), "null getter");
|
||||||
return context;
|
return context;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -72,7 +72,7 @@ namespace OpenTelemetry.Context.Propagation
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
OpenTelemetryApiEventSource.Log.BaggageExtractException(nameof(BaggageFormat), ex);
|
OpenTelemetryApiEventSource.Log.BaggageExtractException(nameof(BaggagePropagator), ex);
|
||||||
}
|
}
|
||||||
|
|
||||||
return context;
|
return context;
|
||||||
|
|
@ -83,13 +83,13 @@ namespace OpenTelemetry.Context.Propagation
|
||||||
{
|
{
|
||||||
if (carrier == null)
|
if (carrier == null)
|
||||||
{
|
{
|
||||||
OpenTelemetryApiEventSource.Log.FailedToInjectBaggage(nameof(BaggageFormat), "null carrier");
|
OpenTelemetryApiEventSource.Log.FailedToInjectBaggage(nameof(BaggagePropagator), "null carrier");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (setter == null)
|
if (setter == null)
|
||||||
{
|
{
|
||||||
OpenTelemetryApiEventSource.Log.FailedToInjectBaggage(nameof(BaggageFormat), "null setter");
|
OpenTelemetryApiEventSource.Log.FailedToInjectBaggage(nameof(BaggagePropagator), "null setter");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
// <copyright file="TraceContextFormat.cs" company="OpenTelemetry Authors">
|
// <copyright file="TextMapPropagator.cs" company="OpenTelemetry Authors">
|
||||||
// Copyright The OpenTelemetry Authors
|
// Copyright The OpenTelemetry Authors
|
||||||
//
|
//
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
|
@ -26,7 +26,7 @@ namespace OpenTelemetry.Context.Propagation
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// W3C trace context text wire protocol formatter. See https://github.com/w3c/distributed-tracing/.
|
/// W3C trace context text wire protocol formatter. See https://github.com/w3c/distributed-tracing/.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class TraceContextFormat : ITextFormat
|
public class TextMapPropagator : ITextFormat
|
||||||
{
|
{
|
||||||
private const string TraceParent = "traceparent";
|
private const string TraceParent = "traceparent";
|
||||||
private const string TraceState = "tracestate";
|
private const string TraceState = "tracestate";
|
||||||
|
|
@ -53,13 +53,13 @@ namespace OpenTelemetry.Context.Propagation
|
||||||
|
|
||||||
if (carrier == null)
|
if (carrier == null)
|
||||||
{
|
{
|
||||||
OpenTelemetryApiEventSource.Log.FailedToExtractActivityContext(nameof(TraceContextFormat), "null carrier");
|
OpenTelemetryApiEventSource.Log.FailedToExtractActivityContext(nameof(TextMapPropagator), "null carrier");
|
||||||
return context;
|
return context;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (getter == null)
|
if (getter == null)
|
||||||
{
|
{
|
||||||
OpenTelemetryApiEventSource.Log.FailedToExtractActivityContext(nameof(TraceContextFormat), "null getter");
|
OpenTelemetryApiEventSource.Log.FailedToExtractActivityContext(nameof(TextMapPropagator), "null getter");
|
||||||
return context;
|
return context;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -94,7 +94,7 @@ namespace OpenTelemetry.Context.Propagation
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
OpenTelemetryApiEventSource.Log.ActivityContextExtractException(nameof(TraceContextFormat), ex);
|
OpenTelemetryApiEventSource.Log.ActivityContextExtractException(nameof(TextMapPropagator), ex);
|
||||||
}
|
}
|
||||||
|
|
||||||
// in case of exception indicate to upstream that there is no parseable context from the top
|
// in case of exception indicate to upstream that there is no parseable context from the top
|
||||||
|
|
@ -106,19 +106,19 @@ namespace OpenTelemetry.Context.Propagation
|
||||||
{
|
{
|
||||||
if (context.ActivityContext.TraceId == default || context.ActivityContext.SpanId == default)
|
if (context.ActivityContext.TraceId == default || context.ActivityContext.SpanId == default)
|
||||||
{
|
{
|
||||||
OpenTelemetryApiEventSource.Log.FailedToInjectActivityContext(nameof(TraceContextFormat), "Invalid context");
|
OpenTelemetryApiEventSource.Log.FailedToInjectActivityContext(nameof(TextMapPropagator), "Invalid context");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (carrier == null)
|
if (carrier == null)
|
||||||
{
|
{
|
||||||
OpenTelemetryApiEventSource.Log.FailedToInjectActivityContext(nameof(TraceContextFormat), "null carrier");
|
OpenTelemetryApiEventSource.Log.FailedToInjectActivityContext(nameof(TextMapPropagator), "null carrier");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (setter == null)
|
if (setter == null)
|
||||||
{
|
{
|
||||||
OpenTelemetryApiEventSource.Log.FailedToInjectActivityContext(nameof(TraceContextFormat), "null setter");
|
OpenTelemetryApiEventSource.Log.FailedToInjectActivityContext(nameof(TextMapPropagator), "null setter");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -26,12 +26,12 @@ namespace OpenTelemetry.Instrumentation.AspNet
|
||||||
public class AspNetInstrumentationOptions
|
public class AspNetInstrumentationOptions
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets <see cref="ITextFormat"/> for context propagation. Default value: <see cref="CompositePropagator"/> with <see cref="TraceContextFormat"/> & <see cref="BaggageFormat"/>.
|
/// Gets or sets <see cref="ITextFormat"/> for context propagation. Default value: <see cref="CompositePropagator"/> with <see cref="TextMapPropagator"/> & <see cref="BaggagePropagator"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public ITextFormat TextFormat { get; set; } = new CompositePropagator(new ITextFormat[]
|
public ITextFormat TextFormat { get; set; } = new CompositePropagator(new ITextFormat[]
|
||||||
{
|
{
|
||||||
new TraceContextFormat(),
|
new TextMapPropagator(),
|
||||||
new BaggageFormat(),
|
new BaggagePropagator(),
|
||||||
});
|
});
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
|
||||||
|
|
@ -63,7 +63,7 @@ namespace OpenTelemetry.Instrumentation.AspNet.Implementation
|
||||||
var request = context.Request;
|
var request = context.Request;
|
||||||
var requestValues = request.Unvalidated;
|
var requestValues = request.Unvalidated;
|
||||||
|
|
||||||
if (!(this.options.TextFormat is TraceContextFormat))
|
if (!(this.options.TextFormat is TextMapPropagator))
|
||||||
{
|
{
|
||||||
var ctx = this.options.TextFormat.Extract(default, request, HttpRequestHeaderValuesGetter);
|
var ctx = this.options.TextFormat.Extract(default, request, HttpRequestHeaderValuesGetter);
|
||||||
|
|
||||||
|
|
@ -125,7 +125,7 @@ namespace OpenTelemetry.Instrumentation.AspNet.Implementation
|
||||||
Activity activityToEnrich = activity;
|
Activity activityToEnrich = activity;
|
||||||
Activity createdActivity = null;
|
Activity createdActivity = null;
|
||||||
|
|
||||||
if (!(this.options.TextFormat is TraceContextFormat))
|
if (!(this.options.TextFormat is TextMapPropagator))
|
||||||
{
|
{
|
||||||
// If using custom context propagator, then the activity here
|
// If using custom context propagator, then the activity here
|
||||||
// could be either the one from Asp.Net, or the one
|
// could be either the one from Asp.Net, or the one
|
||||||
|
|
@ -190,7 +190,7 @@ namespace OpenTelemetry.Instrumentation.AspNet.Implementation
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(this.options.TextFormat is TraceContextFormat))
|
if (!(this.options.TextFormat is TextMapPropagator))
|
||||||
{
|
{
|
||||||
if (activity.OperationName.Equals(ActivityNameByHttpInListener))
|
if (activity.OperationName.Equals(ActivityNameByHttpInListener))
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -26,12 +26,12 @@ namespace OpenTelemetry.Instrumentation.AspNetCore
|
||||||
public class AspNetCoreInstrumentationOptions
|
public class AspNetCoreInstrumentationOptions
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets <see cref="ITextFormat"/> for context propagation. Default value: <see cref="CompositePropagator"/> with <see cref="TraceContextFormat"/> & <see cref="BaggageFormat"/>.
|
/// Gets or sets <see cref="ITextFormat"/> for context propagation. Default value: <see cref="CompositePropagator"/> with <see cref="TextMapPropagator"/> & <see cref="BaggagePropagator"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public ITextFormat TextFormat { get; set; } = new CompositePropagator(new ITextFormat[]
|
public ITextFormat TextFormat { get; set; } = new CompositePropagator(new ITextFormat[]
|
||||||
{
|
{
|
||||||
new TraceContextFormat(),
|
new TextMapPropagator(),
|
||||||
new BaggageFormat(),
|
new BaggagePropagator(),
|
||||||
});
|
});
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
|
||||||
|
|
@ -69,7 +69,7 @@ namespace OpenTelemetry.Instrumentation.AspNetCore.Implementation
|
||||||
}
|
}
|
||||||
|
|
||||||
var request = context.Request;
|
var request = context.Request;
|
||||||
if (!this.hostingSupportsW3C || !(this.options.TextFormat is TraceContextFormat))
|
if (!this.hostingSupportsW3C || !(this.options.TextFormat is TextMapPropagator))
|
||||||
{
|
{
|
||||||
var ctx = this.options.TextFormat.Extract(default, request, HttpRequestHeaderValuesGetter);
|
var ctx = this.options.TextFormat.Extract(default, request, HttpRequestHeaderValuesGetter);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,7 @@
|
||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
// </copyright>
|
// </copyright>
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Net.Http;
|
using System.Net.Http;
|
||||||
using System.Runtime.CompilerServices;
|
using System.Runtime.CompilerServices;
|
||||||
|
|
@ -32,12 +33,12 @@ namespace OpenTelemetry.Instrumentation.Http
|
||||||
public bool SetHttpFlavor { get; set; }
|
public bool SetHttpFlavor { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets <see cref="ITextFormat"/> for context propagation. Default value: <see cref="CompositePropagator"/> with <see cref="TraceContextFormat"/> & <see cref="BaggageFormat"/>.
|
/// Gets or sets <see cref="ITextFormat"/> for context propagation. Default value: <see cref="CompositePropagator"/> with <see cref="TextMapPropagator"/> & <see cref="BaggagePropagator"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public ITextFormat TextFormat { get; set; } = new CompositePropagator(new ITextFormat[]
|
public ITextFormat TextFormat { get; set; } = new CompositePropagator(new ITextFormat[]
|
||||||
{
|
{
|
||||||
new TraceContextFormat(),
|
new TextMapPropagator(),
|
||||||
new BaggageFormat(),
|
new BaggagePropagator(),
|
||||||
});
|
});
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,7 @@
|
||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
// </copyright>
|
// </copyright>
|
||||||
|
|
||||||
#if NETFRAMEWORK
|
#if NETFRAMEWORK
|
||||||
using System;
|
using System;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
|
|
@ -32,12 +33,12 @@ namespace OpenTelemetry.Instrumentation.Http
|
||||||
public bool SetHttpFlavor { get; set; }
|
public bool SetHttpFlavor { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets <see cref="ITextFormat"/> for context propagation. Default value: <see cref="CompositePropagator"/> with <see cref="TraceContextFormat"/> & <see cref="BaggageFormat"/>.
|
/// Gets or sets <see cref="ITextFormat"/> for context propagation. Default value: <see cref="CompositePropagator"/> with <see cref="TextMapPropagator"/> & <see cref="BaggagePropagator"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public ITextFormat TextFormat { get; set; } = new CompositePropagator(new ITextFormat[]
|
public ITextFormat TextFormat { get; set; } = new CompositePropagator(new ITextFormat[]
|
||||||
{
|
{
|
||||||
new TraceContextFormat(),
|
new TextMapPropagator(),
|
||||||
new BaggageFormat(),
|
new BaggagePropagator(),
|
||||||
});
|
});
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
|
||||||
|
|
@ -111,7 +111,7 @@ namespace OpenTelemetry.Instrumentation.Http.Implementation
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(this.httpClientSupportsW3C && this.options.TextFormat is TraceContextFormat))
|
if (!(this.httpClientSupportsW3C && this.options.TextFormat is TextMapPropagator))
|
||||||
{
|
{
|
||||||
this.options.TextFormat.Inject(new PropagationContext(activity.Context, Baggage.Current), request, HttpRequestMessageHeaderValueSetter);
|
this.options.TextFormat.Inject(new PropagationContext(activity.Context, Baggage.Current), request, HttpRequestMessageHeaderValueSetter);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -39,7 +39,7 @@ namespace OpenTelemetry.Shims.OpenTracing.Tests
|
||||||
Assert.Throws<ArgumentNullException>(() => new TracerShim(null, null));
|
Assert.Throws<ArgumentNullException>(() => new TracerShim(null, null));
|
||||||
|
|
||||||
// null tracer
|
// null tracer
|
||||||
Assert.Throws<ArgumentNullException>(() => new TracerShim(null, new TraceContextFormat()));
|
Assert.Throws<ArgumentNullException>(() => new TracerShim(null, new TextMapPropagator()));
|
||||||
|
|
||||||
// null context format
|
// null context format
|
||||||
var tracerMock = new Mock<Trace.Tracer>();
|
var tracerMock = new Mock<Trace.Tracer>();
|
||||||
|
|
@ -50,7 +50,7 @@ namespace OpenTelemetry.Shims.OpenTracing.Tests
|
||||||
public void ScopeManager_NotNull()
|
public void ScopeManager_NotNull()
|
||||||
{
|
{
|
||||||
var tracer = TracerProvider.Default.GetTracer(TracerName);
|
var tracer = TracerProvider.Default.GetTracer(TracerName);
|
||||||
var shim = new TracerShim(tracer, new TraceContextFormat());
|
var shim = new TracerShim(tracer, new TextMapPropagator());
|
||||||
|
|
||||||
// Internals of the ScopeManagerShim tested elsewhere
|
// Internals of the ScopeManagerShim tested elsewhere
|
||||||
Assert.NotNull(shim.ScopeManager as ScopeManagerShim);
|
Assert.NotNull(shim.ScopeManager as ScopeManagerShim);
|
||||||
|
|
@ -60,7 +60,7 @@ namespace OpenTelemetry.Shims.OpenTracing.Tests
|
||||||
public void BuildSpan_NotNull()
|
public void BuildSpan_NotNull()
|
||||||
{
|
{
|
||||||
var tracer = TracerProvider.Default.GetTracer(TracerName);
|
var tracer = TracerProvider.Default.GetTracer(TracerName);
|
||||||
var shim = new TracerShim(tracer, new TraceContextFormat());
|
var shim = new TracerShim(tracer, new TextMapPropagator());
|
||||||
|
|
||||||
// Internals of the SpanBuilderShim tested elsewhere
|
// Internals of the SpanBuilderShim tested elsewhere
|
||||||
Assert.NotNull(shim.BuildSpan("foo") as SpanBuilderShim);
|
Assert.NotNull(shim.BuildSpan("foo") as SpanBuilderShim);
|
||||||
|
|
@ -70,7 +70,7 @@ namespace OpenTelemetry.Shims.OpenTracing.Tests
|
||||||
public void Inject_ArgumentValidation()
|
public void Inject_ArgumentValidation()
|
||||||
{
|
{
|
||||||
var tracer = TracerProvider.Default.GetTracer(TracerName);
|
var tracer = TracerProvider.Default.GetTracer(TracerName);
|
||||||
var shim = new TracerShim(tracer, new TraceContextFormat());
|
var shim = new TracerShim(tracer, new TextMapPropagator());
|
||||||
|
|
||||||
var spanContextShim = new SpanContextShim(new SpanContext(ActivityTraceId.CreateRandom(), ActivitySpanId.CreateRandom(), ActivityTraceFlags.None));
|
var spanContextShim = new SpanContextShim(new SpanContext(ActivityTraceId.CreateRandom(), ActivitySpanId.CreateRandom(), ActivityTraceFlags.None));
|
||||||
var mockFormat = new Mock<IFormat<ITextMap>>();
|
var mockFormat = new Mock<IFormat<ITextMap>>();
|
||||||
|
|
@ -86,7 +86,7 @@ namespace OpenTelemetry.Shims.OpenTracing.Tests
|
||||||
public void Inject_UnknownFormatIgnored()
|
public void Inject_UnknownFormatIgnored()
|
||||||
{
|
{
|
||||||
var tracer = TracerProvider.Default.GetTracer(TracerName);
|
var tracer = TracerProvider.Default.GetTracer(TracerName);
|
||||||
var shim = new TracerShim(tracer, new TraceContextFormat());
|
var shim = new TracerShim(tracer, new TextMapPropagator());
|
||||||
|
|
||||||
var spanContextShim = new SpanContextShim(new SpanContext(ActivityTraceId.CreateRandom(), ActivitySpanId.CreateRandom(), ActivityTraceFlags.Recorded));
|
var spanContextShim = new SpanContextShim(new SpanContext(ActivityTraceId.CreateRandom(), ActivitySpanId.CreateRandom(), ActivityTraceFlags.Recorded));
|
||||||
|
|
||||||
|
|
@ -102,7 +102,7 @@ namespace OpenTelemetry.Shims.OpenTracing.Tests
|
||||||
public void Extract_ArgumentValidation()
|
public void Extract_ArgumentValidation()
|
||||||
{
|
{
|
||||||
var tracer = TracerProvider.Default.GetTracer(TracerName);
|
var tracer = TracerProvider.Default.GetTracer(TracerName);
|
||||||
var shim = new TracerShim(tracer, new TraceContextFormat());
|
var shim = new TracerShim(tracer, new TextMapPropagator());
|
||||||
|
|
||||||
Assert.Throws<ArgumentNullException>(() => shim.Extract(null, new Mock<ITextMap>().Object));
|
Assert.Throws<ArgumentNullException>(() => shim.Extract(null, new Mock<ITextMap>().Object));
|
||||||
Assert.Throws<ArgumentNullException>(() => shim.Extract(new Mock<IFormat<ITextMap>>().Object, null));
|
Assert.Throws<ArgumentNullException>(() => shim.Extract(new Mock<IFormat<ITextMap>>().Object, null));
|
||||||
|
|
@ -112,7 +112,7 @@ namespace OpenTelemetry.Shims.OpenTracing.Tests
|
||||||
public void Extract_UnknownFormatIgnored()
|
public void Extract_UnknownFormatIgnored()
|
||||||
{
|
{
|
||||||
var tracer = TracerProvider.Default.GetTracer(TracerName);
|
var tracer = TracerProvider.Default.GetTracer(TracerName);
|
||||||
var shim = new TracerShim(tracer, new TraceContextFormat());
|
var shim = new TracerShim(tracer, new TextMapPropagator());
|
||||||
|
|
||||||
var spanContextShim = new SpanContextShim(new SpanContext(ActivityTraceId.CreateRandom(), ActivitySpanId.CreateRandom(), ActivityTraceFlags.None));
|
var spanContextShim = new SpanContextShim(new SpanContext(ActivityTraceId.CreateRandom(), ActivitySpanId.CreateRandom(), ActivityTraceFlags.None));
|
||||||
|
|
||||||
|
|
@ -128,11 +128,11 @@ namespace OpenTelemetry.Shims.OpenTracing.Tests
|
||||||
public void Extract_InvalidTraceParent()
|
public void Extract_InvalidTraceParent()
|
||||||
{
|
{
|
||||||
var tracer = TracerProvider.Default.GetTracer(TracerName);
|
var tracer = TracerProvider.Default.GetTracer(TracerName);
|
||||||
var shim = new TracerShim(tracer, new TraceContextFormat());
|
var shim = new TracerShim(tracer, new TextMapPropagator());
|
||||||
|
|
||||||
var mockCarrier = new Mock<ITextMap>();
|
var mockCarrier = new Mock<ITextMap>();
|
||||||
|
|
||||||
// The ProxyTracer uses OpenTelemetry.Context.Propagation.TraceContextFormat, so we need to satisfy the traceparent key at the least
|
// The ProxyTracer uses OpenTelemetry.Context.Propagation.TextMapPropagator, so we need to satisfy the traceparent key at the least
|
||||||
var carrierMap = new Dictionary<string, string>
|
var carrierMap = new Dictionary<string, string>
|
||||||
{
|
{
|
||||||
// This is an invalid traceparent value
|
// This is an invalid traceparent value
|
||||||
|
|
@ -155,7 +155,7 @@ namespace OpenTelemetry.Shims.OpenTracing.Tests
|
||||||
|
|
||||||
var spanContextShim = new SpanContextShim(new SpanContext(ActivityTraceId.CreateRandom(), ActivitySpanId.CreateRandom(), ActivityTraceFlags.None));
|
var spanContextShim = new SpanContextShim(new SpanContext(ActivityTraceId.CreateRandom(), ActivitySpanId.CreateRandom(), ActivityTraceFlags.None));
|
||||||
|
|
||||||
var format = new TraceContextFormat();
|
var format = new TextMapPropagator();
|
||||||
|
|
||||||
var tracer = TracerProvider.Default.GetTracer(TracerName);
|
var tracer = TracerProvider.Default.GetTracer(TracerName);
|
||||||
var shim = new TracerShim(tracer, format);
|
var shim = new TracerShim(tracer, format);
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
// <copyright file="B3FormatTest.cs" company="OpenTelemetry Authors">
|
// <copyright file="B3PropagatorTest.cs" company="OpenTelemetry Authors">
|
||||||
// Copyright The OpenTelemetry Authors
|
// Copyright The OpenTelemetry Authors
|
||||||
//
|
//
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
|
@ -21,7 +21,7 @@ using Xunit.Abstractions;
|
||||||
|
|
||||||
namespace OpenTelemetry.Context.Propagation.Tests
|
namespace OpenTelemetry.Context.Propagation.Tests
|
||||||
{
|
{
|
||||||
public class B3FormatTest
|
public class B3PropagatorTest
|
||||||
{
|
{
|
||||||
private const string TraceIdBase16 = "ff000000000000000000000000000041";
|
private const string TraceIdBase16 = "ff000000000000000000000000000041";
|
||||||
private const string TraceIdBase16EightBytes = "0000000000000041";
|
private const string TraceIdBase16EightBytes = "0000000000000041";
|
||||||
|
|
@ -42,12 +42,12 @@ namespace OpenTelemetry.Context.Propagation.Tests
|
||||||
return new string[] { v };
|
return new string[] { v };
|
||||||
};
|
};
|
||||||
|
|
||||||
private readonly B3Format b3Format = new B3Format();
|
private readonly B3Propagator b3propagator = new B3Propagator();
|
||||||
private readonly B3Format b3FormatSingleHeader = new B3Format(true);
|
private readonly B3Propagator b3PropagatorSingleHeader = new B3Propagator(true);
|
||||||
|
|
||||||
private readonly ITestOutputHelper output;
|
private readonly ITestOutputHelper output;
|
||||||
|
|
||||||
public B3FormatTest(ITestOutputHelper output)
|
public B3PropagatorTest(ITestOutputHelper output)
|
||||||
{
|
{
|
||||||
this.output = output;
|
this.output = output;
|
||||||
}
|
}
|
||||||
|
|
@ -56,8 +56,8 @@ namespace OpenTelemetry.Context.Propagation.Tests
|
||||||
public void Serialize_SampledContext()
|
public void Serialize_SampledContext()
|
||||||
{
|
{
|
||||||
var carrier = new Dictionary<string, string>();
|
var carrier = new Dictionary<string, string>();
|
||||||
this.b3Format.Inject(new PropagationContext(new ActivityContext(TraceId, SpanId, TraceOptions), default), carrier, Setter);
|
this.b3propagator.Inject(new PropagationContext(new ActivityContext(TraceId, SpanId, TraceOptions), default), carrier, Setter);
|
||||||
this.ContainsExactly(carrier, new Dictionary<string, string> { { B3Format.XB3TraceId, TraceIdBase16 }, { B3Format.XB3SpanId, SpanIdBase16 }, { B3Format.XB3Sampled, "1" } });
|
this.ContainsExactly(carrier, new Dictionary<string, string> { { B3Propagator.XB3TraceId, TraceIdBase16 }, { B3Propagator.XB3SpanId, SpanIdBase16 }, { B3Propagator.XB3Sampled, "1" } });
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
|
|
@ -66,8 +66,8 @@ namespace OpenTelemetry.Context.Propagation.Tests
|
||||||
var carrier = new Dictionary<string, string>();
|
var carrier = new Dictionary<string, string>();
|
||||||
var context = new ActivityContext(TraceId, SpanId, ActivityTraceFlags.None);
|
var context = new ActivityContext(TraceId, SpanId, ActivityTraceFlags.None);
|
||||||
this.output.WriteLine(context.ToString());
|
this.output.WriteLine(context.ToString());
|
||||||
this.b3Format.Inject(new PropagationContext(context, default), carrier, Setter);
|
this.b3propagator.Inject(new PropagationContext(context, default), carrier, Setter);
|
||||||
this.ContainsExactly(carrier, new Dictionary<string, string> { { B3Format.XB3TraceId, TraceIdBase16 }, { B3Format.XB3SpanId, SpanIdBase16 } });
|
this.ContainsExactly(carrier, new Dictionary<string, string> { { B3Propagator.XB3TraceId, TraceIdBase16 }, { B3Propagator.XB3SpanId, SpanIdBase16 } });
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
|
|
@ -75,10 +75,10 @@ namespace OpenTelemetry.Context.Propagation.Tests
|
||||||
{
|
{
|
||||||
var headersNotSampled = new Dictionary<string, string>
|
var headersNotSampled = new Dictionary<string, string>
|
||||||
{
|
{
|
||||||
{ B3Format.XB3TraceId, TraceIdBase16 }, { B3Format.XB3SpanId, SpanIdBase16 },
|
{ B3Propagator.XB3TraceId, TraceIdBase16 }, { B3Propagator.XB3SpanId, SpanIdBase16 },
|
||||||
};
|
};
|
||||||
var spanContext = new ActivityContext(TraceId, SpanId, ActivityTraceFlags.None);
|
var spanContext = new ActivityContext(TraceId, SpanId, ActivityTraceFlags.None);
|
||||||
Assert.Equal(new PropagationContext(spanContext, default), this.b3Format.Extract(default, headersNotSampled, Getter));
|
Assert.Equal(new PropagationContext(spanContext, default), this.b3propagator.Extract(default, headersNotSampled, Getter));
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
|
|
@ -86,10 +86,10 @@ namespace OpenTelemetry.Context.Propagation.Tests
|
||||||
{
|
{
|
||||||
var headersSampled = new Dictionary<string, string>
|
var headersSampled = new Dictionary<string, string>
|
||||||
{
|
{
|
||||||
{ B3Format.XB3TraceId, TraceIdBase16 }, { B3Format.XB3SpanId, SpanIdBase16 }, { B3Format.XB3Sampled, "1" },
|
{ B3Propagator.XB3TraceId, TraceIdBase16 }, { B3Propagator.XB3SpanId, SpanIdBase16 }, { B3Propagator.XB3Sampled, "1" },
|
||||||
};
|
};
|
||||||
var activityContext = new ActivityContext(TraceId, SpanId, TraceOptions);
|
var activityContext = new ActivityContext(TraceId, SpanId, TraceOptions);
|
||||||
Assert.Equal(new PropagationContext(activityContext, default), this.b3Format.Extract(default, headersSampled, Getter));
|
Assert.Equal(new PropagationContext(activityContext, default), this.b3propagator.Extract(default, headersSampled, Getter));
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
|
|
@ -97,10 +97,10 @@ namespace OpenTelemetry.Context.Propagation.Tests
|
||||||
{
|
{
|
||||||
var headersNotSampled = new Dictionary<string, string>
|
var headersNotSampled = new Dictionary<string, string>
|
||||||
{
|
{
|
||||||
{ B3Format.XB3TraceId, TraceIdBase16 }, { B3Format.XB3SpanId, SpanIdBase16 }, { B3Format.XB3Sampled, "0" },
|
{ B3Propagator.XB3TraceId, TraceIdBase16 }, { B3Propagator.XB3SpanId, SpanIdBase16 }, { B3Propagator.XB3Sampled, "0" },
|
||||||
};
|
};
|
||||||
var activityContext = new ActivityContext(TraceId, SpanId, ActivityTraceFlags.None);
|
var activityContext = new ActivityContext(TraceId, SpanId, ActivityTraceFlags.None);
|
||||||
Assert.Equal(new PropagationContext(activityContext, default), this.b3Format.Extract(default, headersNotSampled, Getter));
|
Assert.Equal(new PropagationContext(activityContext, default), this.b3propagator.Extract(default, headersNotSampled, Getter));
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
|
|
@ -108,10 +108,10 @@ namespace OpenTelemetry.Context.Propagation.Tests
|
||||||
{
|
{
|
||||||
var headersFlagSampled = new Dictionary<string, string>
|
var headersFlagSampled = new Dictionary<string, string>
|
||||||
{
|
{
|
||||||
{ B3Format.XB3TraceId, TraceIdBase16 }, { B3Format.XB3SpanId, SpanIdBase16 }, { B3Format.XB3Flags, "1" },
|
{ B3Propagator.XB3TraceId, TraceIdBase16 }, { B3Propagator.XB3SpanId, SpanIdBase16 }, { B3Propagator.XB3Flags, "1" },
|
||||||
};
|
};
|
||||||
var activityContext = new ActivityContext(TraceId, SpanId, TraceOptions);
|
var activityContext = new ActivityContext(TraceId, SpanId, TraceOptions);
|
||||||
Assert.Equal(new PropagationContext(activityContext, default), this.b3Format.Extract(default, headersFlagSampled, Getter));
|
Assert.Equal(new PropagationContext(activityContext, default), this.b3propagator.Extract(default, headersFlagSampled, Getter));
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
|
|
@ -119,10 +119,10 @@ namespace OpenTelemetry.Context.Propagation.Tests
|
||||||
{
|
{
|
||||||
var headersFlagNotSampled = new Dictionary<string, string>
|
var headersFlagNotSampled = new Dictionary<string, string>
|
||||||
{
|
{
|
||||||
{ B3Format.XB3TraceId, TraceIdBase16 }, { B3Format.XB3SpanId, SpanIdBase16 }, { B3Format.XB3Flags, "0" },
|
{ B3Propagator.XB3TraceId, TraceIdBase16 }, { B3Propagator.XB3SpanId, SpanIdBase16 }, { B3Propagator.XB3Flags, "0" },
|
||||||
};
|
};
|
||||||
var activityContext = new ActivityContext(TraceId, SpanId, ActivityTraceFlags.None);
|
var activityContext = new ActivityContext(TraceId, SpanId, ActivityTraceFlags.None);
|
||||||
Assert.Equal(new PropagationContext(activityContext, default), this.b3Format.Extract(default, headersFlagNotSampled, Getter));
|
Assert.Equal(new PropagationContext(activityContext, default), this.b3propagator.Extract(default, headersFlagNotSampled, Getter));
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
|
|
@ -130,12 +130,12 @@ namespace OpenTelemetry.Context.Propagation.Tests
|
||||||
{
|
{
|
||||||
var headersEightBytes = new Dictionary<string, string>
|
var headersEightBytes = new Dictionary<string, string>
|
||||||
{
|
{
|
||||||
{ B3Format.XB3TraceId, TraceIdBase16EightBytes },
|
{ B3Propagator.XB3TraceId, TraceIdBase16EightBytes },
|
||||||
{ B3Format.XB3SpanId, SpanIdBase16 },
|
{ B3Propagator.XB3SpanId, SpanIdBase16 },
|
||||||
{ B3Format.XB3Sampled, "1" },
|
{ B3Propagator.XB3Sampled, "1" },
|
||||||
};
|
};
|
||||||
var activityContext = new ActivityContext(TraceIdEightBytes, SpanId, TraceOptions);
|
var activityContext = new ActivityContext(TraceIdEightBytes, SpanId, TraceOptions);
|
||||||
Assert.Equal(new PropagationContext(activityContext, default), this.b3Format.Extract(default, headersEightBytes, Getter));
|
Assert.Equal(new PropagationContext(activityContext, default), this.b3propagator.Extract(default, headersEightBytes, Getter));
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
|
|
@ -143,10 +143,10 @@ namespace OpenTelemetry.Context.Propagation.Tests
|
||||||
{
|
{
|
||||||
var headersEightBytes = new Dictionary<string, string>
|
var headersEightBytes = new Dictionary<string, string>
|
||||||
{
|
{
|
||||||
{ B3Format.XB3TraceId, TraceIdBase16EightBytes }, { B3Format.XB3SpanId, SpanIdBase16 },
|
{ B3Propagator.XB3TraceId, TraceIdBase16EightBytes }, { B3Propagator.XB3SpanId, SpanIdBase16 },
|
||||||
};
|
};
|
||||||
var activityContext = new ActivityContext(TraceIdEightBytes, SpanId, ActivityTraceFlags.None);
|
var activityContext = new ActivityContext(TraceIdEightBytes, SpanId, ActivityTraceFlags.None);
|
||||||
Assert.Equal(new PropagationContext(activityContext, default), this.b3Format.Extract(default, headersEightBytes, Getter));
|
Assert.Equal(new PropagationContext(activityContext, default), this.b3propagator.Extract(default, headersEightBytes, Getter));
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
|
|
@ -154,9 +154,9 @@ namespace OpenTelemetry.Context.Propagation.Tests
|
||||||
{
|
{
|
||||||
var invalidHeaders = new Dictionary<string, string>
|
var invalidHeaders = new Dictionary<string, string>
|
||||||
{
|
{
|
||||||
{ B3Format.XB3TraceId, InvalidId }, { B3Format.XB3SpanId, SpanIdBase16 },
|
{ B3Propagator.XB3TraceId, InvalidId }, { B3Propagator.XB3SpanId, SpanIdBase16 },
|
||||||
};
|
};
|
||||||
Assert.Equal(default, this.b3Format.Extract(default, invalidHeaders, Getter));
|
Assert.Equal(default, this.b3propagator.Extract(default, invalidHeaders, Getter));
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
|
|
@ -164,17 +164,17 @@ namespace OpenTelemetry.Context.Propagation.Tests
|
||||||
{
|
{
|
||||||
var invalidHeaders = new Dictionary<string, string>
|
var invalidHeaders = new Dictionary<string, string>
|
||||||
{
|
{
|
||||||
{ B3Format.XB3TraceId, InvalidSizeId }, { B3Format.XB3SpanId, SpanIdBase16 },
|
{ B3Propagator.XB3TraceId, InvalidSizeId }, { B3Propagator.XB3SpanId, SpanIdBase16 },
|
||||||
};
|
};
|
||||||
|
|
||||||
Assert.Equal(default, this.b3Format.Extract(default, invalidHeaders, Getter));
|
Assert.Equal(default, this.b3propagator.Extract(default, invalidHeaders, Getter));
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void ParseMissingTraceId()
|
public void ParseMissingTraceId()
|
||||||
{
|
{
|
||||||
var invalidHeaders = new Dictionary<string, string> { { B3Format.XB3SpanId, SpanIdBase16 }, };
|
var invalidHeaders = new Dictionary<string, string> { { B3Propagator.XB3SpanId, SpanIdBase16 }, };
|
||||||
Assert.Equal(default, this.b3Format.Extract(default, invalidHeaders, Getter));
|
Assert.Equal(default, this.b3propagator.Extract(default, invalidHeaders, Getter));
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
|
|
@ -182,9 +182,9 @@ namespace OpenTelemetry.Context.Propagation.Tests
|
||||||
{
|
{
|
||||||
var invalidHeaders = new Dictionary<string, string>
|
var invalidHeaders = new Dictionary<string, string>
|
||||||
{
|
{
|
||||||
{ B3Format.XB3TraceId, TraceIdBase16 }, { B3Format.XB3SpanId, InvalidId },
|
{ B3Propagator.XB3TraceId, TraceIdBase16 }, { B3Propagator.XB3SpanId, InvalidId },
|
||||||
};
|
};
|
||||||
Assert.Equal(default, this.b3Format.Extract(default, invalidHeaders, Getter));
|
Assert.Equal(default, this.b3propagator.Extract(default, invalidHeaders, Getter));
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
|
|
@ -192,16 +192,16 @@ namespace OpenTelemetry.Context.Propagation.Tests
|
||||||
{
|
{
|
||||||
var invalidHeaders = new Dictionary<string, string>
|
var invalidHeaders = new Dictionary<string, string>
|
||||||
{
|
{
|
||||||
{ B3Format.XB3TraceId, TraceIdBase16 }, { B3Format.XB3SpanId, InvalidSizeId },
|
{ B3Propagator.XB3TraceId, TraceIdBase16 }, { B3Propagator.XB3SpanId, InvalidSizeId },
|
||||||
};
|
};
|
||||||
Assert.Equal(default, this.b3Format.Extract(default, invalidHeaders, Getter));
|
Assert.Equal(default, this.b3propagator.Extract(default, invalidHeaders, Getter));
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void ParseMissingSpanId()
|
public void ParseMissingSpanId()
|
||||||
{
|
{
|
||||||
var invalidHeaders = new Dictionary<string, string> { { B3Format.XB3TraceId, TraceIdBase16 } };
|
var invalidHeaders = new Dictionary<string, string> { { B3Propagator.XB3TraceId, TraceIdBase16 } };
|
||||||
Assert.Equal(default, this.b3Format.Extract(default, invalidHeaders, Getter));
|
Assert.Equal(default, this.b3propagator.Extract(default, invalidHeaders, Getter));
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
|
|
@ -209,8 +209,8 @@ namespace OpenTelemetry.Context.Propagation.Tests
|
||||||
{
|
{
|
||||||
var carrier = new Dictionary<string, string>();
|
var carrier = new Dictionary<string, string>();
|
||||||
var activityContext = new ActivityContext(TraceId, SpanId, TraceOptions);
|
var activityContext = new ActivityContext(TraceId, SpanId, TraceOptions);
|
||||||
this.b3FormatSingleHeader.Inject(new PropagationContext(activityContext, default), carrier, Setter);
|
this.b3PropagatorSingleHeader.Inject(new PropagationContext(activityContext, default), carrier, Setter);
|
||||||
this.ContainsExactly(carrier, new Dictionary<string, string> { { B3Format.XB3Combined, $"{TraceIdBase16}-{SpanIdBase16}-1" } });
|
this.ContainsExactly(carrier, new Dictionary<string, string> { { B3Propagator.XB3Combined, $"{TraceIdBase16}-{SpanIdBase16}-1" } });
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
|
|
@ -219,8 +219,8 @@ namespace OpenTelemetry.Context.Propagation.Tests
|
||||||
var carrier = new Dictionary<string, string>();
|
var carrier = new Dictionary<string, string>();
|
||||||
var activityContext = new ActivityContext(TraceId, SpanId, ActivityTraceFlags.None);
|
var activityContext = new ActivityContext(TraceId, SpanId, ActivityTraceFlags.None);
|
||||||
this.output.WriteLine(activityContext.ToString());
|
this.output.WriteLine(activityContext.ToString());
|
||||||
this.b3FormatSingleHeader.Inject(new PropagationContext(activityContext, default), carrier, Setter);
|
this.b3PropagatorSingleHeader.Inject(new PropagationContext(activityContext, default), carrier, Setter);
|
||||||
this.ContainsExactly(carrier, new Dictionary<string, string> { { B3Format.XB3Combined, $"{TraceIdBase16}-{SpanIdBase16}" } });
|
this.ContainsExactly(carrier, new Dictionary<string, string> { { B3Propagator.XB3Combined, $"{TraceIdBase16}-{SpanIdBase16}" } });
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
|
|
@ -228,10 +228,10 @@ namespace OpenTelemetry.Context.Propagation.Tests
|
||||||
{
|
{
|
||||||
var headersNotSampled = new Dictionary<string, string>
|
var headersNotSampled = new Dictionary<string, string>
|
||||||
{
|
{
|
||||||
{ B3Format.XB3Combined, $"{TraceIdBase16}-{SpanIdBase16}" },
|
{ B3Propagator.XB3Combined, $"{TraceIdBase16}-{SpanIdBase16}" },
|
||||||
};
|
};
|
||||||
var activityContext = new ActivityContext(TraceId, SpanId, ActivityTraceFlags.None);
|
var activityContext = new ActivityContext(TraceId, SpanId, ActivityTraceFlags.None);
|
||||||
Assert.Equal(new PropagationContext(activityContext, default), this.b3FormatSingleHeader.Extract(default, headersNotSampled, Getter));
|
Assert.Equal(new PropagationContext(activityContext, default), this.b3PropagatorSingleHeader.Extract(default, headersNotSampled, Getter));
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
|
|
@ -239,12 +239,12 @@ namespace OpenTelemetry.Context.Propagation.Tests
|
||||||
{
|
{
|
||||||
var headersSampled = new Dictionary<string, string>
|
var headersSampled = new Dictionary<string, string>
|
||||||
{
|
{
|
||||||
{ B3Format.XB3Combined, $"{TraceIdBase16}-{SpanIdBase16}-1" },
|
{ B3Propagator.XB3Combined, $"{TraceIdBase16}-{SpanIdBase16}-1" },
|
||||||
};
|
};
|
||||||
|
|
||||||
Assert.Equal(
|
Assert.Equal(
|
||||||
new PropagationContext(new ActivityContext(TraceId, SpanId, TraceOptions), default),
|
new PropagationContext(new ActivityContext(TraceId, SpanId, TraceOptions), default),
|
||||||
this.b3FormatSingleHeader.Extract(default, headersSampled, Getter));
|
this.b3PropagatorSingleHeader.Extract(default, headersSampled, Getter));
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
|
|
@ -252,12 +252,12 @@ namespace OpenTelemetry.Context.Propagation.Tests
|
||||||
{
|
{
|
||||||
var headersNotSampled = new Dictionary<string, string>
|
var headersNotSampled = new Dictionary<string, string>
|
||||||
{
|
{
|
||||||
{ B3Format.XB3Combined, $"{TraceIdBase16}-{SpanIdBase16}-0" },
|
{ B3Propagator.XB3Combined, $"{TraceIdBase16}-{SpanIdBase16}-0" },
|
||||||
};
|
};
|
||||||
|
|
||||||
Assert.Equal(
|
Assert.Equal(
|
||||||
new PropagationContext(new ActivityContext(TraceId, SpanId, ActivityTraceFlags.None), default),
|
new PropagationContext(new ActivityContext(TraceId, SpanId, ActivityTraceFlags.None), default),
|
||||||
this.b3FormatSingleHeader.Extract(default, headersNotSampled, Getter));
|
this.b3PropagatorSingleHeader.Extract(default, headersNotSampled, Getter));
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
|
|
@ -265,10 +265,10 @@ namespace OpenTelemetry.Context.Propagation.Tests
|
||||||
{
|
{
|
||||||
var headersFlagSampled = new Dictionary<string, string>
|
var headersFlagSampled = new Dictionary<string, string>
|
||||||
{
|
{
|
||||||
{ B3Format.XB3Combined, $"{TraceIdBase16}-{SpanIdBase16}-1" },
|
{ B3Propagator.XB3Combined, $"{TraceIdBase16}-{SpanIdBase16}-1" },
|
||||||
};
|
};
|
||||||
var activityContext = new ActivityContext(TraceId, SpanId, TraceOptions);
|
var activityContext = new ActivityContext(TraceId, SpanId, TraceOptions);
|
||||||
Assert.Equal(new PropagationContext(activityContext, default), this.b3FormatSingleHeader.Extract(default, headersFlagSampled, Getter));
|
Assert.Equal(new PropagationContext(activityContext, default), this.b3PropagatorSingleHeader.Extract(default, headersFlagSampled, Getter));
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
|
|
@ -276,10 +276,10 @@ namespace OpenTelemetry.Context.Propagation.Tests
|
||||||
{
|
{
|
||||||
var headersFlagNotSampled = new Dictionary<string, string>
|
var headersFlagNotSampled = new Dictionary<string, string>
|
||||||
{
|
{
|
||||||
{ B3Format.XB3Combined, $"{TraceIdBase16}-{SpanIdBase16}-0" },
|
{ B3Propagator.XB3Combined, $"{TraceIdBase16}-{SpanIdBase16}-0" },
|
||||||
};
|
};
|
||||||
var activityContext = new ActivityContext(TraceId, SpanId, ActivityTraceFlags.None);
|
var activityContext = new ActivityContext(TraceId, SpanId, ActivityTraceFlags.None);
|
||||||
Assert.Equal(new PropagationContext(activityContext, default), this.b3FormatSingleHeader.Extract(default, headersFlagNotSampled, Getter));
|
Assert.Equal(new PropagationContext(activityContext, default), this.b3PropagatorSingleHeader.Extract(default, headersFlagNotSampled, Getter));
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
|
|
@ -287,10 +287,10 @@ namespace OpenTelemetry.Context.Propagation.Tests
|
||||||
{
|
{
|
||||||
var headersEightBytes = new Dictionary<string, string>
|
var headersEightBytes = new Dictionary<string, string>
|
||||||
{
|
{
|
||||||
{ B3Format.XB3Combined, $"{TraceIdBase16EightBytes}-{SpanIdBase16}-1" },
|
{ B3Propagator.XB3Combined, $"{TraceIdBase16EightBytes}-{SpanIdBase16}-1" },
|
||||||
};
|
};
|
||||||
var activityContext = new ActivityContext(TraceIdEightBytes, SpanId, TraceOptions);
|
var activityContext = new ActivityContext(TraceIdEightBytes, SpanId, TraceOptions);
|
||||||
Assert.Equal(new PropagationContext(activityContext, default), this.b3FormatSingleHeader.Extract(default, headersEightBytes, Getter));
|
Assert.Equal(new PropagationContext(activityContext, default), this.b3PropagatorSingleHeader.Extract(default, headersEightBytes, Getter));
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
|
|
@ -298,10 +298,10 @@ namespace OpenTelemetry.Context.Propagation.Tests
|
||||||
{
|
{
|
||||||
var headersEightBytes = new Dictionary<string, string>
|
var headersEightBytes = new Dictionary<string, string>
|
||||||
{
|
{
|
||||||
{ B3Format.XB3Combined, $"{TraceIdBase16EightBytes}-{SpanIdBase16}" },
|
{ B3Propagator.XB3Combined, $"{TraceIdBase16EightBytes}-{SpanIdBase16}" },
|
||||||
};
|
};
|
||||||
var activityContext = new ActivityContext(TraceIdEightBytes, SpanId, ActivityTraceFlags.None);
|
var activityContext = new ActivityContext(TraceIdEightBytes, SpanId, ActivityTraceFlags.None);
|
||||||
Assert.Equal(new PropagationContext(activityContext, default), this.b3FormatSingleHeader.Extract(default, headersEightBytes, Getter));
|
Assert.Equal(new PropagationContext(activityContext, default), this.b3PropagatorSingleHeader.Extract(default, headersEightBytes, Getter));
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
|
|
@ -309,9 +309,9 @@ namespace OpenTelemetry.Context.Propagation.Tests
|
||||||
{
|
{
|
||||||
var invalidHeaders = new Dictionary<string, string>
|
var invalidHeaders = new Dictionary<string, string>
|
||||||
{
|
{
|
||||||
{ B3Format.XB3Combined, $"{InvalidId}-{SpanIdBase16}" },
|
{ B3Propagator.XB3Combined, $"{InvalidId}-{SpanIdBase16}" },
|
||||||
};
|
};
|
||||||
Assert.Equal(default, this.b3FormatSingleHeader.Extract(default, invalidHeaders, Getter));
|
Assert.Equal(default, this.b3PropagatorSingleHeader.Extract(default, invalidHeaders, Getter));
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
|
|
@ -319,17 +319,17 @@ namespace OpenTelemetry.Context.Propagation.Tests
|
||||||
{
|
{
|
||||||
var invalidHeaders = new Dictionary<string, string>
|
var invalidHeaders = new Dictionary<string, string>
|
||||||
{
|
{
|
||||||
{ B3Format.XB3Combined, $"{InvalidSizeId}-{SpanIdBase16}" },
|
{ B3Propagator.XB3Combined, $"{InvalidSizeId}-{SpanIdBase16}" },
|
||||||
};
|
};
|
||||||
|
|
||||||
Assert.Equal(default, this.b3FormatSingleHeader.Extract(default, invalidHeaders, Getter));
|
Assert.Equal(default, this.b3PropagatorSingleHeader.Extract(default, invalidHeaders, Getter));
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void ParseMissingTraceId_SingleHeader()
|
public void ParseMissingTraceId_SingleHeader()
|
||||||
{
|
{
|
||||||
var invalidHeaders = new Dictionary<string, string> { { B3Format.XB3Combined, $"-{SpanIdBase16}" } };
|
var invalidHeaders = new Dictionary<string, string> { { B3Propagator.XB3Combined, $"-{SpanIdBase16}" } };
|
||||||
Assert.Equal(default, this.b3FormatSingleHeader.Extract(default, invalidHeaders, Getter));
|
Assert.Equal(default, this.b3PropagatorSingleHeader.Extract(default, invalidHeaders, Getter));
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
|
|
@ -337,9 +337,9 @@ namespace OpenTelemetry.Context.Propagation.Tests
|
||||||
{
|
{
|
||||||
var invalidHeaders = new Dictionary<string, string>
|
var invalidHeaders = new Dictionary<string, string>
|
||||||
{
|
{
|
||||||
{ B3Format.XB3Combined, $"{TraceIdBase16}-{InvalidId}" },
|
{ B3Propagator.XB3Combined, $"{TraceIdBase16}-{InvalidId}" },
|
||||||
};
|
};
|
||||||
Assert.Equal(default, this.b3FormatSingleHeader.Extract(default, invalidHeaders, Getter));
|
Assert.Equal(default, this.b3PropagatorSingleHeader.Extract(default, invalidHeaders, Getter));
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
|
|
@ -347,24 +347,24 @@ namespace OpenTelemetry.Context.Propagation.Tests
|
||||||
{
|
{
|
||||||
var invalidHeaders = new Dictionary<string, string>
|
var invalidHeaders = new Dictionary<string, string>
|
||||||
{
|
{
|
||||||
{ B3Format.XB3Combined, $"{TraceIdBase16}-{InvalidSizeId}" },
|
{ B3Propagator.XB3Combined, $"{TraceIdBase16}-{InvalidSizeId}" },
|
||||||
};
|
};
|
||||||
Assert.Equal(default, this.b3FormatSingleHeader.Extract(default, invalidHeaders, Getter));
|
Assert.Equal(default, this.b3PropagatorSingleHeader.Extract(default, invalidHeaders, Getter));
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void ParseMissingSpanId_SingleHeader()
|
public void ParseMissingSpanId_SingleHeader()
|
||||||
{
|
{
|
||||||
var invalidHeaders = new Dictionary<string, string> { { B3Format.XB3Combined, $"{TraceIdBase16}-" } };
|
var invalidHeaders = new Dictionary<string, string> { { B3Propagator.XB3Combined, $"{TraceIdBase16}-" } };
|
||||||
Assert.Equal(default, this.b3FormatSingleHeader.Extract(default, invalidHeaders, Getter));
|
Assert.Equal(default, this.b3PropagatorSingleHeader.Extract(default, invalidHeaders, Getter));
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void Fields_list()
|
public void Fields_list()
|
||||||
{
|
{
|
||||||
this.ContainsExactly(
|
this.ContainsExactly(
|
||||||
this.b3Format.Fields,
|
this.b3propagator.Fields,
|
||||||
new List<string> { B3Format.XB3TraceId, B3Format.XB3SpanId, B3Format.XB3ParentSpanId, B3Format.XB3Sampled, B3Format.XB3Flags });
|
new List<string> { B3Propagator.XB3TraceId, B3Propagator.XB3SpanId, B3Propagator.XB3ParentSpanId, B3Propagator.XB3Sampled, B3Propagator.XB3Flags });
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ContainsExactly(ISet<string> list, List<string> items)
|
private void ContainsExactly(ISet<string> list, List<string> items)
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
// <copyright file="BaggageFormatTest.cs" company="OpenTelemetry Authors">
|
// <copyright file="BaggagePropagatorTest.cs" company="OpenTelemetry Authors">
|
||||||
// Copyright The OpenTelemetry Authors
|
// Copyright The OpenTelemetry Authors
|
||||||
//
|
//
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
|
@ -13,6 +13,7 @@
|
||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
// </copyright>
|
// </copyright>
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
|
@ -20,7 +21,7 @@ using Xunit;
|
||||||
|
|
||||||
namespace OpenTelemetry.Context.Propagation.Tests
|
namespace OpenTelemetry.Context.Propagation.Tests
|
||||||
{
|
{
|
||||||
public class BaggageFormatTest
|
public class BaggagePropagatorTest
|
||||||
{
|
{
|
||||||
private static readonly Func<IDictionary<string, string>, string, IEnumerable<string>> Getter =
|
private static readonly Func<IDictionary<string, string>, string, IEnumerable<string>> Getter =
|
||||||
(d, k) =>
|
(d, k) =>
|
||||||
|
|
@ -40,12 +41,12 @@ namespace OpenTelemetry.Context.Propagation.Tests
|
||||||
carrier[name] = value;
|
carrier[name] = value;
|
||||||
};
|
};
|
||||||
|
|
||||||
private readonly BaggageFormat baggage = new BaggageFormat();
|
private readonly BaggagePropagator baggage = new BaggagePropagator();
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void ValidateFieldsProperty()
|
public void ValidateFieldsProperty()
|
||||||
{
|
{
|
||||||
Assert.Equal(new HashSet<string> { BaggageFormat.BaggageHeaderName }, this.baggage.Fields);
|
Assert.Equal(new HashSet<string> { BaggagePropagator.BaggageHeaderName }, this.baggage.Fields);
|
||||||
Assert.Single(this.baggage.Fields);
|
Assert.Single(this.baggage.Fields);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -77,7 +78,7 @@ namespace OpenTelemetry.Context.Propagation.Tests
|
||||||
{
|
{
|
||||||
var carrier = new Dictionary<string, string>
|
var carrier = new Dictionary<string, string>
|
||||||
{
|
{
|
||||||
{ BaggageFormat.BaggageHeaderName, "name=test" },
|
{ BaggagePropagator.BaggageHeaderName, "name=test" },
|
||||||
};
|
};
|
||||||
var propagationContext = this.baggage.Extract(default, carrier, Getter);
|
var propagationContext = this.baggage.Extract(default, carrier, Getter);
|
||||||
Assert.False(propagationContext == default);
|
Assert.False(propagationContext == default);
|
||||||
|
|
@ -94,9 +95,9 @@ namespace OpenTelemetry.Context.Propagation.Tests
|
||||||
{
|
{
|
||||||
var carrier = new List<KeyValuePair<string, string>>
|
var carrier = new List<KeyValuePair<string, string>>
|
||||||
{
|
{
|
||||||
new KeyValuePair<string, string>(BaggageFormat.BaggageHeaderName, "name1=test1"),
|
new KeyValuePair<string, string>(BaggagePropagator.BaggageHeaderName, "name1=test1"),
|
||||||
new KeyValuePair<string, string>(BaggageFormat.BaggageHeaderName, "name2=test2"),
|
new KeyValuePair<string, string>(BaggagePropagator.BaggageHeaderName, "name2=test2"),
|
||||||
new KeyValuePair<string, string>(BaggageFormat.BaggageHeaderName, "name2=test2"),
|
new KeyValuePair<string, string>(BaggagePropagator.BaggageHeaderName, "name2=test2"),
|
||||||
};
|
};
|
||||||
|
|
||||||
var propagationContext = this.baggage.Extract(default, carrier, GetterList);
|
var propagationContext = this.baggage.Extract(default, carrier, GetterList);
|
||||||
|
|
@ -120,7 +121,7 @@ namespace OpenTelemetry.Context.Propagation.Tests
|
||||||
{
|
{
|
||||||
var carrier = new Dictionary<string, string>
|
var carrier = new Dictionary<string, string>
|
||||||
{
|
{
|
||||||
{ BaggageFormat.BaggageHeaderName, $"name={new string('x', 8186)},clientId=1234" },
|
{ BaggagePropagator.BaggageHeaderName, $"name={new string('x', 8186)},clientId=1234" },
|
||||||
};
|
};
|
||||||
var propagationContext = this.baggage.Extract(default, carrier, Getter);
|
var propagationContext = this.baggage.Extract(default, carrier, Getter);
|
||||||
Assert.False(propagationContext == default);
|
Assert.False(propagationContext == default);
|
||||||
|
|
@ -156,7 +157,7 @@ namespace OpenTelemetry.Context.Propagation.Tests
|
||||||
this.baggage.Inject(propagationContext, carrier, Setter);
|
this.baggage.Inject(propagationContext, carrier, Setter);
|
||||||
|
|
||||||
Assert.Single(carrier);
|
Assert.Single(carrier);
|
||||||
Assert.Equal("key1=value1,key2=value2", carrier[BaggageFormat.BaggageHeaderName]);
|
Assert.Equal("key1=value1,key2=value2", carrier[BaggagePropagator.BaggageHeaderName]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -108,8 +108,8 @@ namespace OpenTelemetry.Context.Propagation.Tests
|
||||||
{
|
{
|
||||||
var compositePropagator = new CompositePropagator(new List<ITextFormat>
|
var compositePropagator = new CompositePropagator(new List<ITextFormat>
|
||||||
{
|
{
|
||||||
new TraceContextFormat(),
|
new TextMapPropagator(),
|
||||||
new BaggageFormat(),
|
new BaggagePropagator(),
|
||||||
});
|
});
|
||||||
|
|
||||||
var activityContext = new ActivityContext(this.traceId, this.spanId, ActivityTraceFlags.Recorded, traceState: null, isRemote: true);
|
var activityContext = new ActivityContext(this.traceId, this.spanId, ActivityTraceFlags.Recorded, traceState: null, isRemote: true);
|
||||||
|
|
|
||||||
|
|
@ -49,7 +49,7 @@ namespace OpenTelemetry.Context.Propagation.Tests
|
||||||
return context;
|
return context;
|
||||||
}
|
}
|
||||||
|
|
||||||
var traceparentParsed = TraceContextFormat.TryExtractTraceparent(id.First(), out var traceId, out var spanId, out var traceoptions);
|
var traceparentParsed = TextMapPropagator.TryExtractTraceparent(id.First(), out var traceId, out var spanId, out var traceoptions);
|
||||||
if (!traceparentParsed)
|
if (!traceparentParsed)
|
||||||
{
|
{
|
||||||
return context;
|
return context;
|
||||||
|
|
@ -59,7 +59,7 @@ namespace OpenTelemetry.Context.Propagation.Tests
|
||||||
IEnumerable<string> tracestateCollection = getter(carrier, this.stateHeaderName);
|
IEnumerable<string> tracestateCollection = getter(carrier, this.stateHeaderName);
|
||||||
if (tracestateCollection?.Any() ?? false)
|
if (tracestateCollection?.Any() ?? false)
|
||||||
{
|
{
|
||||||
TraceContextFormat.TryExtractTracestate(tracestateCollection.ToArray(), out tracestate);
|
TextMapPropagator.TryExtractTracestate(tracestateCollection.ToArray(), out tracestate);
|
||||||
}
|
}
|
||||||
|
|
||||||
return new PropagationContext(
|
return new PropagationContext(
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
// <copyright file="TraceContextTest.cs" company="OpenTelemetry Authors">
|
// <copyright file="TextMapPropagatorTest.cs" company="OpenTelemetry Authors">
|
||||||
// Copyright The OpenTelemetry Authors
|
// Copyright The OpenTelemetry Authors
|
||||||
//
|
//
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
|
@ -20,7 +20,7 @@ using Xunit;
|
||||||
|
|
||||||
namespace OpenTelemetry.Context.Propagation.Tests
|
namespace OpenTelemetry.Context.Propagation.Tests
|
||||||
{
|
{
|
||||||
public class TraceContextTest
|
public class TextMapPropagatorTest
|
||||||
{
|
{
|
||||||
private const string TraceParent = "traceparent";
|
private const string TraceParent = "traceparent";
|
||||||
private const string TraceState = "tracestate";
|
private const string TraceState = "tracestate";
|
||||||
|
|
@ -44,7 +44,7 @@ namespace OpenTelemetry.Context.Propagation.Tests
|
||||||
};
|
};
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void TraceContextFormatCanParseExampleFromSpec()
|
public void CanParseExampleFromSpec()
|
||||||
{
|
{
|
||||||
var headers = new Dictionary<string, string>
|
var headers = new Dictionary<string, string>
|
||||||
{
|
{
|
||||||
|
|
@ -52,7 +52,7 @@ namespace OpenTelemetry.Context.Propagation.Tests
|
||||||
{ TraceState, $"congo=lZWRzIHRoNhcm5hbCBwbGVhc3VyZS4,rojo=00-{TraceId}-00f067aa0ba902b7-01" },
|
{ TraceState, $"congo=lZWRzIHRoNhcm5hbCBwbGVhc3VyZS4,rojo=00-{TraceId}-00f067aa0ba902b7-01" },
|
||||||
};
|
};
|
||||||
|
|
||||||
var f = new TraceContextFormat();
|
var f = new TextMapPropagator();
|
||||||
var ctx = f.Extract(default, headers, Getter);
|
var ctx = f.Extract(default, headers, Getter);
|
||||||
|
|
||||||
Assert.Equal(ActivityTraceId.CreateFromString(TraceId.AsSpan()), ctx.ActivityContext.TraceId);
|
Assert.Equal(ActivityTraceId.CreateFromString(TraceId.AsSpan()), ctx.ActivityContext.TraceId);
|
||||||
|
|
@ -66,14 +66,14 @@ namespace OpenTelemetry.Context.Propagation.Tests
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void TraceContextFormatNotSampled()
|
public void NotSampled()
|
||||||
{
|
{
|
||||||
var headers = new Dictionary<string, string>
|
var headers = new Dictionary<string, string>
|
||||||
{
|
{
|
||||||
{ TraceParent, $"00-{TraceId}-{SpanId}-00" },
|
{ TraceParent, $"00-{TraceId}-{SpanId}-00" },
|
||||||
};
|
};
|
||||||
|
|
||||||
var f = new TraceContextFormat();
|
var f = new TextMapPropagator();
|
||||||
var ctx = f.Extract(default, headers, Getter);
|
var ctx = f.Extract(default, headers, Getter);
|
||||||
|
|
||||||
Assert.Equal(ActivityTraceId.CreateFromString(TraceId.AsSpan()), ctx.ActivityContext.TraceId);
|
Assert.Equal(ActivityTraceId.CreateFromString(TraceId.AsSpan()), ctx.ActivityContext.TraceId);
|
||||||
|
|
@ -85,46 +85,46 @@ namespace OpenTelemetry.Context.Propagation.Tests
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void TraceContextFormat_IsBlankIfNoHeader()
|
public void IsBlankIfNoHeader()
|
||||||
{
|
{
|
||||||
var headers = new Dictionary<string, string>();
|
var headers = new Dictionary<string, string>();
|
||||||
|
|
||||||
var f = new TraceContextFormat();
|
var f = new TextMapPropagator();
|
||||||
var ctx = f.Extract(default, headers, Getter);
|
var ctx = f.Extract(default, headers, Getter);
|
||||||
|
|
||||||
Assert.False(ctx.ActivityContext.IsValid());
|
Assert.False(ctx.ActivityContext.IsValid());
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void TraceContextFormat_IsBlankIfInvalid()
|
public void IsBlankIfInvalid()
|
||||||
{
|
{
|
||||||
var headers = new Dictionary<string, string>
|
var headers = new Dictionary<string, string>
|
||||||
{
|
{
|
||||||
{ TraceParent, $"00-xyz7651916cd43dd8448eb211c80319c-{SpanId}-01" },
|
{ TraceParent, $"00-xyz7651916cd43dd8448eb211c80319c-{SpanId}-01" },
|
||||||
};
|
};
|
||||||
|
|
||||||
var f = new TraceContextFormat();
|
var f = new TextMapPropagator();
|
||||||
var ctx = f.Extract(default, headers, Getter);
|
var ctx = f.Extract(default, headers, Getter);
|
||||||
|
|
||||||
Assert.False(ctx.ActivityContext.IsValid());
|
Assert.False(ctx.ActivityContext.IsValid());
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void TraceContextFormat_TracestateToStringEmpty()
|
public void TracestateToStringEmpty()
|
||||||
{
|
{
|
||||||
var headers = new Dictionary<string, string>
|
var headers = new Dictionary<string, string>
|
||||||
{
|
{
|
||||||
{ TraceParent, $"00-{TraceId}-{SpanId}-01" },
|
{ TraceParent, $"00-{TraceId}-{SpanId}-01" },
|
||||||
};
|
};
|
||||||
|
|
||||||
var f = new TraceContextFormat();
|
var f = new TextMapPropagator();
|
||||||
var ctx = f.Extract(default, headers, Getter);
|
var ctx = f.Extract(default, headers, Getter);
|
||||||
|
|
||||||
Assert.Null(ctx.ActivityContext.TraceState);
|
Assert.Null(ctx.ActivityContext.TraceState);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void TraceContextFormat_TracestateToString()
|
public void TracestateToString()
|
||||||
{
|
{
|
||||||
var headers = new Dictionary<string, string>
|
var headers = new Dictionary<string, string>
|
||||||
{
|
{
|
||||||
|
|
@ -132,14 +132,14 @@ namespace OpenTelemetry.Context.Propagation.Tests
|
||||||
{ TraceState, "k1=v1,k2=v2,k3=v3" },
|
{ TraceState, "k1=v1,k2=v2,k3=v3" },
|
||||||
};
|
};
|
||||||
|
|
||||||
var f = new TraceContextFormat();
|
var f = new TextMapPropagator();
|
||||||
var ctx = f.Extract(default, headers, Getter);
|
var ctx = f.Extract(default, headers, Getter);
|
||||||
|
|
||||||
Assert.Equal("k1=v1,k2=v2,k3=v3", ctx.ActivityContext.TraceState);
|
Assert.Equal("k1=v1,k2=v2,k3=v3", ctx.ActivityContext.TraceState);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void TraceContextFormat_Inject_NoTracestate()
|
public void Inject_NoTracestate()
|
||||||
{
|
{
|
||||||
var traceId = ActivityTraceId.CreateRandom();
|
var traceId = ActivityTraceId.CreateRandom();
|
||||||
var spanId = ActivitySpanId.CreateRandom();
|
var spanId = ActivitySpanId.CreateRandom();
|
||||||
|
|
@ -151,14 +151,14 @@ namespace OpenTelemetry.Context.Propagation.Tests
|
||||||
var activityContext = new ActivityContext(traceId, spanId, ActivityTraceFlags.Recorded, traceState: null);
|
var activityContext = new ActivityContext(traceId, spanId, ActivityTraceFlags.Recorded, traceState: null);
|
||||||
PropagationContext propagationContext = new PropagationContext(activityContext, default);
|
PropagationContext propagationContext = new PropagationContext(activityContext, default);
|
||||||
var carrier = new Dictionary<string, string>();
|
var carrier = new Dictionary<string, string>();
|
||||||
var f = new TraceContextFormat();
|
var f = new TextMapPropagator();
|
||||||
f.Inject(propagationContext, carrier, Setter);
|
f.Inject(propagationContext, carrier, Setter);
|
||||||
|
|
||||||
Assert.Equal(expectedHeaders, carrier);
|
Assert.Equal(expectedHeaders, carrier);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void TraceContextFormat_Inject_WithTracestate()
|
public void Inject_WithTracestate()
|
||||||
{
|
{
|
||||||
var traceId = ActivityTraceId.CreateRandom();
|
var traceId = ActivityTraceId.CreateRandom();
|
||||||
var spanId = ActivitySpanId.CreateRandom();
|
var spanId = ActivitySpanId.CreateRandom();
|
||||||
|
|
@ -171,7 +171,7 @@ namespace OpenTelemetry.Context.Propagation.Tests
|
||||||
var activityContext = new ActivityContext(traceId, spanId, ActivityTraceFlags.Recorded, expectedHeaders[TraceState]);
|
var activityContext = new ActivityContext(traceId, spanId, ActivityTraceFlags.Recorded, expectedHeaders[TraceState]);
|
||||||
PropagationContext propagationContext = new PropagationContext(activityContext, default);
|
PropagationContext propagationContext = new PropagationContext(activityContext, default);
|
||||||
var carrier = new Dictionary<string, string>();
|
var carrier = new Dictionary<string, string>();
|
||||||
var f = new TraceContextFormat();
|
var f = new TextMapPropagator();
|
||||||
f.Inject(propagationContext, carrier, Setter);
|
f.Inject(propagationContext, carrier, Setter);
|
||||||
|
|
||||||
Assert.Equal(expectedHeaders, carrier);
|
Assert.Equal(expectedHeaders, carrier);
|
||||||
Loading…
Reference in New Issue