Repository navigation
Conversation
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This was referenced Sep 25, 2026
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🤖 Claude-generated PR description
Each
prompt()andchain()call on a wrapped model or conversation now emits one OpenTelemetry span,datasette_llm.prompt(scopedatasette_llm). It records the one thing llm itself can't know: the purpose a Datasette plugin declared for the call.Attributes
datasette_llm.kind:"prompt"or"chain"datasette_llm.purpose: the declared purpose, or"none"gen_ai.request.model: the model IDdatasette_llm.actor.present: a boolean, never the actor itselferror.type: the exception class name on failure.llm.PauseChainis not an error.No prompt or response text, actor details or error messages are recorded. The span has no exception events and no status description.
Shape
AsyncExitStack(WrappedAsyncChainResponse.responses(),WrappedConversation.prompt(),WrappedAsyncModel.prompt()). It is current for thellm_prompt_contexthooks and, for chains, for the whole iteration, so llm's ownchat/execute_toolspans (from an llm release with OpenTelemetry support) nest under it.__init__.pygains 20 added lines and no re-indents.prompt()awaits the llm response, which forces the whole model call. The span therefore covers hooks plus the full call.opentelemetry-api>=1.37. When no SDK is configured the span is non-recording, and the code then never attaches a context. So behaviour without an SDK is unchanged, including when a caller abandons a chain mid-iteration.aclose()(for example, a client disconnect mid-stream) still ends cleanly:datasette_llm.outcome="abandoned".context.detach().contextlib.aclosing(...)to avoid it.PauseChainis looked up withgetattr, sollm>=0.32a1(beforePauseChainexisted) still works.Tests
tests/test_telemetry.pyuses a session-scopedTracerProvider+InMemorySpanExporter. It covers:ValueError, and a hook raisingPauseChainuv run pytest: 65 passed. Tests also cover an abandoned chain (no detach error, outcome abandoned) and a hook that leaks a context (not propagated to the caller).opentelemetry-sdk>=1.37is added to thedevgroup only.🤖 Generated with Claude Code