-
Notifications
You must be signed in to change notification settings - Fork 50
feat(llma): Add Pydantic AI instrumentation via OpenTelemetry #379
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
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 <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
13 files reviewed, 4 comments
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 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.
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