Skip to content

Commit

Permalink
remove redundant catch in ExtractTraceContextFromEventMetadata (#269)
Browse files Browse the repository at this point in the history
* remove redundant catch in ExtractTraceContextFromEventMetadata

* Update PropagationContextJsonConverter.cs
  • Loading branch information
SimonCropp authored May 19, 2024
1 parent 499277c commit 9d16b14
Showing 1 changed file with 5 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,31 +37,18 @@ public override object ReadJson(JsonReader reader, Type objectType, object? exis
{
var jObject = JObject.Load(reader);

var parentContext = TelemetryPropagator.Extract(
return TelemetryPropagator.Extract(
new Dictionary<string, string?>
{
{ TraceParentPropertyName, jObject[TraceParentPropertyName]?.Value<string>() },
{ TraceStatePropertyName, jObject[TraceStatePropertyName]?.Value<string>() }
},
ExtractTraceContextFromEventMetadata
);

return parentContext;
}

private static IEnumerable<string> ExtractTraceContextFromEventMetadata(Dictionary<string, string?> headers,
string key)
{
try
{
return headers.TryGetValue(key, out var value) && value != null
? new[] { value }
: Enumerable.Empty<string>();
}
catch (Exception ex)
{
Console.WriteLine($"Failed to extract trace context: {ex}");
return [];
}
}
private static IEnumerable<string> ExtractTraceContextFromEventMetadata(Dictionary<string, string?> headers, string key) =>
headers.TryGetValue(key, out var value) && value != null
? new[] { value }
: Enumerable.Empty<string>();
}

0 comments on commit 9d16b14

Please sign in to comment.