Skip to content

Conversation

@codyde
Copy link
Contributor

@codyde codyde commented Sep 29, 2025

Summary

Enhances the existing AI client markdown detection feature with improved Accept header support and structured logging using Sentry's logger format.

Key Improvements

🌐 Enhanced Accept Header Detection

Added text/plain to Accept header detection for better semantic matching:

function wantsMarkdownViaAccept(acceptHeader: string): boolean {
  return (
    acceptHeader.includes('text/markdown') ||
    acceptHeader.includes('text/x-markdown') ||
    acceptHeader.includes('text/plain')        // ← NEW
  );
}

📊 Sentry Structured Logging

Converted console.log statements to Sentry's structured logging format:

Before:

console.log(`[Middleware] ${url.pathname} - 📄 MARKDOWN (Accept header) - User-Agent: ${userAgent}`);

After:

Sentry.logger.info(`Middleware request processed: ${url.pathname}`, {
  urlPath: url.pathname,
  acceptHeader: request.headers.get('accept') || '',
  userAgent: request.headers.get('user-agent') || '',
  contentType: willServeMarkdown ? 'markdown' : 'html',
  detectionMethod: willServeMarkdown ? detectionMethod : null,
});

Real-World Impact

Example: Tools Requesting Plain Text

Common scenario with AI tools using axios:

Accept: application/json, text/plain, */*
User-Agent: axios/1.8.4

Before: Gets HTML (not ideal for programmatic use)
After: Gets markdown via text/plain detection ✅

Sentry Dashboard Analytics

With structured logging, you can now query:

// Content type distribution
contentType:markdown OR contentType:html

// Detection method effectiveness  
detectionMethod:"Accept header" OR detectionMethod:"User-agent"

// Accept header analysis
acceptHeader:"text/plain" urlPath:"/platforms/*"

// User agent patterns
userAgent:axios OR userAgent:claude

…gging

- Add text/plain to Accept header detection (markdown is plain text)
- Convert console.log to Sentry.logger.info with structured properties
- Include URL path in log message for better readability
- Log urlPath, acceptHeader, userAgent, contentType, detectionMethod

Benefits:
- Better HTTP semantics: text/plain Accept header gets markdown
- Structured analytics in Sentry dashboard
- Query by contentType, detectionMethod, urlPath, etc.
- Production-ready logging format
@vercel
Copy link

vercel bot commented Sep 29, 2025

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

Project Deployment Preview Comments Updated (UTC)
develop-docs Ready Ready Preview Comment Sep 29, 2025 4:54pm
sentry-docs Ready Ready Preview Comment Sep 29, 2025 4:54pm

cursor[bot]

This comment was marked as outdated.

- Remove unused contentType and methodInfo variables
- Fix ESLint import sorting for @sentry/nextjs import
- Resolves TypeScript TS6133 errors
@codyde codyde changed the title feat: add text/plain Accept header detection and Sentry structured logging fix: add text/plain Accept header / Axios detection + Sentry structured logging Sep 29, 2025
@codecov
Copy link

codecov bot commented Sep 29, 2025

Bundle Report

Changes will increase total bundle size by 53.01kB (0.23%) ⬆️. This is within the configured threshold ✅

Detailed changes
Bundle name Size Change
sentry-docs-edge-server-array-push 406.48kB 53.02kB (15.0%) ⬆️
sentry-docs-client-array-push 10.13MB -6 bytes (-0.0%) ⬇️
sentry-docs-server-cjs 12.9MB -9 bytes (-0.0%) ⬇️

Affected Assets, Files, and Routes:

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%
view changes for bundle: sentry-docs-edge-server-array-push

Assets Changed:

Asset Name Size Change Total Size Change (%)
src/middleware.js 53.02kB 261.71kB 25.41% ⚠️
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/Q3GjHDFVH0cJLd2uuFsCQ/_buildManifest.js (New) 684 bytes 684 bytes 100.0% 🚀
static/Q3GjHDFVH0cJLd2uuFsCQ/_ssgManifest.js (New) 77 bytes 77 bytes 100.0% 🚀
static/oniBsuoOqa41jMhL_MA-*.js (Deleted) -77 bytes 0 bytes -100.0% 🗑️
static/oniBsuoOqa41jMhL_MA-*.js (Deleted) -684 bytes 0 bytes -100.0% 🗑️

@codyde codyde merged commit b88b176 into master Sep 29, 2025
15 checks passed
@codyde codyde deleted the feat/structured-logging-improvements branch September 29, 2025 16:54
@github-actions github-actions bot locked and limited conversation to collaborators Oct 15, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants