Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Renaming ITextFormat to IPropagator #1190

Merged
merged 3 commits into from
Aug 28, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ namespace Utils.Messaging
public class MessageReceiver : IDisposable
{
private static readonly ActivitySource ActivitySource = new ActivitySource(nameof(MessageReceiver));
private static readonly ITextFormat TextFormat = new TextMapPropagator();
private static readonly IPropagator Propagator = new TextMapPropagator();

private readonly ILogger<MessageReceiver> logger;
private readonly IConnection connection;
Expand All @@ -57,7 +57,7 @@ public void StartConsumer()
public void ReceiveMessage(BasicDeliverEventArgs ea)
{
// Extract the ActivityContext of the upstream parent from the message headers.
var parentContext = TextFormat.Extract(default, ea.BasicProperties, this.ExtractTraceContextFromBasicProperties);
var parentContext = Propagator.Extract(default, ea.BasicProperties, this.ExtractTraceContextFromBasicProperties);

// Start an activity with a name following the semantic convention of the OpenTelemetry messaging specification.
// https://github.com/open-telemetry/opentelemetry-specification/blob/master/specification/trace/semantic_conventions/messaging.md#span-name
Expand Down
4 changes: 2 additions & 2 deletions examples/MicroserviceExample/Utils/Messaging/MessageSender.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ namespace Utils.Messaging
public class MessageSender : IDisposable
{
private static readonly ActivitySource ActivitySource = new ActivitySource(nameof(MessageSender));
private static readonly ITextFormat TextFormat = new TextMapPropagator();
private static readonly IPropagator Propagator = new TextMapPropagator();

private readonly ILogger<MessageSender> logger;
private readonly IConnection connection;
Expand Down Expand Up @@ -62,7 +62,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 PropagationContext(activity.Context, Baggage.Current), props, this.InjectTraceContextIntoBasicProperties);
Propagator.Inject(new PropagationContext(activity.Context, Baggage.Current), props, this.InjectTraceContextIntoBasicProperties);

// The OpenTelemetry messaging specification defines a number of attributes. These attributes are added here.
RabbitMqHelper.AddMessagingTags(activity);
Expand Down
2 changes: 2 additions & 0 deletions src/OpenTelemetry.Api/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@
* Renamed `TraceContextFormat` to `TextMapPropagator`, `BaggageFormat` to
`BaggagePropagator`, and `B3Format` to `B3Propagator`
([#1175](https://github.com/open-telemetry/opentelemetry-dotnet/pull/1175))
* Renamed `ITextPropagator` to `IPropagator`
([#1190](https://github.com/open-telemetry/opentelemetry-dotnet/pull/1190))

## 0.4.0-beta.2

Expand Down
2 changes: 1 addition & 1 deletion src/OpenTelemetry.Api/Context/Propagation/B3Propagator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ namespace OpenTelemetry.Context.Propagation
/// <summary>
/// B3 text propagator. See https://github.com/openzipkin/b3-propagation for the specification.
/// </summary>
public sealed class B3Propagator : ITextFormat
public sealed class B3Propagator : IPropagator
{
internal const string XB3TraceId = "X-B3-TraceId";
internal const string XB3SpanId = "X-B3-SpanId";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ namespace OpenTelemetry.Context.Propagation
/// <summary>
/// W3C baggage: https://github.com/w3c/baggage/blob/master/baggage/HTTP_HEADER_FORMAT.md.
/// </summary>
public class BaggagePropagator : ITextFormat
public class BaggagePropagator : IPropagator
{
internal const string BaggageHeaderName = "Baggage";

Expand Down
18 changes: 9 additions & 9 deletions src/OpenTelemetry.Api/Context/Propagation/CompositePropagator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,18 @@ namespace OpenTelemetry.Context.Propagation
/// <summary>
/// CompositePropagator provides a mechanism for combining multiple propagators into a single one.
/// </summary>
public class CompositePropagator : ITextFormat
public class CompositePropagator : IPropagator
{
private static readonly ISet<string> EmptyFields = new HashSet<string>();
private readonly List<ITextFormat> textFormats;
private readonly List<IPropagator> propagators;

/// <summary>
/// Initializes a new instance of the <see cref="CompositePropagator"/> class.
/// </summary>
/// <param name="textFormats">List of <see cref="ITextFormat"/> wire context propagator.</param>
public CompositePropagator(IEnumerable<ITextFormat> textFormats)
/// <param name="propagators">List of <see cref="IPropagator"/> wire context propagator.</param>
public CompositePropagator(IEnumerable<IPropagator> propagators)
{
this.textFormats = new List<ITextFormat>(textFormats ?? throw new ArgumentNullException(nameof(textFormats)));
this.propagators = new List<IPropagator>(propagators ?? throw new ArgumentNullException(nameof(propagators)));
}

/// <inheritdoc/>
Expand All @@ -42,9 +42,9 @@ public CompositePropagator(IEnumerable<ITextFormat> textFormats)
/// <inheritdoc/>
public PropagationContext Extract<T>(PropagationContext context, T carrier, Func<T, string, IEnumerable<string>> getter)
{
foreach (var textFormat in this.textFormats)
foreach (var propagator in this.propagators)
{
context = textFormat.Extract(context, carrier, getter);
context = propagator.Extract(context, carrier, getter);
}

return context;
Expand All @@ -53,9 +53,9 @@ public PropagationContext Extract<T>(PropagationContext context, T carrier, Func
/// <inheritdoc/>
public void Inject<T>(PropagationContext context, T carrier, Action<T, string, string> setter)
{
foreach (var textFormat in this.textFormats)
foreach (var propagator in this.propagators)
{
textFormat.Inject(context, carrier, setter);
propagator.Inject(context, carrier, setter);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// <copyright file="ITextFormat.cs" company="OpenTelemetry Authors">
// <copyright file="IPropagator.cs" company="OpenTelemetry Authors">
// Copyright The OpenTelemetry Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -23,7 +23,7 @@ namespace OpenTelemetry.Context.Propagation
/// Text format wire context propagator. Helps to extract and inject context from textual
/// representation (typically http headers or metadata collection).
/// </summary>
public interface ITextFormat
public interface IPropagator
{
/// <summary>
/// Gets the list of headers used by propagator. The use cases of this are:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ namespace OpenTelemetry.Context.Propagation
/// <summary>
/// W3C trace context text wire protocol formatter. See https://github.com/w3c/distributed-tracing/.
/// </summary>
public class TextMapPropagator : ITextFormat
public class TextMapPropagator : IPropagator
{
private const string TraceParent = "traceparent";
private const string TraceState = "tracestate";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ namespace OpenTelemetry.Instrumentation.AspNet
public class AspNetInstrumentationOptions
{
/// <summary>
/// Gets or sets <see cref="ITextFormat"/> for context propagation. Default value: <see cref="CompositePropagator"/> with <see cref="TextMapPropagator"/> &amp; <see cref="BaggagePropagator"/>.
/// Gets or sets <see cref="IPropagator"/> for context propagation. Default value: <see cref="CompositePropagator"/> with <see cref="TextMapPropagator"/> &amp; <see cref="BaggagePropagator"/>.
/// </summary>
public ITextFormat TextFormat { get; set; } = new CompositePropagator(new ITextFormat[]
public IPropagator Propagator { get; set; } = new CompositePropagator(new IPropagator[]
{
new TextMapPropagator(),
new BaggagePropagator(),
Expand Down
2 changes: 2 additions & 0 deletions src/OpenTelemetry.Instrumentation.AspNet/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
BaggageFormat)`. Baggage sent via the [W3C
Baggage](https://github.com/w3c/baggage/blob/master/baggage/HTTP_HEADER_FORMAT.md)
header will now be parsed and set on incoming Http spans.
* Renamed `ITextPropagator` to `IPropagator`
([#1190](https://github.com/open-telemetry/opentelemetry-dotnet/pull/1190))

## 0.4.0-beta.2

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,9 @@ public override void OnStartActivity(Activity activity, object payload)
var request = context.Request;
var requestValues = request.Unvalidated;

if (!(this.options.TextFormat is TextMapPropagator))
if (!(this.options.Propagator is TextMapPropagator))
{
var ctx = this.options.TextFormat.Extract(default, request, HttpRequestHeaderValuesGetter);
var ctx = this.options.Propagator.Extract(default, request, HttpRequestHeaderValuesGetter);

if (ctx.ActivityContext.IsValid() && ctx.ActivityContext != activity.Context)
{
Expand Down Expand Up @@ -132,7 +132,7 @@ public override void OnStopActivity(Activity activity, object payload)
Activity activityToEnrich = activity;
Activity createdActivity = null;

if (!(this.options.TextFormat is TextMapPropagator))
if (!(this.options.Propagator is TextMapPropagator))
{
// If using custom context propagator, then the activity here
// could be either the one from Asp.Net, or the one
Expand Down Expand Up @@ -197,7 +197,7 @@ public override void OnStopActivity(Activity activity, object payload)
}
}

if (!(this.options.TextFormat is TextMapPropagator))
if (!(this.options.Propagator is TextMapPropagator))
{
if (activity.OperationName.Equals(ActivityNameByHttpInListener))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ namespace OpenTelemetry.Instrumentation.AspNetCore
public class AspNetCoreInstrumentationOptions
{
/// <summary>
/// Gets or sets <see cref="ITextFormat"/> for context propagation. Default value: <see cref="CompositePropagator"/> with <see cref="TextMapPropagator"/> &amp; <see cref="BaggagePropagator"/>.
/// Gets or sets <see cref="IPropagator"/> for context propagation. Default value: <see cref="CompositePropagator"/> with <see cref="TextMapPropagator"/> &amp; <see cref="BaggagePropagator"/>.
/// </summary>
public ITextFormat TextFormat { get; set; } = new CompositePropagator(new ITextFormat[]
public IPropagator Propagator { get; set; } = new CompositePropagator(new IPropagator[]
{
new TextMapPropagator(),
new BaggagePropagator(),
Expand Down
2 changes: 2 additions & 0 deletions src/OpenTelemetry.Instrumentation.AspNetCore/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
calls where one span is created for the gRPC call and a separate span is
created for the underlying HTTP call in the event both gRPC and HTTP
instrumentation are enabled.
* Renamed `ITextPropagator` to `IPropagator`
([#1190](https://github.com/open-telemetry/opentelemetry-dotnet/pull/1190))

## 0.4.0-beta.2

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,9 @@ public override void OnStartActivity(Activity activity, object payload)
}

var request = context.Request;
if (!this.hostingSupportsW3C || !(this.options.TextFormat is TextMapPropagator))
if (!this.hostingSupportsW3C || !(this.options.Propagator is TextMapPropagator))
{
var ctx = this.options.TextFormat.Extract(default, request, HttpRequestHeaderValuesGetter);
var ctx = this.options.Propagator.Extract(default, request, HttpRequestHeaderValuesGetter);

if (ctx.ActivityContext.IsValid() && ctx.ActivityContext != activity.Context)
{
Expand Down
2 changes: 2 additions & 0 deletions src/OpenTelemetry.Instrumentation.Http/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
Framework) `TracerProviderBuilderExtensions`. `AddHttpClientInstrumentation`
will now register `HttpClient` instrumentation on .NET Core and `HttpClient` +
`HttpWebRequest` instrumentation on .NET Framework.
* Renamed `ITextPropagator` to `IPropagator`
([#1190](https://github.com/open-telemetry/opentelemetry-dotnet/pull/1190))

## 0.3.0-beta

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ public class HttpClientInstrumentationOptions
public bool SetHttpFlavor { get; set; }

/// <summary>
/// Gets or sets <see cref="ITextFormat"/> for context propagation. Default value: <see cref="CompositePropagator"/> with <see cref="TextMapPropagator"/> &amp; <see cref="BaggagePropagator"/>.
/// Gets or sets <see cref="IPropagator"/> for context propagation. Default value: <see cref="CompositePropagator"/> with <see cref="TextMapPropagator"/> &amp; <see cref="BaggagePropagator"/>.
/// </summary>
public ITextFormat TextFormat { get; set; } = new CompositePropagator(new ITextFormat[]
public IPropagator Propagator { get; set; } = new CompositePropagator(new IPropagator[]
{
new TextMapPropagator(),
new BaggagePropagator(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ public class HttpWebRequestInstrumentationOptions
public bool SetHttpFlavor { get; set; }

/// <summary>
/// Gets or sets <see cref="ITextFormat"/> for context propagation. Default value: <see cref="CompositePropagator"/> with <see cref="TextMapPropagator"/> &amp; <see cref="BaggagePropagator"/>.
/// Gets or sets <see cref="IPropagator"/> for context propagation. Default value: <see cref="CompositePropagator"/> with <see cref="TextMapPropagator"/> &amp; <see cref="BaggagePropagator"/>.
/// </summary>
public ITextFormat TextFormat { get; set; } = new CompositePropagator(new ITextFormat[]
public IPropagator Propagator { get; set; } = new CompositePropagator(new IPropagator[]
{
new TextMapPropagator(),
new BaggagePropagator(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public override void OnStartActivity(Activity activity, object payload)
return;
}

if (this.options.TextFormat.Extract(default, request, HttpRequestMessageHeaderValuesGetter) != default)
if (this.options.Propagator.Extract(default, request, HttpRequestMessageHeaderValuesGetter) != default)
{
// this request is already instrumented, we should back off
activity.IsAllDataRequested = false;
Expand All @@ -110,9 +110,9 @@ public override void OnStartActivity(Activity activity, object payload)
}
}

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

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

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

[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static bool IsRequestInstrumented(HttpWebRequest request)
=> Options.TextFormat.Extract(default, request, HttpWebRequestHeaderValuesGetter) != default;
=> Options.Propagator.Extract(default, request, HttpWebRequestHeaderValuesGetter) != default;

private static void ProcessRequest(HttpWebRequest request)
{
Expand Down
3 changes: 3 additions & 0 deletions src/OpenTelemetry.Shims.OpenTracing/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

## Unreleased

* Renamed `ITextPropagator` to `IPropagator`
([#1190](https://github.com/open-telemetry/opentelemetry-dotnet/pull/1190))

## 0.4.0-beta.2

Released 2020-07-24
Expand Down
11 changes: 5 additions & 6 deletions src/OpenTelemetry.Shims.OpenTracing/TracerShim.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,19 @@
using System;
using System.Collections.Generic;
using global::OpenTracing.Propagation;
using OpenTelemetry.Context;
using OpenTelemetry.Context.Propagation;

namespace OpenTelemetry.Shims.OpenTracing
{
public class TracerShim : global::OpenTracing.ITracer
{
private readonly Trace.Tracer tracer;
private readonly ITextFormat textFormat;
private readonly IPropagator propagator;

public TracerShim(Trace.Tracer tracer, ITextFormat textFormat)
public TracerShim(Trace.Tracer tracer, IPropagator textFormat)
{
this.tracer = tracer ?? throw new ArgumentNullException(nameof(tracer));
this.textFormat = textFormat ?? throw new ArgumentNullException(nameof(textFormat));
this.propagator = textFormat ?? throw new ArgumentNullException(nameof(textFormat));

this.ScopeManager = new ScopeManagerShim(this.tracer);
}
Expand Down Expand Up @@ -81,7 +80,7 @@ static IEnumerable<string> GetCarrierKeyValue(Dictionary<string, IEnumerable<str
return value;
}

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

// TODO:
Expand Down Expand Up @@ -120,7 +119,7 @@ public void Inject<TCarrier>(

if ((format == BuiltinFormats.TextMap || format == BuiltinFormats.HttpHeaders) && carrier is ITextMap textMapCarrier)
{
this.textFormat.Inject(
this.propagator.Inject(
new PropagationContext(shim.SpanContext, Baggage.Current),
textMapCarrier,
(instrumentation, key, value) => instrumentation.Set(key, value));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,8 @@ public void AspNetRequestsAreCollectedSuccessfully(

var expectedTraceId = ActivityTraceId.CreateRandom();
var expectedSpanId = ActivitySpanId.CreateRandom();
var textFormat = new Mock<ITextFormat>();
textFormat.Setup(m => m.Extract<HttpRequest>(It.IsAny<PropagationContext>(), It.IsAny<HttpRequest>(), It.IsAny<Func<HttpRequest, string, IEnumerable<string>>>())).Returns(new PropagationContext(
var propagator = new Mock<IPropagator>();
propagator.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 Expand Up @@ -160,7 +160,7 @@ public void AspNetRequestsAreCollectedSuccessfully(

if (!carrierFormat.Equals("TraceContext"))
{
options.TextFormat = textFormat.Object;
options.Propagator = propagator.Object;
}
})
.SetResource(expectedResource)
Expand Down
Loading