Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 78 additions & 0 deletions static/app/gettingStartedDocs/python/python.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,8 @@ export const agentMonitoringOnboarding: OnboardingConfig = {
packageName = 'sentry-sdk[langgraph]';
} else if (selected === 'litellm') {
packageName = 'sentry-sdk[litellm]';
} else if (selected === 'pydantic_ai') {
packageName = 'sentry-sdk[pydantic_ai]';
}

return [
Expand Down Expand Up @@ -724,6 +726,50 @@ sentry_sdk.init(
],
};

const pydanticAiStep: OnboardingStep = {
type: StepType.CONFIGURE,
content: [
{
type: 'text',
text: tct(
'Import and initialize the Sentry SDK for [pydantic_ai:Pydantic AI] monitoring:',
{
pydantic_ai: (
<ExternalLink href="https://docs.sentry.io/platforms/python/integrations/pydantic-ai/" />
),
}
),
},
{
type: 'code',
language: 'python',
code: `
import sentry_sdk
from sentry_sdk.integrations.pydantic_ai import PydanticAiIntegration

sentry_sdk.init(
dsn="${params.dsn.public}",
environment="local",
traces_sample_rate=1.0,
# Add data like inputs and responses to/from LLMs and tools;
# see https://docs.sentry.io/platforms/python/data-management/data-collected/ for more info
send_default_pii=True,
integrations=[
PydanticAiIntegration(),
],
# Disable OpenAI integration for correct token accounting
disabled_integrations=[OpenAIIntegration()],
)`,
Comment on lines +752 to +762
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Potential bug: The Pydantic AI getting started code snippet uses OpenAIIntegration without importing it, which will cause a NameError when the code is executed.
  • Description: The Python code snippet for the pydanticAiStep in the getting started documentation uses OpenAIIntegration within the disabled_integrations list. However, it omits the necessary import statement for OpenAIIntegration. When a user copies and executes this code, their application will raise a NameError during the sentry_sdk.init() call, preventing the application from starting. This pattern is inconsistent with other similar code snippets in the same file which correctly include the import.

  • Suggested fix: Add from sentry_sdk.integrations.openai import OpenAIIntegration to the Python code snippet within the pydanticAiStep component. This will resolve the NameError by making the class available before it's referenced in disabled_integrations.
    severity: 0.85, confidence: 1.0

Did we get this right? 👍 / 👎 to inform future reviews.

},
{
type: 'text',
text: t(
'The Pydantic AI integration will automatically collect information about agents, tools, prompts, tokens, and models.'
),
},
],
};

const selected = (params.platformOptions as any)?.integration ?? 'openai_agents';
if (selected === 'openai') {
return [openaiSdkStep];
Expand All @@ -740,6 +786,9 @@ sentry_sdk.init(
if (selected === 'litellm') {
return [liteLLMStep];
}
if (selected === 'pydantic_ai') {
return [pydanticAiStep];
}
if (selected === 'manual') {
return [manualStep];
}
Expand Down Expand Up @@ -973,6 +1022,32 @@ print(response.choices[0].message.content)
],
};

const pydanticAiVerifyStep: OnboardingStep = {
type: StepType.VERIFY,
content: [
{
type: 'text',
text: t(
'Verify that agent monitoring is working correctly by creating a Pydantic AI agent:'
),
},
{
type: 'code',
language: 'python',
code: `
from pydantic_ai import Agent

# Create an agent with OpenAI model
agent = Agent('openai:gpt-4o-mini')

# Run the agent
result = agent.run_sync('Tell me a joke')
print(result.data)
`,
},
],
};

const manualVerifyStep: OnboardingStep = {
type: StepType.VERIFY,
content: [
Expand Down Expand Up @@ -1025,6 +1100,9 @@ with sentry_sdk.start_span(op="gen_ai.chat", name="chat o3-mini") as span:
if (selected === 'litellm') {
return [liteLLMVerifyStep];
}
if (selected === 'pydantic_ai') {
return [pydanticAiVerifyStep];
}
if (selected === 'manual') {
return [manualVerifyStep];
}
Expand Down
1 change: 1 addition & 0 deletions static/app/views/insights/agents/views/onboarding.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@ export function Onboarding() {
{label: 'LangChain', value: 'langchain'},
{label: 'LangGraph', value: 'langgraph'},
{label: 'LiteLLM', value: 'litellm'},
{label: 'Pydantic AI', value: 'pydantic_ai'},
{label: 'Manual', value: 'manual'},
]
: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ const knownSpanOrigins = {
'auto.ai.langgraph',
'auto.ai.anthropic',
'auto.ai.litellm',
'auto.ai.pydantic_ai',
],
javascript: ['auto.ai.anthropic', 'auto.ai.openai', 'auto.vercelai.otel'],
} as const;
Expand Down Expand Up @@ -136,6 +137,8 @@ const pythonIntegrationLinks: Record<PythonSpanOrigin, string> = {
'auto.ai.langgraph': 'https://docs.sentry.io/platforms/python/integrations/langgraph/',
'auto.ai.anthropic': 'https://docs.sentry.io/platforms/python/integrations/anthropic/',
'auto.ai.litellm': 'https://docs.sentry.io/platforms/python/integrations/litellm/',
'auto.ai.pydantic_ai':
'https://docs.sentry.io/platforms/python/integrations/pydantic-ai/',
};

function PythonContent({
Expand Down
Loading