Skip to content

Conversation

@sergical
Copy link
Member

@sergical sergical commented Jan 13, 2026

Closes https://linear.app/getsentry/issue/DEVEX-227/metrics

Summary

  • Creates dedicated metrics guide for Next.js
  • Shows patterns for API routes, Server Actions, and middleware
  • Includes attribute best practices
  • Follows the logs/tracing doc pattern with SplitLayout

Why Override?

The common metrics doc shows generic JavaScript examples. This override adds:

  • Next.js-specific patterns (Server Actions, middleware)
  • Runtime context (works in client/server/edge)
  • Practical examples developers can copy

Test plan

  • Verify page renders at /platforms/javascript/guides/nextjs/metrics/
  • Check SplitLayout renders correctly
  • Verify beta badge appears

🤖 Generated with Claude Code

@vercel
Copy link

vercel bot commented Jan 13, 2026

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

Project Deployment Review Updated (UTC)
develop-docs Ready Ready Preview, Comment Jan 15, 2026 8:27pm
sentry-docs Ready Ready Preview, Comment Jan 15, 2026 8:27pm

Review with Vercel Agent

Comment on lines 144 to 169
export function middleware(request: NextRequest) {
Sentry.metrics.count("requests", 1, {
attributes: {
path: request.nextUrl.pathname,
method: request.method,
},
});

This comment was marked as outdated.

Comment on lines 178 to 206
```typescript
Sentry.metrics.count("api_calls", 1, {
attributes: {
endpoint: "/api/orders",
user_tier: "pro",
region: "us-west",
user_id: user.id,
order_id: order.id,
},
});

This comment was marked as outdated.

@linear
Copy link

linear bot commented Jan 14, 2026

DEVEX-227 Metrics

Copy link
Member

@chargome chargome left a comment

Choose a reason for hiding this comment

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

I love the change! I would just rather not have different versions of the metrics documentation for js out there as we would have to maintain them all, wdyt of rolling this out for all js docs and just adding the "Nextjs Patterns" part specifically here?

|------|---------|
| `count` | Events (orders, clicks, API calls) |
| `gauge` | Current values (queue depth, connections) |
| `distribution` | Value ranges (response times, payload sizes) |
Copy link
Member

Choose a reason for hiding this comment

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

The distribution part does not break well on smaller displays:

Image

beta: true
---

Sentry Metrics let you track custom application data beyond errors and traces. Track business metrics like orders processed, API response times, or cache hit rates across all Next.js runtimes.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
Sentry Metrics let you track custom application data beyond errors and traces. Track business metrics like orders processed, API response times, or cache hit rates across all Next.js runtimes.
[Sentry Metrics](/product/explore/metrics/) let you track custom application data beyond errors and traces. Track business metrics like orders processed, API response times, or cache hit rates across all Next.js runtimes.

We say almost nothing about the value prop of this feature here. We need to at least link out to the product docs.


## Options

Configure these options in **all three runtime files** (`instrumentation-client.ts`, `sentry.server.config.ts`, `sentry.edge.config.ts`).
Copy link
Contributor

Choose a reason for hiding this comment

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

Are we assuming that of someone has gotten this far, they know about the config of these files already? Is there something we could link to that references the sentry-specific config files?


### Flush Metrics

Metrics are buffered and sent periodically. To flush immediately:
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
Metrics are buffered and sent periodically. To flush immediately:
Metrics are buffered and sent periodically. Use this snippet ot flush immediately -

Comment on lines 291 to 299
**If user is set:**
- `user.id`, `user.name`, `user.email`

**Client-side:**
- `browser.name`, `browser.version`, `sentry.replay_id`

**Server-side:**
- `server.address`

Copy link
Contributor

Choose a reason for hiding this comment

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

I can't tell why these are formatted differently. I'd add them to the table above and just have a note for "if user is set", "client-side", "server-side".

Copy link
Contributor

@sfanahata sfanahata left a comment

Choose a reason for hiding this comment

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

@chargome has a good point. This shouldn't be a blocker, per say, but could this be the common file with nextjs-specific references inserted in through includes?

sergical and others added 5 commits January 15, 2026 14:47
Creates a dedicated metrics guide showing:
- Metric types (count, gauge, distribution)
- Next.js patterns (API routes, Server Actions, middleware)
- Attribute best practices (avoid high-cardinality)
- Quick reference tables

Follows technical-docs skill principles: concise, pattern-focused,
no redundant API documentation.

Co-Authored-By: Claude Opus 4.5 <[email protected]>
- Move metrics content to common JS doc with SplitLayout format
- Add Next.js-specific patterns as platform include
- Delete dedicated Next.js metrics page (content now in common + includes)
- Fix CSS width constraint to only apply on 1800px+ screens
- Add link to product docs in intro
- Consolidate Default Attributes into single table
- Rename Requirements to Prerequisites with getting started link

Addresses PR feedback from @chargome and @sfanahata

Co-Authored-By: Claude Opus 4.5 <[email protected]>
Move inline SplitLayout content from common metrics doc to platform-include
files where it belongs. This follows the docs architecture pattern and
restores the original SEO description and alert text.

Changes:
- Restore common doc to use <PlatformContent> for usage/options/default-attributes
- Move SplitLayout components to platform-includes/metrics/usage/javascript.mdx
- Move options SplitLayout to platform-includes/metrics/options/javascript.mdx
- Consolidate default-attributes into a cleaner table format

Co-Authored-By: Claude <[email protected]>
- First/middle columns now use white-space: nowrap to keep config names,
  options, and short values compact
- Only last column allows word-break for long descriptions
- Revert SplitLayout styles to original 80% max-width with mobile override

Co-Authored-By: Claude <[email protected]>
@sergical sergical force-pushed the docs/nextjs-metrics-override branch from d9586fd to 4fd3901 Compare January 15, 2026 19:48
Restore documentation for using getGlobalScope() and withScope() to set
attributes that apply to all metrics (10.33.0+).

Co-Authored-By: Claude <[email protected]>
- Add display: block and overflow-x: auto for horizontal scroll
- Add min-width: 200px to last column to prevent squishing

Co-Authored-By: Claude <[email protected]>
@sergical sergical force-pushed the docs/nextjs-metrics-override branch from 8f48c0c to 05a4343 Compare January 15, 2026 20:17
Comment on lines +192 to +193
display: block;
overflow-x: auto;
Copy link

Choose a reason for hiding this comment

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

Bug: Setting display: block on <table> elements makes the border-collapse: collapse rule ineffective, causing incorrect border rendering and accessibility issues.
Severity: HIGH

Suggested Fix

To enable horizontal scrolling, wrap the <table> element in a container <div> and apply overflow-x: auto to the wrapper. Remove the display: block style from the table element itself to ensure border-collapse and other table-specific properties function correctly.

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: src/components/docPage/type.scss#L192-L193

Potential issue: In `src/components/docPage/type.scss`, setting `display: block` on
`<table>` elements is incompatible with the `border-collapse: collapse` property that is
also being applied. The `border-collapse` property only works on elements with `display:
table` or `display: inline-table`. Consequently, browsers will ignore the
`border-collapse` rule, causing table borders to render incorrectly (separated instead
of merged). This change will also negatively impact accessibility by altering the
semantic structure of tables for screen readers, and may lead to inconsistent column
width rendering.

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.

4 participants