Skip to content

Conversation

@codyde
Copy link
Contributor

@codyde codyde commented Oct 31, 2025

No description provided.

codyde added 13 commits October 31, 2025 00:09
- Add four comprehensive real-world examples with sample repositories
- E-Commerce Checkout Flow (Crash Commerce)
- Media Upload with Background Processing (SnapTrace)
- Search Autocomplete (NullFlix)
- Manual LLM Instrumentation (Customer Service Bot)
- Fix high-cardinality span name in payment processing
- Add missing gen_ai.response.model attribute to AI agent span
- Include implementation guidance and monitoring recommendations
- Fix duplicate finalResponse declaration (line 719)
- Fix undefined uploadId reference, use uploadData.jobId instead (line 224)
- Fix function name mismatch, call searchKnowledgeBase instead of executeKnowledgeBaseSearch (line 708)
- Serialize processing.operations array with JSON.stringify()
- Ensures proper attribute serialization in Sentry spans
- Follows Sentry conventions for non-primitive span attributes
File Upload Example:
- Use proper queue operations (queue.publish/queue.process)
- Add queue instrumentation attributes (messaging.*)
- Implement trace continuation with continueTrace()
- Link to Queues Module documentation
- Align span names with queue docs pattern (queue_producer/queue_consumer)

Search Autocomplete Example:
- Change manual span from http.client to function op
- Let SDK auto-instrument fetch requests
- Don't re-throw AbortError to avoid sending to Sentry
- Return empty results on abort instead

LLM Example:
- Add link to AI Agents Module documentation
- Reference gen_ai attribute specifications

All changes follow Sentry's documented conventions and patterns.
Remove ✨ and ❌ emoji characters from code examples that were causing
'InvalidCharacterError: Failed to execute atob' errors in docs.

The atob function only supports Latin1 (ISO-8859-1) characters, and
emojis are outside that range, causing encoding issues during page
rendering.
Replace em dashes (—) with hyphens (-) and arrows (→) with (->)
These Unicode characters were causing 'atob' encoding errors:
'InvalidCharacterError: Failed to execute atob on Window'

The atob function only supports Latin1 (ISO-8859-1) characters.
All special Unicode characters have been replaced with ASCII equivalents.
The high-cardinality fix was reverted during rebase.
Changed back from template literal to static name:
- name: 'Charge Payment Provider' (not `Charge ${requestedProvider}`)
This attribute was lost during the rebase and needs to be present
in the frontend invoke_agent span for proper AI monitoring.
Replace 'Coming soon' with link to actual example repository:
https://github.com/getsentry/llm-manual-agent-monitoring-example

This repo demonstrates custom AI agent instrumentation with tool calls,
token tracking, and conversation monitoring.
@codyde codyde requested a review from rahulchhabria October 31, 2025 20:45
@vercel
Copy link

vercel bot commented Oct 31, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
sentry-docs Building Building Preview Comment Oct 31, 2025 8:45pm
1 Skipped Deployment
Project Deployment Preview Comments Updated (UTC)
develop-docs Ignored Ignored Oct 31, 2025 8:45pm

@codyde codyde closed this Oct 31, 2025
Comment on lines +315 to +325
```typescript
// Async media processing (runs in background via setImmediate)
export async function processMedia(job: ProcessingJob): Promise<void> {
// Continue trace from producer using stored trace headers
Sentry.continueTrace(
{ sentryTrace: job.sentryTrace, baggage: job.sentryBaggage },
() => {
// Parent span for the consumer transaction
Sentry.startSpan(
{
name: 'media_processing_consumer',
Copy link

Choose a reason for hiding this comment

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

Bug: Sentry.continueTrace's synchronous callback does not await nested async Sentry.startSpan operations, causing premature trace completion.
Severity: CRITICAL | Confidence: 0.98

🔍 Detailed Analysis

The synchronous callback provided to Sentry.continueTrace initiates asynchronous operations within nested Sentry.startSpan calls, specifically await optimizeImage() and await generateThumbnail(). However, the outer synchronous callback does not await the Promise returned by Sentry.startSpan(). This causes the processMedia function to complete and the trace to potentially end before the actual asynchronous media processing finishes, leading to incomplete trace data and lost trace context.

💡 Suggested Fix

Modify the callbacks to Sentry.continueTrace and Sentry.startSpan to be async and ensure that the Promises returned by inner startSpan calls are properly awaited or returned up the call chain.

🤖 Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent.
Verify if this is a real issue. If it is, propose a fix; if not, explain why it's not
valid.

Location: docs/platforms/javascript/common/tracing/span-metrics/examples.mdx#L315-L325

Potential issue: The synchronous callback provided to `Sentry.continueTrace` initiates
asynchronous operations within nested `Sentry.startSpan` calls, specifically `await
optimizeImage()` and `await generateThumbnail()`. However, the outer synchronous
callback does not await the Promise returned by `Sentry.startSpan()`. This causes the
`processMedia` function to complete and the trace to potentially end before the actual
asynchronous media processing finishes, leading to incomplete trace data and lost trace
context.

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

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