Files
wehub-resource-sync 4b6817381b
CI (OpenClaw E2E) / openclaw test (push) Has been cancelled
CI / coverage-report (push) Has been cancelled
CI / test-kubernetes (push) Has been cancelled
CI / should-run-thorough (push) Has been cancelled
CI / test-thorough (cloudwatch-demo) (push) Has been cancelled
CI / test-thorough (flink-ecs) (push) Has been cancelled
CI / test-thorough (upstream-lambda) (push) Has been cancelled
CI / test-thorough (prefect-ecs-fargate) (push) Has been cancelled
Release / build-binaries (zip, opensre.exe, onefile, windows-latest, windows-x64) (push) Has been cancelled
Benchmark image — build + push to ECR (any adapter) / build + push (push) Has been cancelled
CI / quality (ubuntu-latest) (push) Has been cancelled
CI / test (tools-runtime) (push) Has been cancelled
CI / test (e2e-general) (push) Has been cancelled
CI / test (cli-runtime) (push) Has been cancelled
CI / test (e2e-provider-and-openclaw) (push) Has been cancelled
CI / test (integrations-and-misc) (push) Has been cancelled
Release / verify (push) Has been cancelled
Release / build-python-dist (push) Has been cancelled
Release / build-binaries (tar.gz, opensre, onedir, macos-15-intel, darwin-x64) (push) Has been cancelled
Release / build-binaries (tar.gz, opensre, onedir, macos-latest, darwin-arm64) (push) Has been cancelled
Release / build-binaries (tar.gz, opensre, onedir, ubuntu-22.04, linux-x64) (push) Has been cancelled
Release / publish-release (push) Has been cancelled
Release / publish-main-release (push) Has been cancelled
Interactive Shell Live (PR + post-merge) / turn-checks (no-LLM) (push) Has been cancelled
CodeQL / Analyze (python) (push) Has been cancelled
Interactive Shell Live (PR + post-merge) / turn-live shard ${{ matrix.shard_index }} (push) Has been cancelled
Release / prepare (push) Has been cancelled
Release / build-binaries (tar.gz, opensre, onedir, ubuntu-22.04-arm, linux-arm64) (push) Has been cancelled
Synthetic Deterministic Tests / Synthetic offline (deterministic) (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 13:10:45 +08:00

72 lines
2.6 KiB
Python

"""Unit tests for the shared OTLP/JSON trace parser."""
from __future__ import annotations
from platform.observability.otlp_parser import extract_span_attributes, parse_otlp_trace
def test_extract_span_attributes_value_kinds() -> None:
span = {
"attributes": [
{"key": "str", "value": {"stringValue": "v"}},
{"key": "int", "value": {"intValue": "42"}},
{"key": "bool", "value": {"boolValue": True}},
{"key": "double", "value": {"doubleValue": 1.5}},
{"key": "empty", "value": {}},
{"value": {"stringValue": "no-key"}},
]
}
attrs = extract_span_attributes(span)
assert attrs == {"str": "v", "int": "42", "bool": True, "double": 1.5}
def test_parse_otlp_trace_flattens_spans_with_service_name() -> None:
trace = {
"batches": [
{
"resource": {
"attributes": [{"key": "service.name", "value": {"stringValue": "checkout"}}]
},
"scopeSpans": [
{
"spans": [
{
"name": "POST /checkout",
"spanId": "span-1",
"parentSpanId": "span-0",
"traceId": "trace-1",
"kind": 2,
"startTimeUnixNano": "1000000000",
"endTimeUnixNano": "1150000000",
"status": {"code": 2, "message": "boom"},
"attributes": [
{
"key": "http.status_code",
"value": {"intValue": "500"},
}
],
}
]
}
],
}
]
}
spans = parse_otlp_trace(trace)
assert len(spans) == 1
span = spans[0]
assert span["name"] == "POST /checkout"
assert span["service_name"] == "checkout"
assert span["span_id"] == "span-1"
assert span["parent_span_id"] == "span-0"
assert span["duration_ms"] == 150.0
assert span["status_code"] == 2
assert span["status_message"] == "boom"
assert span["attributes"]["http.status_code"] == "500"
def test_parse_otlp_trace_handles_empty_and_malformed() -> None:
assert parse_otlp_trace({}) == []
assert parse_otlp_trace({"batches": ["not-a-dict"]}) == []
assert parse_otlp_trace({"batches": [{"scopeSpans": [{"spans": []}]}]}) == []