Skip to main content

otel_mapper

Pure mapping from OTLP/HTTP JSON spans to AgentRun / Edge candidates (Agent Detective build spec section 6.1). No I/O, no network, standard library only. License: Apache-2.0.

Usage

from otel_mapper import flatten_export_request, map_spans

spans = flatten_export_request(otlp_export_request_payload)  # full OTLP JSON
result = map_spans(spans)                    # a2a_detection=False by default
result.runs        # list[AgentRunCandidate], sorted by (start_time, run_key)
result.edges       # list[EdgeCandidate], sorted by (from, to, type)
result.graph_ids   # set[str]

map_spans also accepts a flat list of span dicts directly, in either the OTLP/HTTP JSON shape (traceId/spanId/attributes key-value array) or a flattened snake_case shape with plain-dict attributes. Timestamps may be ISO-8601 strings or unix-nanosecond strings. See otel_mapper/mapper.py's module docstring for the full input contract.

Keying (contract with ingest / M3)

  • run_key = "<trace_id>:<span_id>" of the AGENT span that opened the run. Deterministic and stable across redelivery; ingest hashes it into agent_runs.run_id (e.g. uuid5).
  • Every openinference.span.kind = AGENT span opens exactly one run; other spans join the run of their nearest AGENT ancestor in the same trace.
  • graph_id is the x-execution-graph-id correlation header when present on any member span (plain attribute or http.request.header.x-execution-graph-id), else the trace id.

Edge rules and direction

Edges point in the direction of influence (from_run output feeds to_run), which is what blame_engine expects.

Type Rule Direction
SPAWN AGENT span whose parent belongs to a different agent's run parent run -> child run
TOOL_DELEGATION TOOL span with gen_ai.tool.target_agent target agent's run -> caller run
A2A_MESSAGE a2a.task_id attribute, or HTTP client span on /.well-known/agent.json; only with a2a_detection=True peer run -> caller run (flipped for SERVER spans)

Edges carry a free-text detection_method recording which rule fired, and are deduplicated on (from_run_key, to_run_key, type).

Correlation-header limitation

x-execution-graph-id determines graph membership only. It groups runs into one execution graph, possibly across many traces, but says nothing about who called whom. The mapper deliberately derives no edges from it; header-correlated graphs without structural (SPAWN/TOOL/A2A) evidence are a forest of independent runs.

Tests

uv run pytest packages/otel_mapper -v

Fixtures in testdata/ are full ExportTraceServiceRequest payloads covering SPAWN, TOOL_DELEGATION, A2A (flag on/off), correlation-header membership, and malformed input.

Metadata

Release files for otel-mapper 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for otel-mapper 0.1.0
File Size Uploaded
otel_mapper-0.1.0.tar.gz 31.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for otel-mapper 0.1.0
File Interpreter ABI Platform
otel_mapper-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 51.6 kB

Release files / otel_mapper-0.1.0.tar.gz

Download URL otel_mapper-0.1.0.tar.gz
Size 31.1 kB
Tags Source
SHA-256 checksum
How to use checksums
8f12c4503033e25858a9b7d732f5deee0b572adb78edc6cd8774c784f192d359
BLAKE2b-256 checksum
How to use checksums
441d9933ec3ed6ca183a19100490cc23c9279567d273187d46c7a20e54681ffb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.11.29 {"installer":{"name":"uv","version":"0.11.29","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / otel_mapper-0.1.0-py3-none-any.whl

Download URL otel_mapper-0.1.0-py3-none-any.whl
Size 20.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
21da6a0b7702ad244d7f3ef5dbcaeb06e1d7795af883d9102249ade29920572a
BLAKE2b-256 checksum
How to use checksums
cb043def16cf57e2925be032445b265585df9f8712896d0289a2373ea26779fe
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.11.29 {"installer":{"name":"uv","version":"0.11.29","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release history Release notifications | RSS feed

0.3.1

2 release files

0.3.0

2 release files

0.2.0

2 release files

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page