-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4f34ea1
commit e825094
Showing
8 changed files
with
212 additions
and
55 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
33 changes: 33 additions & 0 deletions
33
Endpoints/GenericEndpoint.Messaging/MessageHeaders/TraceContext.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,33 @@ | ||
namespace SpaceEngineers.Core.GenericEndpoint.Messaging.MessageHeaders | ||
{ | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using Basics; | ||
|
||
/// <summary> | ||
/// TraceContext | ||
/// </summary> | ||
public class TraceContext : IIntegrationMessageHeader | ||
{ | ||
/// <summary> .cctor </summary> | ||
/// <param name="value">Trace context attributes</param> | ||
public TraceContext(Dictionary<string, object> value) | ||
{ | ||
Value = value; | ||
} | ||
|
||
/// <summary> | ||
/// Trace context attributes | ||
/// </summary> | ||
public Dictionary<string, object> Value { get; } | ||
|
||
/// <inheritdoc /> | ||
public string StringValue => Value.Select(pair => pair.ToString()).ToString(", "); | ||
|
||
/// <inheritdoc /> | ||
public override string ToString() | ||
{ | ||
return $"[{nameof(TraceContext)}:{StringValue}]"; | ||
} | ||
} | ||
} |
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
42 changes: 42 additions & 0 deletions
42
Endpoints/GenericEndpoint/Pipeline/TraceContextPropagationProvider.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,42 @@ | ||
namespace SpaceEngineers.Core.GenericEndpoint.Pipeline | ||
{ | ||
using System.Collections.Generic; | ||
using Messaging; | ||
using Messaging.MessageHeaders; | ||
using OpenTelemetry; | ||
using OpenTelemetry.Context.Propagation; | ||
using OpenTelemetry.Trace; | ||
using SpaceEngineers.Core.AutoRegistration.Api.Abstractions; | ||
using SpaceEngineers.Core.AutoRegistration.Api.Attributes; | ||
using SpaceEngineers.Core.AutoRegistration.Api.Enumerations; | ||
|
||
[Component(EnLifestyle.Singleton)] | ||
internal class TraceContextPropagationProvider : IIntegrationMessageHeaderProvider, | ||
ICollectionResolvable<IIntegrationMessageHeaderProvider> | ||
{ | ||
public void WriteHeaders(IntegrationMessage generalMessage, IntegrationMessage? initiatorMessage) | ||
{ | ||
Propagators.DefaultTextMapPropagator.Inject( | ||
new PropagationContext(Tracer.CurrentSpan.Context, Baggage.Current), | ||
generalMessage, | ||
InjectTraceContext); | ||
} | ||
|
||
private static void InjectTraceContext(IntegrationMessage message, string key, string value) | ||
{ | ||
Dictionary<string, object> traceContextAttributes; | ||
|
||
if (message.ReadHeader<TraceContext>() is { } traceContext) | ||
{ | ||
traceContextAttributes = traceContext.Value; | ||
} | ||
else | ||
{ | ||
traceContextAttributes = new Dictionary<string, object>(); | ||
message.WriteHeader(new TraceContext(traceContextAttributes)); | ||
} | ||
|
||
traceContextAttributes[key] = value; | ||
} | ||
} | ||
} |
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