Skip to content

feat(ai-monitoring): add sampling guidance and Node.js AI monitoring reference#87

Merged
sergical merged 7 commits intomainfrom
feat/ai-monitoring-sampling-guidance
Mar 31, 2026
Merged

feat(ai-monitoring): add sampling guidance and Node.js AI monitoring reference#87
sergical merged 7 commits intomainfrom
feat/ai-monitoring-sampling-guidance

Conversation

@sergical
Copy link
Copy Markdown
Member

Summary

  • Add sentry-setup-ai-monitoring/references/sampling.md with gen_ai span sampling strategies for JS + Python
  • Add sentry-node-sdk/references/ai-monitoring.md (was missing, Python/Next.js/NestJS already had one)
  • Update sentry-setup-ai-monitoring/SKILL.md with sampling rate detection + user prompt
  • Add sampling cross-links to Python, Next.js, and NestJS ai-monitoring references

What the sampling reference covers

  • Why gen_ai spans need special sampling (all-or-nothing span trees)
  • Head-based sampling mechanics (root-only, children inherit)
  • Two scenarios: gen_ai as root span vs child of HTTP transaction
  • Working tracesSampler (JS) and traces_sampler (Python) patterns
  • Metrics/logs fallback when 100% tracing isn't feasible
  • Decision guide and troubleshooting table

What the Node.js reference covers

  • Integration matrix (OpenAI, Anthropic, Vercel AI SDK, LangChain, LangGraph, Google GenAI)
  • PII control, browser wrapping, streaming requirements
  • Manual gen_ai.* span instrumentation
  • Token usage attributes and cost tracking

IS YOUR CHANGE URGENT?

  • Urgent deadline (GA date, etc.)
  • Other deadline
  • None: Not urgent

🤖 Generated with Claude Code

sergical and others added 5 commits March 30, 2026 11:43
…reference

Add sampling strategy reference for gen_ai spans (JS + Python) covering:
- Head-based sampling gotcha (root-only, children inherit)
- tracesSampler patterns for both standalone agents and HTTP-child scenarios
- Metrics/logs fallback for when 100% tracing isn't feasible
- Cost comparison and troubleshooting

Also adds:
- Node.js ai-monitoring.md reference (was missing, Python/Next.js/NestJS had one)
- Sampling check + user prompt to SKILL.md detection flow
- Sampling cross-links to Python, Next.js, and NestJS references

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- sampling.md: 242 → 78 lines. Removed 4 redundant code blocks (JS+Python
  metrics+logs shown separately), consolidated into one Python example + note
  that JS uses same pattern. Removed comparison table.
- ai-monitoring.md (Node): 341 → 95 lines. Removed per-integration
  setup/wrapping/streaming sections, consolidated into single setup block
  with important notes callout.
- Updated model names from gpt-4o to claude-sonnet-4-6.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Match Python SDK reference structure: add Integration Matrix with min
library versions, Configuration Examples (auto + explicit + Vercel AI +
browser), 4 manual instrumentation examples (chat, invoke_agent,
execute_tool, handoff), Span Attribute Reference tables, Agent Workflow
Hierarchy diagram, Streaming compatibility table. Updated model names.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Lists providers without auto-instrumentation in Node (Pydantic AI,
OpenAI Agents SDK, HuggingFace Hub, MCP are Python-only; Cohere,
Bedrock, Mistral, Groq need manual spans in both).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Pydantic AI, OpenAI Agents SDK, HuggingFace Hub are Python libraries -
not relevant to Node developers. MCP is a separate product with its own
docs. Keep only providers a Node developer might actually encounter:
Cohere, Bedrock, Mistral, Groq.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@sergical sergical marked this pull request as ready for review March 31, 2026 15:17
Comment on lines +134 to +144
### `gen_ai.handoff` - Agent-to-agent transition

```typescript
await Sentry.startSpan({
op: "gen_ai.handoff",
name: "handoff Billing → Refund Agent",
attributes: { "gen_ai.agent.name": "Refund Agent" },
}, async (span) => {
return await refundAgent.run(context);
});
```
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We plan to remove this span type in the future so we should probably omit it here.

Suggested change
### `gen_ai.handoff` - Agent-to-agent transition
```typescript
await Sentry.startSpan({
op: "gen_ai.handoff",
name: "handoff Billing → Refund Agent",
attributes: { "gen_ai.agent.name": "Refund Agent" },
}, async (span) => {
return await refundAgent.run(context);
});
```


```typescript
await generateText({
model: openai("claude-sonnet-4-6"),
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
model: openai("claude-sonnet-4-6"),
model: openai("gpt-5.4"),

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

omg 🤦 they are really missing out on something like this https://community.openai.com/t/introducing-codex-plugin-for-claude-code/1378186 😂

- Remove gen_ai.handoff example (planned for deprecation per @obostjancic)
- Fix openai("claude-sonnet-4-6") → openai("gpt-4.1") (wrong provider/model combo)
- Remove handoff from span hierarchy diagram

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
gen_ai.chat is an internal SDK op. The docs document gen_ai.request
for manual instrumentation. Fixed all code examples and span hierarchy.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@sergical sergical merged commit c544c10 into main Mar 31, 2026
10 of 11 checks passed
@sergical sergical deleted the feat/ai-monitoring-sampling-guidance branch March 31, 2026 17:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants