Skip to content
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

Tracing improvements #311

Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,16 @@ public static ReadOnlySpan<byte> InjectTracingContext(this ReadOnlyMemory<byte>

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static TracingMetadata ExtractTracingMetadata(this ReadOnlyMemory<byte> eventMetadata) {
try {
using var doc = JsonDocument.Parse(eventMetadata);

return new TracingMetadata(
doc.RootElement.GetProperty(TracingConstants.Metadata.TraceId).GetString(),
doc.RootElement.GetProperty(TracingConstants.Metadata.SpanId).GetString()
);
}
catch (Exception) {
var reader = new Utf8JsonReader(eventMetadata.Span);

if (!JsonDocument.TryParseValue(ref reader, out var doc)
josephcummings marked this conversation as resolved.
Show resolved Hide resolved
|| !doc.RootElement.TryGetProperty(TracingConstants.Metadata.TraceId, out var traceId)
|| !doc.RootElement.TryGetProperty(TracingConstants.Metadata.SpanId, out var spanId))
return TracingMetadata.None;
}

return new TracingMetadata(traceId.GetString(), spanId.GetString());
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
static ReadOnlySpan<byte> InjectTracingMetadata(this ReadOnlyMemory<byte> eventMetadata, TracingMetadata tracingMetadata) {
if (tracingMetadata == TracingMetadata.None || !tracingMetadata.IsValid)
Expand Down
Loading