-
-
Notifications
You must be signed in to change notification settings - Fork 4.6k
feat(ai-insights): ai agent onboarding prompt #105907
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
Merged
obostjancic
merged 10 commits into
master
from
ogi/tet-1573-make-a-claudecursor-prompt-that-manually-instruments-gen_ai
Jan 13, 2026
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
786ea71
feat(ai-insights): ai agent onboarding prompt
obostjancic a5ec19b
remove export
obostjancic 173fab1
Update static/app/views/insights/pages/agents/onboarding.tsx
obostjancic 8abbeec
Merge branch 'master' into ogi/tet-1573-make-a-claudecursor-prompt-th…
obostjancic c9038de
Merge branch 'master' into ogi/tet-1573-make-a-claudecursor-prompt-th…
obostjancic 61fb9df
Update static/app/views/insights/pages/agents/llmOnboardingInstructio…
obostjancic 6aa0a1b
Update static/app/views/insights/pages/agents/llmOnboardingInstructio…
obostjancic 8dcee3f
fixes
obostjancic 96af695
Update static/app/views/insights/pages/agents/llmOnboardingInstructio…
obostjancic de874ea
fix
obostjancic File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
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
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
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
197 changes: 197 additions & 0 deletions
197
static/app/views/insights/pages/agents/llmOnboardingInstructions.tsx
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,197 @@ | ||
| import {Button} from 'sentry/components/core/button'; | ||
| import {IconCopy} from 'sentry/icons'; | ||
| import {t} from 'sentry/locale'; | ||
| import {trackAnalytics} from 'sentry/utils/analytics'; | ||
| import useCopyToClipboard from 'sentry/utils/useCopyToClipboard'; | ||
| import useOrganization from 'sentry/utils/useOrganization'; | ||
|
|
||
| export function CopyLLMPromptButton() { | ||
| const {copy} = useCopyToClipboard(); | ||
| const organization = useOrganization(); | ||
|
|
||
| return ( | ||
| <Button | ||
| size="sm" | ||
| icon={<IconCopy />} | ||
| onClick={() => { | ||
| trackAnalytics('agent-monitoring.copy-llm-prompt-click', { | ||
| organization, | ||
| }); | ||
| copy(LLM_ONBOARDING_INSTRUCTIONS, { | ||
| successMessage: t('Copied instrumentation prompt to clipboard'), | ||
| }); | ||
| }} | ||
| > | ||
| {t('Copy Prompt for AI Agent')} | ||
| </Button> | ||
| ); | ||
| } | ||
|
|
||
| const LLM_ONBOARDING_INSTRUCTIONS = ` | ||
| # Instrument Sentry AI Agent Monitoring | ||
|
|
||
| Follow this decision tree to instrument AI Agent Monitoring. | ||
|
|
||
| ## 1. Verify Sentry + Tracing | ||
|
|
||
| **Search for Sentry initialization:** | ||
| - JS/TS: \`Sentry.init\` in entry points, \`@sentry/*\` in package.json | ||
| - Python: \`sentry_sdk.init\` in entry points, \`sentry-sdk\` in requirements | ||
|
|
||
| **If not found:** Set up Sentry first following the official docs: | ||
| - JS/TS: https://docs.sentry.io/platforms/javascript/guides/node/ | ||
| - Python: https://docs.sentry.io/platforms/python/ | ||
|
|
||
| **Verify tracing is enabled** (REQUIRED for AI monitoring): | ||
| \`\`\`javascript | ||
| // JS - must have tracesSampleRate > 0, min SDK version 10.28.0 | ||
| Sentry.init({ dsn: "...", tracesSampleRate: 1.0, sendDefaultPii: true }) | ||
| \`\`\` | ||
| \`\`\`python | ||
| # Python - must have traces_sample_rate > 0 | ||
| sentry_sdk.init(dsn="...", traces_sample_rate=1.0, send_default_pii=True) | ||
| \`\`\` | ||
|
|
||
| If missing, add \`tracesSampleRate: 1.0\` / \`traces_sample_rate=1.0\` and \`sendDefaultPii: true\` / \`send_default_pii=True\`. | ||
|
|
||
| ## 2. Check for Supported AI Libraries | ||
|
|
||
| Check in this order - **use the highest-level framework found** (e.g., if using Vercel AI SDK with OpenAI provider, use Vercel integration, not OpenAI): | ||
|
|
||
| | Library (check in order) | JS Integration | Python Integration | Python Extra | | ||
| |--------------------------|---------------|-------------------|--------------| | ||
| | Vercel AI SDK | \`Sentry.vercelAIIntegration()\` | - | - | | ||
| | LangGraph | \`Sentry.langGraphIntegration()\` | Auto-enabled | \`sentry-sdk[langgraph]\` | | ||
| | LangChain | \`Sentry.langChainIntegration()\` | Auto-enabled | \`sentry-sdk[langchain]\` | | ||
| | OpenAI Agents | - | Auto-enabled | - | | ||
| | Pydantic AI | - | Auto-enabled | \`sentry-sdk[pydantic_ai]\` | | ||
| | LiteLLM | - | \`LiteLLMIntegration()\` | \`sentry-sdk[litellm]\` | | ||
| | OpenAI | \`Sentry.openAIIntegration()\` | Auto-enabled | - | | ||
| | Anthropic | \`Sentry.anthropicAIIntegration()\` | Auto-enabled | - | | ||
| | Google GenAI | \`Sentry.googleGenAIIntegration()\` | \`GoogleGenAIIntegration()\` | \`sentry-sdk[google_genai]\` | | ||
|
|
||
| **If supported library found → Step 3A** | ||
| **If no supported library → Step 3B** | ||
|
|
||
| ## 3A. Enable Automatic Integration | ||
|
|
||
| ### JavaScript | ||
|
|
||
| Add to Sentry.init integrations array with \`recordInputs\` and \`recordOutputs\`: | ||
|
|
||
| \`\`\`javascript | ||
| import * as Sentry from "@sentry/node"; | ||
|
|
||
| Sentry.init({ | ||
| dsn: "...", | ||
| tracesSampleRate: 1.0, | ||
| sendDefaultPii: true, | ||
| integrations: [ | ||
| Sentry.openAIIntegration({ recordInputs: true, recordOutputs: true }), | ||
| // OR other integration as needed | ||
| ], | ||
| }); | ||
| \`\`\` | ||
|
|
||
| **Vercel AI SDK Extra Step:** Pass \`experimental_telemetry\` with \`functionId\` to every call: | ||
| \`\`\`javascript | ||
| const result = await generateText({ | ||
| model: openai("gpt-4o"), | ||
| prompt: "Tell me a joke", | ||
| experimental_telemetry: { | ||
| isEnabled: true, | ||
| functionId: "generate-joke", // Name your functions for better tracing | ||
| recordInputs: true, | ||
| recordOutputs: true, | ||
| }, | ||
| }); | ||
| \`\`\` | ||
|
|
||
| ### Python | ||
|
|
||
| Install with extras if needed: | ||
| \`\`\`bash | ||
| pip install sentry-sdk[langchain] # or [langgraph], [litellm], [google_genai], [pydantic_ai] | ||
| \`\`\` | ||
|
|
||
| Configure (some integrations auto-enable, some need explicit import): | ||
|
|
||
| \`\`\`python | ||
| import sentry_sdk | ||
| # Only import if NOT auto-enabled (see table above) | ||
| from sentry_sdk.integrations.openai_agents import OpenAIAgentsIntegration | ||
|
|
||
| sentry_sdk.init( | ||
| dsn="...", | ||
| traces_sample_rate=1.0, | ||
| send_default_pii=True, # Required to capture inputs/outputs | ||
| integrations=[ | ||
| OpenAIAgentsIntegration(), # Only if explicit integration needed | ||
| ], | ||
| ) | ||
| \`\`\` | ||
|
|
||
| **Done.** SDK auto-instruments AI calls. | ||
|
|
||
| ## 3B. Manual Instrumentation | ||
|
|
||
| Create spans with these exact \`op\` values and attributes: | ||
|
|
||
| ### AI Request (LLM call) | ||
| - **op:** \`"gen_ai.request"\` | ||
| - **name:** \`"chat <model>"\` | ||
| - **Required:** \`gen_ai.request.model\` | ||
| - **Recommended:** \`gen_ai.usage.input_tokens\`, \`gen_ai.usage.output_tokens\` | ||
|
|
||
| \`\`\`python | ||
| with sentry_sdk.start_span(op="gen_ai.request", name=f"chat {model}") as span: | ||
| span.set_data("gen_ai.request.model", model) | ||
| result = llm.generate(messages) | ||
| span.set_data("gen_ai.usage.input_tokens", result.input_tokens) | ||
| span.set_data("gen_ai.usage.output_tokens", result.output_tokens) | ||
obostjancic marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| span.set_data("gen_ai.usage.input_tokens.cached", result.cached_tokens) | ||
|
|
||
| \`\`\` | ||
|
|
||
| ### Invoke Agent | ||
| - **op:** \`"gen_ai.invoke_agent"\` | ||
| - **name:** \`"invoke_agent <AgentName>"\` | ||
| - **Required:** \`gen_ai.request.model\`, \`gen_ai.agent.name\` | ||
|
|
||
| \`\`\`python | ||
| with sentry_sdk.start_span(op="gen_ai.invoke_agent", name=f"invoke_agent {agent_name}") as span: | ||
| span.set_data("gen_ai.agent.name", agent_name) | ||
| span.set_data("gen_ai.request.model", model) | ||
| result = agent.run() | ||
| \`\`\` | ||
|
|
||
| ### Execute Tool | ||
| - **op:** \`"gen_ai.execute_tool"\` | ||
| - **name:** \`"execute_tool <tool_name>"\` | ||
| - **Required:** \`gen_ai.tool.name\` | ||
|
|
||
| \`\`\`python | ||
| with sentry_sdk.start_span(op="gen_ai.execute_tool", name=f"execute_tool {tool_name}") as span: | ||
| span.set_data("gen_ai.tool.name", tool_name) | ||
| span.set_data("gen_ai.tool.input", json.dumps(inputs)) | ||
| result = tool(**inputs) | ||
| span.set_data("gen_ai.tool.output", json.dumps(result)) | ||
| \`\`\` | ||
|
|
||
| ### Handoff (agent-to-agent) | ||
| - **op:** \`"gen_ai.handoff"\` | ||
| - **name:** \`"handoff from <A> to <B>"\` | ||
|
|
||
| \`\`\`python | ||
| with sentry_sdk.start_span(op="gen_ai.handoff", name=f"handoff from {a} to {b}"): | ||
| pass | ||
| \`\`\` | ||
|
|
||
| ## Key Rules | ||
|
|
||
| 1. **All complex data must be JSON-stringified** - span attributes only accept primitives | ||
| 2. **\`gen_ai.request.model\` is required** on \`gen_ai.request\` and \`gen_ai.invoke_agent\` spans | ||
| 3. **Nest spans correctly:** \`gen_ai.invoke_agent\` spans should contain \`gen_ai.request\` and \`gen_ai.execute_tool\` spans as children | ||
| 4. **JS min version:** \`@sentry/[email protected]\` or later | ||
| 5. **Enable PII:** \`sendDefaultPii: true\` (JS) / \`send_default_pii=True\` (Python) to capture inputs/outputs | ||
| `; | ||
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.