Backfills trace injection test and migrates from request.params to request.params._meta (#360)

* Adds test to show where trace IDs are encoded

Signed-off-by: Adrian Cole <adrian.cole@elastic.co>

* update impl to params._meta

Signed-off-by: Adrian Cole <adrian.cole@elastic.co>

---------

Signed-off-by: Adrian Cole <adrian.cole@elastic.co>
This commit is contained in:
Adrian Cole 2025-04-30 04:38:14 +12:00 • committed by GitHub
commit 17a94272d9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -50,22 +50,19 @@ internal static class Diagnostics
fieldValues = null;
fieldValue = null;
JsonNode? parameters = null;
JsonNode? meta = null;
switch (message)
{
case JsonRpcRequest request:
parameters = request.Params;
meta = request.Params?["_meta"];
break;
case JsonRpcNotification notification:
parameters = notification.Params;
break;
default:
meta = notification.Params?["_meta"];
break;
}
if (parameters?[fieldName] is JsonValue value && value.GetValueKind() == JsonValueKind.String)
if (meta?[fieldName] is JsonValue value && value.GetValueKind() == JsonValueKind.String)
{
fieldValue = value.GetValue<string>();
}
@ -89,14 +86,17 @@ internal static class Diagnostics
case JsonRpcNotification notification:
parameters = notification.Params;
break;
default:
break;
}
if (parameters is JsonObject jsonObject && jsonObject[key] == null)
// Replace any params._meta with the current value
if (parameters is JsonObject jsonObject)
{
jsonObject[key] = value;
if (jsonObject["_meta"] is not JsonObject meta)
{
meta = new JsonObject();
jsonObject["_meta"] = meta;
}
meta[key] = value;
}
}