Skip to content

Commit 307d87f

Browse files
authored
Add values handling to span_event array_value to mirror agent (#218)
1 parent 6d273ae commit 307d87f

File tree

4 files changed

+30
-16
lines changed

4 files changed

+30
-16
lines changed

ddapm_test_agent/trace.py

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -261,9 +261,12 @@ def verify_span(d: Any) -> Span:
261261
), f"Expected 'double_value' to be of type: 'float', got: {type(attr['double_value'])}"
262262
elif attr["type"] == 4:
263263
assert isinstance(
264-
attr["array_value"], list
265-
), f"Expected 'array_value' to be of type: 'list', got: {type(attr['array_value'])}"
266-
array = attr["array_value"]
264+
attr["array_value"], dict
265+
), f"Expected 'array_value' to be of type: 'dict', got: {type(attr['array_value'])}"
266+
assert (
267+
len(attr["array_value"]) == 1 and attr["array_value"].get("values") is not None
268+
), f"Expected 'array_value' to contain exactly one key values, got keys: {' ,'.join(attr['array_value'].keys())}"
269+
array = attr["array_value"]["values"]
267270
if array:
268271
first_type = array[0]["type"]
269272
i = None
@@ -433,10 +436,10 @@ def copy_span_events(s: SpanEvent) -> SpanEvent:
433436
# Copy arrays inside attributes
434437
for k, v in attributes.items():
435438
if isinstance(v, dict) and v["type"] == "array_value":
436-
array = v["array_value"]
439+
array = v["array_value"]["values"]
437440

438441
value = v.copy()
439-
value["array_value"] = array.copy()
442+
value["array_value"] = {"values": array.copy()}
440443

441444
attributes[k] = value
442445
copy["attributes"] = attributes
@@ -543,17 +546,17 @@ def add_span_event(
543546
elif isinstance(v, float):
544547
new_attributes[k] = {"type": 3, "double_value": v}
545548
elif isinstance(v, list):
546-
array_value: List[Dict[str, Any]] = []
549+
array_value: Dict[str, List[Dict[str, Any]]] = {"values": []}
547550
new_attributes[k] = {"type": 4, "array_value": array_value}
548551
for i in v:
549552
if isinstance(i, str):
550-
array_value.append({"type": 0, "string_value": i})
553+
array_value["values"].append({"type": 0, "string_value": i})
551554
elif isinstance(i, bool):
552-
array_value.append({"type": 1, "bool_value": i})
555+
array_value["values"].append({"type": 1, "bool_value": i})
553556
elif isinstance(i, int):
554-
array_value.append({"type": 2, "int_value": i})
557+
array_value["values"].append({"type": 2, "int_value": i})
555558
elif isinstance(i, float):
556-
array_value.append({"type": 3, "double_value": i})
559+
array_value["values"].append({"type": 3, "double_value": i})
557560
else:
558561
raise ValueError(f"Unsupported span event attribute type {type(i)} for: {k}={v}")
559562
else:
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
fixes:
3+
- |
4+
The agent requires any span_event array_value to be wrapped in a {values: [...]} object.
5+
This reflects this requirement from the SpanEvent prototype here.

tests/conftest.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,9 @@ def v04_reference_http_trace_payload_data_raw() -> List[Trace]:
180180
"string": {"type": 0, "string_value": "foo"},
181181
"array": {
182182
"type": 4,
183-
"array_value": [{"type": 2, "int_value": 1}, {"type": 2, "int_value": 2}],
183+
"array_value": {
184+
"values": [{"type": 2, "int_value": 1}, {"type": 2, "int_value": 2}],
185+
},
184186
},
185187
},
186188
},

tests/test_trace.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,9 @@ def test_trace_chunk():
6666
"attributes": {
6767
"b": {
6868
"type": 4,
69-
"array_value": [{"type": 2, "int_value": 2}, {"type": 2, "int_value": 3}],
69+
"array_value": {
70+
"values": [{"type": 2, "int_value": 2}, {"type": 2, "int_value": 3}],
71+
},
7072
}
7173
},
7274
}
@@ -148,10 +150,12 @@ def test_decode_v04(content_type, payload):
148150
"attributes": {
149151
"b": {
150152
"type": 4,
151-
"array_value": [
152-
{"type": 2, "int_value": 2},
153-
{"type": 0, "string_value": "3"},
154-
],
153+
"array_value": {
154+
"values": [
155+
{"type": 2, "int_value": 2},
156+
{"type": 0, "string_value": "3"},
157+
],
158+
},
155159
}
156160
},
157161
}

0 commit comments

Comments
 (0)