-
Notifications
You must be signed in to change notification settings - Fork 772
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
Removed Moq dependency from Instrumentation.AspNetCore.Tests #5123
Changes from 2 commits
41215f1
33a57f7
38de305
d37bf63
9a552d6
f202cbf
d1e8510
39a9998
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,57 @@ | ||
// <copyright file="CustomTextMapPropagator.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.Diagnostics; | ||
using OpenTelemetry.Context.Propagation; | ||
|
||
namespace OpenTelemetry.Tests; | ||
|
||
internal sealed class CustomTextMapPropagator : TextMapPropagator | ||
{ | ||
#pragma warning disable SA1010 | ||
public List<string> ExtractValues = []; | ||
public Dictionary<string, Func<PropagationContext, string>> InjectValues = []; | ||
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. SA1010: OpeningSquareBracketsMustBeSpacedCorrectly Is the pragma warning disable because of the List and Dictionary initializations (Lines 25 & 26)? 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. @TimothyMothra : 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. haha. okay, then leave it as you had it. Thanks for checking :) |
||
private static readonly PropagationContext DefaultPropagationContext = default; | ||
|
||
public event EventHandler<PropagationContextEventArgs> Injected; | ||
|
||
public override ISet<string> Fields => null; | ||
|
||
public override PropagationContext Extract<T>(PropagationContext context, T carrier, Func<T, string, IEnumerable<string>> getter) | ||
{ | ||
if (this.ExtractValues.Count == 2) | ||
{ | ||
return new PropagationContext( | ||
new ActivityContext( | ||
ActivityTraceId.CreateFromString(this.ExtractValues[0].ToCharArray()), | ||
ActivitySpanId.CreateFromString(this.ExtractValues[1].ToCharArray()), | ||
ActivityTraceFlags.Recorded), | ||
default); | ||
} | ||
|
||
return DefaultPropagationContext; | ||
} | ||
|
||
public override void Inject<T>(PropagationContext context, T carrier, Action<T, string, string> setter) | ||
{ | ||
foreach (var kv in this.InjectValues) | ||
{ | ||
setter(carrier, kv.Key, kv.Value.Invoke(context)); | ||
} | ||
|
||
this.Injected?.Invoke(this, new PropagationContextEventArgs(context)); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// <copyright file="PropagationContextEventArgs.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 OpenTelemetry.Context.Propagation; | ||
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. can be removed now that we are using Action delegate |
||
|
||
namespace OpenTelemetry.Tests; | ||
|
||
internal class PropagationContextEventArgs(PropagationContext context) : EventArgs | ||
{ | ||
public PropagationContext Context { get; private set; } = context; | ||
} |
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.
nit: Define traceId, spanId and flags as individual fields.