-
Notifications
You must be signed in to change notification settings - Fork 771
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Creating CompositePropagator Adding ActivityContext to interface Adding tests Updating CompositePropagator + tests updating comments Improving performance when size is 0 updating tests updating default tracestate for empty MikeGoldsmith review adding more tests to exemplify usage Feature/composite propagator refactor (#1) * Added TestPropagator and switched a couple tests to use it. * removing extra classes Co-authored-by: Mikel Blanchard <[email protected]> updating changelog and constructor MikeGoldsmith comments updating logic * checking value * adding inverted test * updating tests * removing tracecontext and b3 tests * testing only aspnet to merge * Revert "testing only aspnet to merge" This reverts commit 43ca7d0. Co-authored-by: Cijo Thomas <[email protected]>
- Loading branch information
1 parent
53a579f
commit 8948470
Showing
17 changed files
with
419 additions
and
281 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
src/OpenTelemetry.Api/Context/Propagation/CompositePropagator.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
// <copyright file="CompositePropagator.cs" company="OpenTelemetry Authors"> | ||
// Copyright The OpenTelemetry Authors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// </copyright> | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Diagnostics; | ||
using System.Linq; | ||
|
||
namespace OpenTelemetry.Context.Propagation | ||
{ | ||
/// <summary> | ||
/// CompositePropagator provides a mechanism for combining multiple propagators into a single one. | ||
/// </summary> | ||
public class CompositePropagator : ITextFormat | ||
{ | ||
private static readonly ISet<string> EmptyFields = new HashSet<string>(); | ||
private readonly List<ITextFormat> textFormats; | ||
|
||
/// <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(List<ITextFormat> textFormats) | ||
{ | ||
this.textFormats = textFormats ?? throw new ArgumentNullException(nameof(textFormats)); | ||
} | ||
|
||
/// <inheritdoc/> | ||
public ISet<string> Fields => EmptyFields; | ||
|
||
/// <inheritdoc/> | ||
public ActivityContext Extract<T>(ActivityContext activityContext, T carrier, Func<T, string, IEnumerable<string>> getter) | ||
{ | ||
foreach (var textFormat in this.textFormats) | ||
{ | ||
activityContext = textFormat.Extract(activityContext, carrier, getter); | ||
if (activityContext.IsValid()) | ||
{ | ||
return activityContext; | ||
} | ||
} | ||
|
||
return activityContext; | ||
} | ||
|
||
/// <inheritdoc/> | ||
public void Inject<T>(ActivityContext activityContext, T carrier, Action<T, string, string> setter) | ||
{ | ||
foreach (var textFormat in this.textFormats) | ||
{ | ||
textFormat.Inject(activityContext, carrier, setter); | ||
} | ||
} | ||
|
||
/// <inheritdoc/> | ||
public bool IsInjected<T>(T carrier, Func<T, string, IEnumerable<string>> getter) | ||
{ | ||
return this.textFormats.All(textFormat => textFormat.IsInjected(carrier, getter)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.