Skip to content

Commit 8f2e84e

Browse files
committed
wip: work on status
1 parent 820ed1c commit 8f2e84e

File tree

3 files changed

+46
-30
lines changed

3 files changed

+46
-30
lines changed

otlp_json/__init__.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,14 +118,18 @@ def _scope(scope: InstrumentationScope):
118118
return rv
119119

120120

121+
_REMOTE = 0x300
122+
_LOCAL = 0x100
123+
124+
121125
def _span(span: ReadableSpan):
122126
assert span.context
123127
rv = {
124128
"name": span.name,
125129
"kind": span.kind.value or 1, # unspecified -> internal
126130
"traceId": _trace_id(span.context.trace_id),
127131
"spanId": _span_id(span.context.span_id),
128-
"flags": 0x100 | ([0, 0x200][bool(span.parent and span.parent.is_remote)]),
132+
"flags": _REMOTE if span.parent and span.parent.is_remote else _LOCAL,
129133
"startTimeUnixNano": str(span.start_time),
130134
"endTimeUnixNano": str(span.end_time), # can this be unset?
131135
"status": _status(span.status),
@@ -155,8 +159,10 @@ def _span_id(span_id: int) -> str:
155159

156160

157161
def _status(status: Status) -> dict[str, Any]:
158-
# FIXME: need an example of bad status
159-
return {}
162+
rv = {}
163+
# rv["code"] ...
164+
# rv["message"] = ...
165+
return rv
160166

161167

162168
def _event(event: Event) -> dict[str, Any]:

test/test_pure_python.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,17 @@
1111
CONTENT_TYPE = "application/json"
1212

1313

14+
def canonical(batch):
15+
batch["resourceSpans"].sort(key=lambda rs: json.dumps(rs["resource"]))
16+
for rs in batch["resourceSpans"]:
17+
rs["scopeSpans"].sort(key=lambda sc: sc["scope"]["name"])
18+
for sc in rs["scopeSpans"]:
19+
sc["spans"].sort(key=lambda sp: sp["spanId"])
20+
21+
return batch
22+
23+
1424
def test_equiv():
15-
auth = json.loads(otlp_test_data.sample_json())
16-
mine = json.loads(otlp_json.encode_spans(otlp_test_data.sample_spans()))
25+
auth = canonical(json.loads(otlp_test_data.sample_json()))
26+
mine = canonical(json.loads(otlp_json.encode_spans(otlp_test_data.sample_spans())))
1727
assert mine == auth

uv.lock

Lines changed: 25 additions & 25 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)