-
Notifications
You must be signed in to change notification settings - Fork 762
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add GlobalPropagators API and have instrumentation default to it (#1428)
* Add GlobalPropagators API and have instrumentation default to it * changelog * fix name * reset after * min comment address * move id format to same place as context propagator * renam * renai * text initialize correctly * modify microsoervice example to pick global propagator * make Global propagator get only in api * Add SetDefaultPropagato to SDK
- Loading branch information
1 parent
ddac284
commit 0979259
Showing
17 changed files
with
195 additions
and
28 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
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
37 changes: 37 additions & 0 deletions
37
src/OpenTelemetry.Api/Context/Propagation/NoopTextMapPropagator.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,37 @@ | ||
// <copyright file="NoopTextMapPropagator.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; | ||
|
||
namespace OpenTelemetry.Context.Propagation | ||
{ | ||
internal class NoopTextMapPropagator : TextMapPropagator | ||
{ | ||
private static readonly PropagationContext DefaultPropagationContext = default; | ||
|
||
public override ISet<string> Fields => null; | ||
|
||
public override PropagationContext Extract<T>(PropagationContext context, T carrier, Func<T, string, IEnumerable<string>> getter) | ||
{ | ||
return DefaultPropagationContext; | ||
} | ||
|
||
public override void Inject<T>(PropagationContext context, T carrier, Action<T, string, string> setter) | ||
{ | ||
} | ||
} | ||
} |
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,39 @@ | ||
// <copyright file="Propagators.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> | ||
|
||
namespace OpenTelemetry.Context.Propagation | ||
{ | ||
/// <summary> | ||
/// Propagators allow setting the global default Propagators. | ||
/// </summary> | ||
public static class Propagators | ||
{ | ||
private static readonly TextMapPropagator Noop = new NoopTextMapPropagator(); | ||
|
||
/// <summary> | ||
/// Gets the Default TextMapPropagator to be used. | ||
/// </summary> | ||
/// <remarks> | ||
/// Setting this can be done only from Sdk. | ||
/// </remarks> | ||
public static TextMapPropagator DefaultTextMapPropagator { get; internal set; } = Noop; | ||
|
||
internal static void Reset() | ||
{ | ||
DefaultTextMapPropagator = Noop; | ||
} | ||
} | ||
} |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// <copyright file="PropagatorsTest.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 OpenTelemetry.Context.Propagation; | ||
using OpenTelemetry.Context.Propagation.Tests; | ||
using Xunit; | ||
|
||
namespace OpenTelemetry.Context.Tests | ||
{ | ||
public class PropagatorsTest : IDisposable | ||
{ | ||
public PropagatorsTest() | ||
{ | ||
Propagators.Reset(); | ||
} | ||
|
||
[Fact] | ||
public void DefaultTextMapPropagatorIsNoop() | ||
{ | ||
Assert.IsType<NoopTextMapPropagator>(Propagators.DefaultTextMapPropagator); | ||
Assert.Same(Propagators.DefaultTextMapPropagator, Propagators.DefaultTextMapPropagator); | ||
} | ||
|
||
[Fact] | ||
public void CanSetPropagator() | ||
{ | ||
var testPropagator = new TestPropagator(string.Empty, string.Empty); | ||
Propagators.DefaultTextMapPropagator = testPropagator; | ||
Assert.Same(testPropagator, Propagators.DefaultTextMapPropagator); | ||
} | ||
|
||
public void Dispose() | ||
{ | ||
Propagators.Reset(); | ||
} | ||
} | ||
} |
File renamed without changes.