Skip to main content

Prism OpenTelemetry for Python

OpenTelemetry spans for Prism generations, using the GenAI semantic conventions and the OpenInference keys that Phoenix and Arize read. The Python port of particle-academy/prism-opentelemetry.

Zero runtime dependencies. Python 3.10+.

pip install prism-ai-opentelemetry
from prism_opentelemetry import GenerationContext, PendingTool, TelemetrySubscriber, Usage

telemetry = TelemetrySubscriber(my_tracer)

context = GenerationContext(
    trace_id="run-42", operation="text", provider="anthropic", model="claude-opus-5"
)

telemetry.on_generation_started(context, prompt)
telemetry.on_tool_invoked("run-42", PendingTool(name="search", call_id="call_1", step_index=0))
telemetry.on_step_completed(
    "run-42", 0, "claude-opus-5", "anthropic", Usage(prompt_tokens=812, completion_tokens=64)
)
telemetry.on_generation_completed("run-42", finish_reason="stop", output=response_text)

my_tracer is anything with start_span(name, start_time_nanos=None, parent=None) returning a span with set_attribute, set_status, record_exception and end. Wrap your OpenTelemetry SDK tracer in that method; the package imports no OpenTelemetry code.

Spans

  • One root span per generation, with the operation, provider, model and, when given, session.id and user.id.
  • A child span per step, with token usage and, when given, cost.
  • A child span per tool call (execute_tool <name>), attached to the step it belongs to.
  • A failed generation ends its root span with an error status.

Children are parented off the root stored in SpanStore under the trace id, never off the ambient context. Prism's tool loop is recursive, and ambient context does not survive it.

Content is off by default

Prompts, completions and tool arguments are user content, and a span export leaves the application. They are recorded only with capture_content=True.

  • Captured content is cut at max_content_length characters (65,536 by default) and marked …[truncated].
  • Even with capture on, media bytes (images, audio, video, documents) are replaced by their size unless you also pass capture_media=True. without_media_bytes() is the function that does it.
  • The model, provider, token counts and rate limits are not content and are always recorded.
  • record_exceptions is on by default and puts the exception's message on the root span. Turn it off if your errors can carry user content.

Rate limits

Pass the provider's quota buckets as RateLimit(name, limit, remaining, resets_at) to on_generation_completed or on the error given to on_generation_failed. They are written as prism.rate_limit.<name>.* attributes, on success as well as on failure.

Parity

prism-parity's opentelemetry-media-content corpus pins the media-byte rule, and all three languages agree on it.

Its opentelemetry-span-attributes corpus does not agree yet. Rate-limit attributes are identical in PHP, TypeScript and Python. These still differ:

  • the operation name and span name, which the PHP reference maps onto the GenAI vocabulary and the ports pass through;
  • the span kind for image and stream operations;
  • the status of a successful span, unset in PHP and ok in the ports;
  • gen_ai.response.finish_reasons;
  • captured content, which Python encodes with spaces after separators and escaped non-ASCII;
  • where truncation cuts a long value.

Spans from a PHP application and a Python agent in the same trace show those differences.

License

MIT. See LICENSE.

Metadata

Release files for prism-ai-opentelemetry 0.3.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 prism-ai-opentelemetry 0.3.0
File Size Uploaded
prism_ai_opentelemetry-0.3.0.tar.gz 16.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for prism-ai-opentelemetry 0.3.0
File Interpreter ABI Platform
prism_ai_opentelemetry-0.3.0-py3-none-any.whl Python 3 none any Details

Total release size: 33.0 kB

Release files / prism_ai_opentelemetry-0.3.0.tar.gz

Download URL prism_ai_opentelemetry-0.3.0.tar.gz
Size 16.0 kB
Tags Source
SHA-256 checksum
How to use checksums
ac32673c196c8d4fd6ada57d94fd734fc71098c1deb3a37b02d2f6967d95278e
BLAKE2b-256 checksum
How to use checksums
4feba11123e52d10b020b287f37fdccdf1503d508939c5ce52ec0d87bcddd01a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 22, 2026.

Transparency log

Release files / prism_ai_opentelemetry-0.3.0-py3-none-any.whl

Download URL prism_ai_opentelemetry-0.3.0-py3-none-any.whl
Size 17.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
74e94f0d1558b0bcc97cd7d2efa2bb4fb8f68cdd90d0aee36328b19336b83fec
BLAKE2b-256 checksum
How to use checksums
134bbeb3cc2f5e30adc28d79ebc6380871ff5ba7d981b951462d28fbee42e87d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 22, 2026.

Transparency log

Release history Release notifications | RSS feed

0.3.1

2 release files

This release

0.3.0 This release

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