-
Notifications
You must be signed in to change notification settings - Fork 775
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
Add GlobalPropagators API and have instrumentation default to it #1428
Changes from 14 commits
a2008c1
6aef3e8
7d4a097
655753a
dd21bef
df433be
5d6989c
d42da65
51de2ae
08a5c63
50036b6
9eaf4c7
9756c11
399c912
b24435b
445f40e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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) | ||
{ | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// <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 or sets the Default TextMapPropagator to be used. | ||
/// </summary> | ||
public static TextMapPropagator DefaultTextMapPropagator { get; set; } = Noop; | ||
|
||
internal static void Reset() | ||
{ | ||
DefaultTextMapPropagator = Noop; | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,13 +27,10 @@ namespace OpenTelemetry.Instrumentation.AspNet | |
public class AspNetInstrumentationOptions | ||
{ | ||
/// <summary> | ||
/// Gets or sets <see cref="TextMapPropagator"/> for context propagation. Default value: <see cref="CompositeTextMapPropagator"/> with <see cref="TraceContextPropagator"/> & <see cref="BaggagePropagator"/>. | ||
/// Gets or sets <see cref="TextMapPropagator"/> for context propagation. | ||
/// By default, <see cref="Propagators.DefaultTextMapPropagator" /> will be used. | ||
/// </summary> | ||
public TextMapPropagator Propagator { get; set; } = new CompositeTextMapPropagator(new TextMapPropagator[] | ||
{ | ||
new TraceContextPropagator(), | ||
new BaggagePropagator(), | ||
}); | ||
public TextMapPropagator Propagator { get; set; } = Propagators.DefaultTextMapPropagator; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could be a timing thing here. When options are created they'll copy the ref for the current default propagator. If user sets through SDK the global propagator after that, it won't be reflected. Could leave it null here and then when it is used in instrumentation do |
||
|
||
/// <summary> | ||
/// Gets or sets a Filter function to filter instrumentation for requests on a per request basis. | ||
|
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(); | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for tests only.