-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Metrics Product Docs #15375
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
coolguyzone
wants to merge
3
commits into
master
Choose a base branch
from
metrics-docs
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Metrics Product Docs #15375
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,380 @@ | ||
| --- | ||
| title: Set Up | ||
| sidebar_order: 0 | ||
| description: "Learn how to set up Sentry's Metrics feature using our supported SDKs." | ||
| --- | ||
|
|
||
| <Alert level="info"> | ||
| Metrics is currently in Open Beta for non-Enterprise plans runing the JavaScript or Python SDKs. If you'd like access, please comment with your org slug on [this GitHub discussion](https://github.com/getsentry/sentry/discussions/102275) or contact us at [email protected]. | ||
| </Alert> | ||
|
|
||
| To set up Sentry Metrics, use the links below for supported SDKs. After it's been set up, you'll be able to send counters, gauges, and distributions from your code and view them in Sentry with direct links to related traces. | ||
|
|
||
| ## Supported SDKs | ||
|
|
||
| ### JavaScript | ||
|
|
||
| Minimum SDK version: **10.20.0** | ||
|
|
||
| - <LinkWithPlatformIcon | ||
| platform="javascript.browser" | ||
| label="Browser JavaScript" | ||
| url="/platforms/javascript/metrics/" | ||
| /> | ||
| - <LinkWithPlatformIcon | ||
| platform="javascript.angular" | ||
| label="Angular" | ||
| url="/platforms/javascript/guides/angular/metrics/" | ||
| /> | ||
| - <LinkWithPlatformIcon | ||
| platform="javascript.astro" | ||
| label="Astro" | ||
| url="/platforms/javascript/guides/astro/metrics/" | ||
| /> | ||
| - <LinkWithPlatformIcon | ||
| platform="javascript.aws-lambda" | ||
| label="AWS Lambda" | ||
| url="/platforms/javascript/guides/aws-lambda/metrics/" | ||
| /> | ||
| - <LinkWithPlatformIcon | ||
| platform="javascript.azure-functions" | ||
| label="Azure Functions" | ||
| url="/platforms/javascript/guides/azure-functions/metrics/" | ||
| /> | ||
| - <LinkWithPlatformIcon | ||
| platform="javascript.bun" | ||
| label="Bun" | ||
| url="/platforms/javascript/guides/bun/metrics/" | ||
| /> | ||
| - <LinkWithPlatformIcon | ||
| platform="javascript.cloudflare" | ||
| label="Cloudflare" | ||
| url="/platforms/javascript/guides/cloudflare/metrics/" | ||
| /> | ||
| - <LinkWithPlatformIcon | ||
| platform="javascript.connect" | ||
| label="Connect" | ||
| url="/platforms/javascript/guides/connect/metrics/" | ||
| /> | ||
| - <LinkWithPlatformIcon | ||
| platform="javascript.electron" | ||
| label="Electron" | ||
| url="/platforms/javascript/guides/electron/metrics/" | ||
| /> | ||
| - <LinkWithPlatformIcon | ||
| platform="javascript.ember" | ||
| label="Ember" | ||
| url="/platforms/javascript/guides/ember/metrics/" | ||
| /> | ||
| - <LinkWithPlatformIcon | ||
| platform="javascript.express" | ||
| label="Express" | ||
| url="/platforms/javascript/guides/express/metrics/" | ||
| /> | ||
| - <LinkWithPlatformIcon | ||
| platform="javascript.fastify" | ||
| label="Fastify" | ||
| url="/platforms/javascript/guides/fastify/metrics/" | ||
| /> | ||
| - <LinkWithPlatformIcon | ||
| platform="javascript.gatsby" | ||
| label="Gatsby" | ||
| url="/platforms/javascript/guides/gatsby/metrics/" | ||
| /> | ||
| - <LinkWithPlatformIcon | ||
| platform="javascript.gcp-functions" | ||
| label="Google Cloud Functions" | ||
| url="/platforms/javascript/guides/gcp-functions/metrics/" | ||
| /> | ||
| - <LinkWithPlatformIcon | ||
| platform="javascript.hapi" | ||
| label="Hapi" | ||
| url="/platforms/javascript/guides/hapi/metrics/" | ||
| /> | ||
| - <LinkWithPlatformIcon | ||
| platform="javascript.hono" | ||
| label="Hono" | ||
| url="/platforms/javascript/guides/hono/metrics/" | ||
| /> | ||
| - <LinkWithPlatformIcon | ||
| platform="javascript.koa" | ||
| label="Koa" | ||
| url="/platforms/javascript/guides/koa/metrics/" | ||
| /> | ||
| - <LinkWithPlatformIcon | ||
| platform="javascript.nestjs" | ||
| label="Nest.js" | ||
| url="/platforms/javascript/guides/nestjs/metrics/" | ||
| /> | ||
| - <LinkWithPlatformIcon | ||
| platform="javascript.node" | ||
| label="Node.js" | ||
| url="/platforms/javascript/guides/node/metrics/" | ||
| /> | ||
| - <LinkWithPlatformIcon | ||
| platform="javascript.nextjs" | ||
| label="Next.js" | ||
| url="/platforms/javascript/guides/nextjs/metrics/" | ||
| /> | ||
| - <LinkWithPlatformIcon | ||
| platform="javascript.nuxt" | ||
| label="Nuxt" | ||
| url="/platforms/javascript/guides/nuxt/metrics/" | ||
| /> | ||
| - <LinkWithPlatformIcon | ||
| platform="javascript.react" | ||
| label="React" | ||
| url="/platforms/javascript/guides/react/metrics/" | ||
| /> | ||
| - <LinkWithPlatformIcon | ||
| platform="javascript.react-router" | ||
| label="React Router" | ||
| url="/platforms/javascript/guides/react-router/metrics/" | ||
| /> | ||
| - <LinkWithPlatformIcon | ||
| platform="javascript.remix" | ||
| label="Remix" | ||
| url="/platforms/javascript/guides/remix/metrics/" | ||
| /> | ||
| - <LinkWithPlatformIcon | ||
| platform="javascript.solid" | ||
| label="Solid" | ||
| url="/platforms/javascript/guides/solid/metrics/" | ||
| /> | ||
| - <LinkWithPlatformIcon | ||
| platform="javascript.solidstart" | ||
| label="SolidStart" | ||
| url="/platforms/javascript/guides/solidstart/metrics/" | ||
| /> | ||
| - <LinkWithPlatformIcon | ||
| platform="javascript.svelte" | ||
| label="Svelte" | ||
| url="/platforms/javascript/guides/svelte/metrics/" | ||
| /> | ||
| - <LinkWithPlatformIcon | ||
| platform="javascript.sveltekit" | ||
| label="SvelteKit" | ||
| url="/platforms/javascript/guides/sveltekit/metrics/" | ||
| /> | ||
| - <LinkWithPlatformIcon | ||
| platform="javascript.tanstackstart-react" | ||
| label="TanStack Start" | ||
| url="/platforms/javascript/guides/tanstackstart-react/metrics/" | ||
| /> | ||
| - <LinkWithPlatformIcon | ||
| platform="javascript.vue" | ||
| label="Vue" | ||
| url="/platforms/javascript/guides/vue/metrics/" | ||
| /> | ||
| - <LinkWithPlatformIcon | ||
| platform="javascript.wasm" | ||
| label="Wasm" | ||
| url="/platforms/javascript/guides/wasm/metrics/" | ||
| /> | ||
|
|
||
| ### Python | ||
|
|
||
| Minimum SDK version: **2.43.0** | ||
|
|
||
| - <LinkWithPlatformIcon | ||
| platform="python" | ||
| label="Python" | ||
| url="/platforms/python/metrics/" | ||
| /> | ||
| - <LinkWithPlatformIcon | ||
| platform="python.django" | ||
| label="Django" | ||
| url="/platforms/python/guides/django/metrics/" | ||
| /> | ||
| - <LinkWithPlatformIcon | ||
| platform="python.flask" | ||
| label="Flask" | ||
| url="/platforms/python/guides/flask/metrics/" | ||
| /> | ||
| - <LinkWithPlatformIcon | ||
| platform="python.fastapi" | ||
| label="FastAPI" | ||
| url="/platforms/python/guides/fastapi/metrics/" | ||
| /> | ||
| - <LinkWithPlatformIcon | ||
| platform="python.starlette" | ||
| label="Starlette" | ||
| url="/platforms/python/guides/starlette/metrics/" | ||
| /> | ||
| - <LinkWithPlatformIcon | ||
| platform="python.celery" | ||
| label="Celery" | ||
| url="/platforms/python/guides/celery/metrics/" | ||
| /> | ||
| - <LinkWithPlatformIcon | ||
| platform="python.aws-lambda" | ||
| label="AWS Lambda" | ||
| url="/platforms/python/guides/aws-lambda/metrics/" | ||
| /> | ||
| - <LinkWithPlatformIcon | ||
| platform="python.gcp-functions" | ||
| label="Google Cloud Functions" | ||
| url="/platforms/python/guides/gcp-functions/metrics/" | ||
| /> | ||
|
|
||
| ## Quick Start Examples | ||
|
|
||
| ### JavaScript Example | ||
|
|
||
| First, enable metrics in your Sentry initialization: | ||
|
|
||
| ```javascript | ||
| import * as Sentry from "@sentry/node"; // or your specific framework | ||
|
|
||
| Sentry.init({ | ||
| dsn: '<your-dsn>', | ||
| _experiments: { | ||
| enableMetrics: true | ||
| }, | ||
| }); | ||
| ``` | ||
|
|
||
| Then use the metrics API to send counters, gauges, and distributions: | ||
|
|
||
| ```javascript | ||
| // Counter — increment a metric (defaults to +1) | ||
| Sentry.metrics.count('checkout.failed', 1, { | ||
| attributes: { | ||
| route: '/checkout', | ||
| tenant: 'acme', | ||
| provider: 'stripe', | ||
| }, | ||
| }); | ||
|
|
||
| // Gauge — set a current value | ||
| Sentry.metrics.gauge('queue.depth', 42, { | ||
| unit: 'items', | ||
| attributes: { | ||
| queue: 'emails', | ||
| region: 'us-east-1', | ||
| }, | ||
| }); | ||
|
|
||
| // Distribution — record numeric values to compute p95, avg, sum, etc. | ||
| Sentry.metrics.distribution('cart.amount_usd', 187.5, { | ||
| unit: 'usd', | ||
| attributes: { | ||
| currency: 'USD', | ||
| tenant: 'acme', | ||
| }, | ||
| }); | ||
| ``` | ||
|
|
||
| Each metric event includes: | ||
| - **name**: The metric identifier | ||
| - **kind**: counter, gauge, or distribution | ||
| - **value**: The numeric value | ||
| - **attributes**: Custom key-value pairs for grouping and filtering | ||
| - **trace_id, span_id**: Automatically attached to link with traces | ||
| - **unit** (optional): Unit of measurement | ||
| - **byte_size** (optional): Size information | ||
|
|
||
| More details: [JavaScript SDK Metrics Discussion](https://github.com/getsentry/sentry-javascript/discussions/18055) | ||
|
|
||
| ### Python Example | ||
|
|
||
| First, enable metrics in your Sentry initialization: | ||
|
|
||
| ```python | ||
| import sentry_sdk | ||
| from sentry_sdk import metrics | ||
|
|
||
| sentry_sdk.init( | ||
| dsn="___PUBLIC_DSN___", | ||
| _experiments={ | ||
| "enable_metrics": True, | ||
| }, | ||
| ) | ||
| ``` | ||
|
|
||
| Then use the metrics API to send counters, gauges, and distributions: | ||
|
|
||
| ```python | ||
| # Counter — increment a metric (defaults to +1) | ||
| metrics.count( | ||
| "checkout.failed", | ||
| 1, | ||
| attributes={"route": "/checkout", "tenant": "acme"} | ||
| ) | ||
|
|
||
| # Gauge — set a current value | ||
| metrics.gauge( | ||
| "queue.depth", | ||
| 42, | ||
| attributes={"queue": "emails"} | ||
| ) | ||
|
|
||
| # Distribution — record numeric values to compute p95, avg, sum, etc. | ||
| metrics.distribution( | ||
| "cart.amount_usd", | ||
| 187.5, | ||
| attributes={"currency": "USD", "tenant": "acme"} | ||
| ) | ||
| ``` | ||
|
|
||
| Each metric event includes: | ||
| - **name**: The metric identifier | ||
| - **kind**: counter, gauge, or distribution | ||
| - **value**: The numeric value | ||
| - **attributes**: Custom key-value pairs for grouping and filtering | ||
| - **trace_id, span_id**: Automatically attached to link with traces | ||
| - **unit** (optional): Unit of measurement | ||
|
|
||
| More details: [Python SDK Metrics Discussion](https://github.com/getsentry/sentry-python/discussions/5042) | ||
|
|
||
| ## Best Practices | ||
|
|
||
| ### Naming Conventions | ||
|
|
||
| Use descriptive, dot-separated names that indicate the metric's purpose: | ||
|
|
||
| - **Good**: `checkout.failed`, `email.sent`, `queue.depth` | ||
| - **Avoid**: `metric1`, `counter`, `x` | ||
|
|
||
| ### Attributes | ||
|
|
||
| Add attributes for any dimension you want to group or filter by: | ||
|
|
||
| ```javascript | ||
| Sentry.metrics.count('api.request', 1, { | ||
| attributes: { | ||
| endpoint: '/users', | ||
| method: 'GET', | ||
| status: '200', | ||
| region: 'us-west', | ||
| }, | ||
| }); | ||
| ``` | ||
|
|
||
| This allows you to query metrics like: | ||
| - `sum(api.request)` grouped by `endpoint` | ||
| - `sum(api.request)` where `status:500` | ||
| - `sum(api.request)` grouped by `region` where `method:POST` | ||
|
|
||
| ### Units | ||
|
|
||
| Always specify units for clarity: | ||
|
|
||
| - Time: `ms`, `seconds` | ||
| - Size: `bytes`, `kb`, `mb` | ||
| - Currency: `usd`, `eur` | ||
| - Count: `items`, `requests`, `users` | ||
|
|
||
| ### When to Instrument | ||
|
|
||
| Add metrics at key decision points in your code: | ||
|
|
||
| - **Before/after critical operations**: Track success and failure rates | ||
| - **At service boundaries**: Monitor external API calls, database queries | ||
| - **Business logic**: Capture important business events | ||
| - **Resource usage**: Track queue depths, connection pools, cache sizes | ||
|
|
||
| ## Upcoming SDKs | ||
|
|
||
| We're actively working on adding Metrics functionality to additional SDKs. If you don't see your platform listed above, please reach out to us on [GitHub](https://github.com/getsentry/sentry/discussions/102275) or contact us at [[email protected]](mailto:[email protected]). | ||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bug: New documentation links are silently redirected to old span-metrics content due to existing
redirects.jsrules.Severity: HIGH | Confidence: 0.90
🔍 Detailed Analysis
New documentation links added in
docs/product/explore/metrics/getting-started/index.mdx(lines 19-218), such as/platforms/javascript/metrics/and/platforms/python/guides/django/metrics/, will be intercepted by existing redirect rules inredirects.js. These rules, like{ source: '/platforms/javascript/metrics/:path*', destination: '/platforms/javascript/tracing/span-metrics/:path*', }, will silently redirect users to older span-metrics documentation instead of the intended new Metrics product documentation. This occurs when users click on these newly introduced links.💡 Suggested Fix
Remove or update the conflicting platform-specific metrics redirects in
redirects.js, or confirm that the new documentation paths do not collide with existing redirect patterns.🤖 Prompt for AI Agent
Did we get this right? 👍 / 👎 to inform future reviews.