feat(llma): Add Pydantic AI instrumentation via OpenTelemetry#379
Draft
andrewm4894 wants to merge 14 commits intomasterfrom
Draft
feat(llma): Add Pydantic AI instrumentation via OpenTelemetry#379andrewm4894 wants to merge 14 commits intomasterfrom
andrewm4894 wants to merge 14 commits intomasterfrom
Conversation
Add OpenTelemetry-based instrumentation for Pydantic AI agents:
- PostHogSpanExporter: Generic OTel exporter that translates spans to PostHog events
- PydanticAISpanExporter: Wrapper that normalizes Pydantic AI message formats and tool attributes
- instrument_pydantic_ai(): One-liner setup function for easy integration
Usage:
from posthog.ai.pydantic_ai import instrument_pydantic_ai
instrument_pydantic_ai(posthog_client, distinct_id="user_123")
agent = Agent("openai:gpt-4")
result = await agent.run("Hello") # Automatically traced
Co-Authored-By: Claude <noreply@anthropic.com>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
Agent spans now create $ai_trace events so that child spans (tools, etc.) have a valid parent reference. Previously agent spans were skipped, which caused orphaned $ai_parent_id references in tool spans.
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.
Summary
Add OpenTelemetry-based instrumentation for Pydantic AI agents. This provides a foundation for OTel-instrumented AI frameworks.
New modules:
posthog.ai.otel- Generic OTel SpanExporter that translates spans to PostHog eventsposthog.ai.pydantic_ai- Pydantic AI-specific wrapper and setup functionUsage
Architecture
PostHogSpanExporter: Generic exporter following GenAI semantic conventionsPydanticAISpanExporter: Normalizes Pydantic AI message formats and tool attribute namesChanges
posthog/ai/otel/with generic OTel exporterposthog/ai/pydantic_ai/with Pydantic AI wrapper andinstrument_pydantic_ai()pip install posthog[pydantic-ai]orpip install posthog[otel]Test plan