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.3.1

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.3.1
File Size Uploaded
otel_mapper-0.3.1.tar.gz 32.9 kB Details

Built distribution (wheel)

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

Total release size: 54.6 kB

Release files / otel_mapper-0.3.1.tar.gz

Download URL otel_mapper-0.3.1.tar.gz
Size 32.9 kB
Tags Source
SHA-256 checksum
How to use checksums
b7aa4eac08ad0848efb4f694f2cd7de0e4898399630e0fc7eeba87c69771753b
BLAKE2b-256 checksum
How to use checksums
aba75c26355b9f9fa4faa2a29c4dbc716102def6cb59da78b26a19e4407dcb22
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.3.1-py3-none-any.whl

Download URL otel_mapper-0.3.1-py3-none-any.whl
Size 21.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d4b12204a00521de46912acabdfa1fcfe84b1cc1da61bcd332266de9c6fa4f68
BLAKE2b-256 checksum
How to use checksums
d9cc8c0aa049ee5b97f1714271718e41ab083424a95ac88ffbd863663c6e5dda
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

This release

0.3.1 This release

2 release files

0.3.0

2 release files

0.2.0

2 release files

0.1.0

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