Repository navigation
Releases
v0.3.1
A long tool list no longer costs a span its usage and finish reason
The Python half of a regression 0.2.0 introduced, found in production by a
consumer running the PHP package.
An OpenTelemetry SDK caps a span's attributes -- 128 by default in several
implementations -- and drops the excess SILENTLY. Tool attributes were written
at on_generation_started, two per tool ungated and four under capture, before
anything else. A generation offering 31 tools filled the span before usage,
finish reason and output were ever set, and the exported root carried a model
and a tool list and nothing else, with nothing erroring anywhere.
The tool list is written LAST now, when the span ends, after usage, rate limits
and output. Both orders are lossy at the ceiling; only one is legible.
MAX_TOOLS is 64 and is NOT the binding limit. If you want the whole list, raise
it at the SDK -- OTEL_SPAN_ATTRIBUTE_COUNT_LIMIT, or the equivalent span-limits
builder for your exporter.
A generation that never completes now carries no tool attributes; an unended
span is never exported anyway. SpanStore.forget() clears the held list, so a
long-lived worker cannot accumulate the tool list of every generation it saw.
The cross-language corpus compares sorted attribute maps, so write order is
invisible to it. No conformance suite could have caught this.
v0.3.0
The digest is computed here now, not just accepted
advertised_tool_digest() is exported. The package accepted a digest and
computed none, so "the same tool" got whatever each caller had invented -- and
the attribute exists to be compared ACROSS services.
from prism_opentelemetry import advertised_tool_digest
advertised_tool_digest(name="search", description="Search the docs", parameters=schema)
The reference's canonicalisation, exactly: name, description and parameters, map
keys sorted at every depth, LISTS LEFT ALONE because required: ["b","a"] is a
different schema from required: ["a","b"], sha256 over the compact JSON.
separators=(",", ":") and ensure_ascii=False are both load-bearing: Python's
defaults put a space after every separator and escape non-ASCII, and either
alone yields different BYTES, and so a different digest, from the same tool in
the other two languages.
AN ABSENT PARAMETER MAP IS {}. The reference shipped a version hashing [] there
and could not reproduce its own digests in any other language; fixed in prism
0.124.1. This port was right the whole time and had no way to say so.
Verified by execution: prism-parity's otel-0021..0023 run one fixture through
all three languages and compare the bytes.
v0.2.0
Spans now say which tools the model was offered
The Python half of prism-opentelemetry#2.
on_generation_started takes an optional third argument: the tools the model was
offered.
subscriber.on_generation_started(context, input, [
AdvertisedTool("search", "sha256:…", "Search the docs", {...}),
])
AdvertisedTool is exported. description and parameters default to None --
leave them out if you never want them on a span.
llm.tools.<i>.tool.name always
prism.tools.<i>.digest always
llm.tools.<i>.tool.description capture_content only
llm.tools.<i>.tool.json_schema capture_content only
TWO HALVES, BECAUSE THEY ANSWER TWO QUESTIONS. The first pair answers "did the
tool set change between these two turns" -- asked in production, which is
exactly where the content gate is off, so a gated answer would be absent
whenever it was wanted. A name and a digest are authored by the application and
carry nothing the user wrote. The second pair answers "WHAT changed", and a tool
description is instructions to a model, so it goes through the capture gate.
A provider caches the tools array AS SERIALISED, so the same tools in a
different order is a different prefix and a cache miss. The attributes are
flattened by zero-based index -- OpenInference's own shape -- so order survives
without a list attribute to invent. A sorted list would report an unchanged tool
set for a turn that actually missed, which is the reassuring direction to be
wrong in. A test sends zebra before alpha and asserts they stay that way.
64 tools and 512 characters of name, capped separately from
max_content_length. That option exists so an operator can see more of a PROMPT
and a name has no reason to follow it. An MCP client builds tools from a REMOTE
server's advertised definitions, and since names are ungated they ride EVERY
span rather than only captured ones.
Additive: the parameter is optional and existing calls are unaffected.
v0.1.0
First release: Prism telemetry as OpenTelemetry spans, in Python
prism-ai-opentelemetry is the Python port of
particle-academy/prism-opentelemetry — Prism's telemetry events as spans
carrying both the OpenTelemetry GenAI conventions and the OpenInference
attributes Phoenix and Arize read.
pip install prism-ai-opentelemetry
Zero runtime dependencies. Python 3.10+.
TelemetrySubscriber turns generation, step and tool events into spans. Both
conventions are emitted on the same span, because a backend reads one or the
other and a span that picks a side is invisible to half of them.
The one setting here with a privacy consequence. Prompts, messages and tool
ARGUMENTS are user content, and a span export leaves the application. They are
withheld unless you turn capture on, and a truncation ruler bounds them when you
do.
Rate limits are NOT behind that gate, deliberately: a bucket is a name, two
integers and a reset instant read off a provider's response header. Nothing the
user wrote and nothing the model returned can reach it. They travel
unconditionally because quota headroom is only useful BEFORE the 429.
Shipping with the fix that prism-opentelemetry v0.4.0 and the TypeScript
0.3.0 carry, so the three languages agree from this package's first version
rather than converging later.
Both conventions define their input count as the whole prompt side WITH cached
tokens inside it, and Prism's Usage normalises prompt_tokens to exclude
them. So gen_ai.usage.input_tokens and llm.token_count.prompt are
prompt_tokens + cache_read + cache_write. The breakdowns are emitted beside
them:
gen_ai.usage.cache_read.input_tokens llm.token_count.prompt_details.cache_read
gen_ai.usage.cache_write.input_tokens llm.token_count.prompt_details.cache_write
gen_ai.usage.reasoning.output_tokens llm.token_count.completion_details.reasoning
Absent rather than zero when a provider reports nothing, so "this provider has
no prompt caching" stays distinguishable from "the cache never hit".
A bucket name comes from the provider and becomes part of an attribute KEY, so
it is checked against an explicit codepoint set spelled identically in all three
languages — not str.lower(), which is Unicode-aware and turns a capital dotted
I into two codepoints. A name containing anything else is DROPPED rather than
normalised: repairing means two distinct names can collapse onto one key, and a
bucket named tokens followed by a zero-width space could then overwrite the
real one. At most 16 buckets reach a span.
prism-parity's opentelemetry-span-attributes runs one fixture through all
three languages. Read its findings before trusting agreement here: zero of the
first thirteen rows agreed, in six classes registered as G-23..G-28, and the
suite has no cached row yet (G-62).