Skip to content

Conversation

@codyde
Copy link
Contributor

@codyde codyde commented Oct 27, 2025

Overview

Updates the span metrics instrumentation examples page with comprehensive, real-world use cases demonstrating how to instrument both frontend and backend code for distributed tracing.

What's New

Four Complete Examples with Sample Repositories

  1. E-Commerce Checkout Flow (Crash Commerce)

    • Frontend: React checkout button instrumentation with ui.action spans
    • Backend: Order processing and payment provider spans
    • Demonstrates: Cart metrics, payment provider tracking, end-to-end checkout flow
    • Metrics to monitor: p95 duration by cart size, error rates by payment provider
  2. Media Upload with Background Processing (SnapTrace)

    • Frontend: Upload experience tracking with file.upload spans
    • Backend: Validation spans and async media processing
    • Demonstrates: User-perceived upload time, async background jobs, trace continuity
    • Metrics to monitor: p95 by file size, processing success rates, storage optimization
  3. Search Autocomplete (NullFlix)

    • Frontend: Debounced search with abort handling
    • Backend: Search performance with query categorization
    • Demonstrates: Cancellable requests, slow query detection, performance patterns
    • Metrics to monitor: p95 by query length, cancellation rates, empty result rates
  4. Manual LLM Instrumentation (Customer Service Bot)

    • Frontend: AI chat interface with agent spans
    • Backend: Custom LLM integration with tool execution
    • Demonstrates: AI agent conventions, token tracking, tool call monitoring
    • Metrics to monitor: Token usage, tool performance, agent effectiveness

Key Improvements

  • Practical, production-ready examples - Each example shows real-world monitoring scenarios
  • End-to-end tracing - Demonstrates how frontend and backend spans work together in a distributed trace
  • Best practices - Shows proper span naming, attribute usage, and error handling
  • Actionable metrics - Each example includes specific span metrics queries to monitor
  • Sample repos - Links to working example repositories with Arcade demos
  • Implementation guidance - Clear notes on where to place instrumentation code

Content Structure

Each example includes:

  • Challenge statement - The monitoring problem to solve
  • Solution approach - How to instrument with spans and attributes
  • Code examples - Frontend and backend instrumentation
  • Implementation notes - Where to add code in your app
  • Trace flow explanation - How the spans connect in a distributed trace
  • Monitoring guidance - Specific span metrics queries to use

- 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
@vercel
Copy link

vercel bot commented Oct 27, 2025

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

Project Deployment Preview Comments Updated (UTC)
sentry-docs Ready Ready Preview Comment Oct 28, 2025 9:47am
1 Skipped Deployment
Project Deployment Preview Comments Updated (UTC)
develop-docs Ignored Ignored Preview Oct 28, 2025 9:47am

cursor[bot]

This comment was marked as outdated.

},
},
async (toolSpan) => {
const toolOutput = await executeKnowledgeBaseSearch(toolCall.function.arguments);
Copy link

Choose a reason for hiding this comment

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

Bug: Function executeKnowledgeBaseSearch is called but searchKnowledgeBase is defined, causing a ReferenceError.
Severity: CRITICAL | Confidence: 1.00

🔍 Detailed Analysis

The code at line 706 attempts to call executeKnowledgeBaseSearch(toolCall.function.arguments), but the corresponding function is defined as searchKnowledgeBase at line 740+. This mismatch will cause a ReferenceError when an LLM response includes tool calls and the system attempts to execute them.

💡 Suggested Fix

Rename executeKnowledgeBaseSearch to searchKnowledgeBase at line 706 to match the function definition.

🤖 Prompt for AI Agent
Fix this bug. In docs/platforms/javascript/common/tracing/span-metrics/examples.mdx at
line 706: The code at line 706 attempts to call
`executeKnowledgeBaseSearch(toolCall.function.arguments)`, but the corresponding
function is defined as `searchKnowledgeBase` at line 740+. This mismatch will cause a
`ReferenceError` when an LLM response includes tool calls and the system attempts to
execute them.

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

span?.setAttribute('job.id', uploadData.jobId);

// Update UI to show processing status
updateUploadStatus(uploadId, 'processing');
Copy link

Choose a reason for hiding this comment

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

Bug: Variable uploadId is used at line 224 without being declared or defined, leading to a ReferenceError.
Severity: CRITICAL | Confidence: 1.00

🔍 Detailed Analysis

In the handleUpload function, uploadId is referenced at line 224 within updateUploadStatus(uploadId, 'processing'). However, uploadId is never declared or defined as a variable or function parameter within its scope. This will result in a ReferenceError: uploadId is not defined when the upload completes successfully.

💡 Suggested Fix

Declare and assign a value to uploadId before its usage at line 224, likely by extracting it from uploadData.

🤖 Prompt for AI Agent
Fix this bug. In docs/platforms/javascript/common/tracing/span-metrics/examples.mdx at
line 224: In the `handleUpload` function, `uploadId` is referenced at line 224 within
`updateUploadStatus(uploadId, 'processing')`. However, `uploadId` is never declared or
defined as a variable or function parameter within its scope. This will result in a
`ReferenceError: uploadId is not defined` when the upload completes successfully.

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

- 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)
cursor[bot]

This comment was marked as outdated.

- Serialize processing.operations array with JSON.stringify()
- Ensures proper attribute serialization in Sentry spans
- Follows Sentry conventions for non-primitive span attributes
@codyde codyde requested review from Lms24, chargome and s1gr1d October 27, 2025 09:24
@codecov
Copy link

codecov bot commented Oct 27, 2025

Bundle Report

Changes will increase total bundle size by 279 bytes (0.0%) ⬆️. This is within the configured threshold ✅

Detailed changes
Bundle name Size Change
sentry-docs-client-array-push 10.16MB -6 bytes (-0.0%) ⬇️
sentry-docs-server-cjs 12.98MB 285 bytes (0.0%) ⬆️

Affected Assets, Files, and Routes:

view changes for bundle: sentry-docs-client-array-push

Assets Changed:

Asset Name Size Change Total Size Change (%)
static/chunks/pages/_app-*.js -3 bytes 882.71kB -0.0%
static/chunks/8321-*.js -3 bytes 425.87kB -0.0%
server/middleware-*.js -6.46kB 1.0kB -86.59%
server/middleware-*.js 6.46kB 7.46kB 645.5% ⚠️
static/Ix-*.js (New) 77 bytes 77 bytes 100.0% 🚀
static/Ix-*.js (New) 684 bytes 684 bytes 100.0% 🚀
static/jEw33C-*.js (Deleted) -684 bytes 0 bytes -100.0% 🗑️
static/jEw33C-*.js (Deleted) -77 bytes 0 bytes -100.0% 🗑️
view changes for bundle: sentry-docs-server-cjs

Assets Changed:

Asset Name Size Change Total Size Change (%)
1729.js -3 bytes 1.78MB -0.0%
../instrumentation.js -3 bytes 1.1MB -0.0%
9523.js -3 bytes 1.08MB -0.0%
../app/[[...path]]/page.js.nft.json 98 bytes 859.58kB 0.01%
../app/platform-redirect/page.js.nft.json 98 bytes 859.49kB 0.01%
../app/sitemap.xml/route.js.nft.json 98 bytes 856.72kB 0.01%

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