Skip to content

Commit c0d6f87

Browse files
coolguyzoneAlex KrawiecKyleTryon
authored
Metrics Product Docs (#15375)
<!-- Use this checklist to make sure your PR is ready for merge. You may delete any sections you don't need. --> ## DESCRIBE YOUR PR *Tell us what you're changing and why. If your PR **resolves an issue**, please link it so it closes automatically.* ## IS YOUR CHANGE URGENT? Help us prioritize incoming PRs by letting us know when the change needs to go live. - [ ] Urgent deadline (GA date, etc.): <!-- ENTER DATE HERE --> - [ ] Other deadline: <!-- ENTER DATE HERE --> - [ ] None: Not urgent, can wait up to 1 week+ ## SLA - Teamwork makes the dream work, so please add a reviewer to your PRs. - Please give the docs team up to 1 week to review your PR unless you've added an urgent due date to it. Thanks in advance for your help! ## PRE-MERGE CHECKLIST *Make sure you've checked the following before merging your changes:* - [ ] Checked Vercel preview for correctness, including links - [ ] PR was reviewed and approved by any necessary SMEs (subject matter experts) - [ ] PR was reviewed and approved by a member of the [Sentry docs team](https://github.com/orgs/getsentry/teams/docs) ## LEGAL BOILERPLATE <!-- Sentry employees and contractors can delete or ignore this section. --> Look, I get it. The entity doing business as "Sentry" was incorporated in the State of Delaware in 2015 as Functional Software, Inc. and is gonna need some rights from me in order to utilize my contributions in this here PR. So here's the deal: I retain all rights, title and interest in and to my contributions, and by keeping this boilerplate intact I confirm that Sentry can use, modify, copy, and redistribute my contributions, under Sentry's choice of terms. ## EXTRA RESOURCES - [Sentry Docs contributor guide](https://docs.sentry.io/contributing/) --------- Co-authored-by: Alex Krawiec <[email protected]> Co-authored-by: Kyle a.k.a. TechSquidTV <[email protected]>
1 parent f9b300d commit c0d6f87

File tree

6 files changed

+543
-5
lines changed

6 files changed

+543
-5
lines changed

docs/product/explore/index.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ The Explore tab in Sentry offers multiple ways to search and investigate your ap
88

99
## Learn More
1010

11-
<PageGrid exclude={['metrics']} />
11+
<PageGrid />
Lines changed: 380 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,380 @@
1+
---
2+
title: Set Up
3+
sidebar_order: 0
4+
description: "Learn how to set up Sentry's Metrics feature using our supported SDKs."
5+
---
6+
7+
<Alert level="info">
8+
Metrics is currently in Open Beta for non-Enterprise plans running 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].
9+
</Alert>
10+
11+
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.
12+
13+
## Supported SDKs
14+
15+
### JavaScript
16+
17+
Minimum SDK version: **10.20.0**
18+
19+
- <LinkWithPlatformIcon
20+
platform="javascript.browser"
21+
label="Browser JavaScript"
22+
url="/platforms/javascript/metrics/"
23+
/>
24+
- <LinkWithPlatformIcon
25+
platform="javascript.angular"
26+
label="Angular"
27+
url="/platforms/javascript/guides/angular/metrics/"
28+
/>
29+
- <LinkWithPlatformIcon
30+
platform="javascript.astro"
31+
label="Astro"
32+
url="/platforms/javascript/guides/astro/metrics/"
33+
/>
34+
- <LinkWithPlatformIcon
35+
platform="javascript.aws-lambda"
36+
label="AWS Lambda"
37+
url="/platforms/javascript/guides/aws-lambda/metrics/"
38+
/>
39+
- <LinkWithPlatformIcon
40+
platform="javascript.azure-functions"
41+
label="Azure Functions"
42+
url="/platforms/javascript/guides/azure-functions/metrics/"
43+
/>
44+
- <LinkWithPlatformIcon
45+
platform="javascript.bun"
46+
label="Bun"
47+
url="/platforms/javascript/guides/bun/metrics/"
48+
/>
49+
- <LinkWithPlatformIcon
50+
platform="javascript.cloudflare"
51+
label="Cloudflare"
52+
url="/platforms/javascript/guides/cloudflare/metrics/"
53+
/>
54+
- <LinkWithPlatformIcon
55+
platform="javascript.connect"
56+
label="Connect"
57+
url="/platforms/javascript/guides/connect/metrics/"
58+
/>
59+
- <LinkWithPlatformIcon
60+
platform="javascript.electron"
61+
label="Electron"
62+
url="/platforms/javascript/guides/electron/metrics/"
63+
/>
64+
- <LinkWithPlatformIcon
65+
platform="javascript.ember"
66+
label="Ember"
67+
url="/platforms/javascript/guides/ember/metrics/"
68+
/>
69+
- <LinkWithPlatformIcon
70+
platform="javascript.express"
71+
label="Express"
72+
url="/platforms/javascript/guides/express/metrics/"
73+
/>
74+
- <LinkWithPlatformIcon
75+
platform="javascript.fastify"
76+
label="Fastify"
77+
url="/platforms/javascript/guides/fastify/metrics/"
78+
/>
79+
- <LinkWithPlatformIcon
80+
platform="javascript.gatsby"
81+
label="Gatsby"
82+
url="/platforms/javascript/guides/gatsby/metrics/"
83+
/>
84+
- <LinkWithPlatformIcon
85+
platform="javascript.gcp-functions"
86+
label="Google Cloud Functions"
87+
url="/platforms/javascript/guides/gcp-functions/metrics/"
88+
/>
89+
- <LinkWithPlatformIcon
90+
platform="javascript.hapi"
91+
label="Hapi"
92+
url="/platforms/javascript/guides/hapi/metrics/"
93+
/>
94+
- <LinkWithPlatformIcon
95+
platform="javascript.hono"
96+
label="Hono"
97+
url="/platforms/javascript/guides/hono/metrics/"
98+
/>
99+
- <LinkWithPlatformIcon
100+
platform="javascript.koa"
101+
label="Koa"
102+
url="/platforms/javascript/guides/koa/metrics/"
103+
/>
104+
- <LinkWithPlatformIcon
105+
platform="javascript.nestjs"
106+
label="Nest.js"
107+
url="/platforms/javascript/guides/nestjs/metrics/"
108+
/>
109+
- <LinkWithPlatformIcon
110+
platform="javascript.node"
111+
label="Node.js"
112+
url="/platforms/javascript/guides/node/metrics/"
113+
/>
114+
- <LinkWithPlatformIcon
115+
platform="javascript.nextjs"
116+
label="Next.js"
117+
url="/platforms/javascript/guides/nextjs/metrics/"
118+
/>
119+
- <LinkWithPlatformIcon
120+
platform="javascript.nuxt"
121+
label="Nuxt"
122+
url="/platforms/javascript/guides/nuxt/metrics/"
123+
/>
124+
- <LinkWithPlatformIcon
125+
platform="javascript.react"
126+
label="React"
127+
url="/platforms/javascript/guides/react/metrics/"
128+
/>
129+
- <LinkWithPlatformIcon
130+
platform="javascript.react-router"
131+
label="React Router"
132+
url="/platforms/javascript/guides/react-router/metrics/"
133+
/>
134+
- <LinkWithPlatformIcon
135+
platform="javascript.remix"
136+
label="Remix"
137+
url="/platforms/javascript/guides/remix/metrics/"
138+
/>
139+
- <LinkWithPlatformIcon
140+
platform="javascript.solid"
141+
label="Solid"
142+
url="/platforms/javascript/guides/solid/metrics/"
143+
/>
144+
- <LinkWithPlatformIcon
145+
platform="javascript.solidstart"
146+
label="SolidStart"
147+
url="/platforms/javascript/guides/solidstart/metrics/"
148+
/>
149+
- <LinkWithPlatformIcon
150+
platform="javascript.svelte"
151+
label="Svelte"
152+
url="/platforms/javascript/guides/svelte/metrics/"
153+
/>
154+
- <LinkWithPlatformIcon
155+
platform="javascript.sveltekit"
156+
label="SvelteKit"
157+
url="/platforms/javascript/guides/sveltekit/metrics/"
158+
/>
159+
- <LinkWithPlatformIcon
160+
platform="javascript.tanstackstart-react"
161+
label="TanStack Start"
162+
url="/platforms/javascript/guides/tanstackstart-react/metrics/"
163+
/>
164+
- <LinkWithPlatformIcon
165+
platform="javascript.vue"
166+
label="Vue"
167+
url="/platforms/javascript/guides/vue/metrics/"
168+
/>
169+
- <LinkWithPlatformIcon
170+
platform="javascript.wasm"
171+
label="Wasm"
172+
url="/platforms/javascript/guides/wasm/metrics/"
173+
/>
174+
175+
### Python
176+
177+
Minimum SDK version: **2.43.0**
178+
179+
- <LinkWithPlatformIcon
180+
platform="python"
181+
label="Python"
182+
url="/platforms/python/metrics/"
183+
/>
184+
- <LinkWithPlatformIcon
185+
platform="python.django"
186+
label="Django"
187+
url="/platforms/python/guides/django/metrics/"
188+
/>
189+
- <LinkWithPlatformIcon
190+
platform="python.flask"
191+
label="Flask"
192+
url="/platforms/python/guides/flask/metrics/"
193+
/>
194+
- <LinkWithPlatformIcon
195+
platform="python.fastapi"
196+
label="FastAPI"
197+
url="/platforms/python/guides/fastapi/metrics/"
198+
/>
199+
- <LinkWithPlatformIcon
200+
platform="python.starlette"
201+
label="Starlette"
202+
url="/platforms/python/guides/starlette/metrics/"
203+
/>
204+
- <LinkWithPlatformIcon
205+
platform="python.celery"
206+
label="Celery"
207+
url="/platforms/python/guides/celery/metrics/"
208+
/>
209+
- <LinkWithPlatformIcon
210+
platform="python.aws-lambda"
211+
label="AWS Lambda"
212+
url="/platforms/python/guides/aws-lambda/metrics/"
213+
/>
214+
- <LinkWithPlatformIcon
215+
platform="python.gcp-functions"
216+
label="Google Cloud Functions"
217+
url="/platforms/python/guides/gcp-functions/metrics/"
218+
/>
219+
220+
## Quick Start Examples
221+
222+
### JavaScript Example
223+
224+
First, enable metrics in your Sentry initialization:
225+
226+
```javascript
227+
import * as Sentry from "@sentry/node"; // or your specific framework
228+
229+
Sentry.init({
230+
dsn: '<your-dsn>',
231+
_experiments: {
232+
enableMetrics: true
233+
},
234+
});
235+
```
236+
237+
Then use the metrics API to send counters, gauges, and distributions:
238+
239+
```javascript
240+
// Counter — increment a metric (defaults to +1)
241+
Sentry.metrics.count('checkout.failed', 1, {
242+
attributes: {
243+
route: '/checkout',
244+
tenant: 'acme',
245+
provider: 'stripe',
246+
},
247+
});
248+
249+
// Gauge — set a current value
250+
Sentry.metrics.gauge('queue.depth', 42, {
251+
unit: 'items',
252+
attributes: {
253+
queue: 'emails',
254+
region: 'us-east-1',
255+
},
256+
});
257+
258+
// Distribution — record numeric values to compute p95, avg, sum, etc.
259+
Sentry.metrics.distribution('cart.amount_usd', 187.5, {
260+
unit: 'usd',
261+
attributes: {
262+
currency: 'USD',
263+
tenant: 'acme',
264+
},
265+
});
266+
```
267+
268+
Each metric event includes:
269+
- **name**: The metric identifier
270+
- **kind**: counter, gauge, or distribution
271+
- **value**: The numeric value
272+
- **attributes**: Custom key-value pairs for grouping and filtering
273+
- **trace_id, span_id**: Automatically attached to link with traces
274+
- **unit** (optional): Unit of measurement
275+
- **byte_size** (optional): Size information
276+
277+
More details: [JavaScript SDK Metrics Discussion](https://github.com/getsentry/sentry-javascript/discussions/18055)
278+
279+
### Python Example
280+
281+
First, enable metrics in your Sentry initialization:
282+
283+
```python
284+
import sentry_sdk
285+
from sentry_sdk import metrics
286+
287+
sentry_sdk.init(
288+
dsn="___PUBLIC_DSN___",
289+
_experiments={
290+
"enable_metrics": True,
291+
},
292+
)
293+
```
294+
295+
Then use the metrics API to send counters, gauges, and distributions:
296+
297+
```python
298+
# Counter — increment a metric (defaults to +1)
299+
metrics.count(
300+
"checkout.failed",
301+
1,
302+
attributes={"route": "/checkout", "tenant": "acme"}
303+
)
304+
305+
# Gauge — set a current value
306+
metrics.gauge(
307+
"queue.depth",
308+
42,
309+
attributes={"queue": "emails"}
310+
)
311+
312+
# Distribution — record numeric values to compute p95, avg, sum, etc.
313+
metrics.distribution(
314+
"cart.amount_usd",
315+
187.5,
316+
attributes={"currency": "USD", "tenant": "acme"}
317+
)
318+
```
319+
320+
Each metric event includes:
321+
- **name**: The metric identifier
322+
- **kind**: counter, gauge, or distribution
323+
- **value**: The numeric value
324+
- **attributes**: Custom key-value pairs for grouping and filtering
325+
- **trace_id, span_id**: Automatically attached to link with traces
326+
- **unit** (optional): Unit of measurement
327+
328+
More details: [Python SDK Metrics Discussion](https://github.com/getsentry/sentry-python/discussions/5042)
329+
330+
## Best Practices
331+
332+
### Naming Conventions
333+
334+
Use descriptive, dot-separated names that indicate the metric's purpose:
335+
336+
- **Good**: `checkout.failed`, `email.sent`, `queue.depth`
337+
- **Avoid**: `metric1`, `counter`, `x`
338+
339+
### Attributes
340+
341+
Add attributes for any dimension you want to group or filter by:
342+
343+
```javascript
344+
Sentry.metrics.count('api.request', 1, {
345+
attributes: {
346+
endpoint: '/users',
347+
method: 'GET',
348+
status: '200',
349+
region: 'us-west',
350+
},
351+
});
352+
```
353+
354+
This allows you to query metrics like:
355+
- `sum(api.request)` grouped by `endpoint`
356+
- `sum(api.request)` where `status:500`
357+
- `sum(api.request)` grouped by `region` where `method:POST`
358+
359+
### Units
360+
361+
Always specify units for clarity:
362+
363+
- Time: `ms`, `seconds`
364+
- Size: `bytes`, `kb`, `mb`
365+
- Currency: `usd`, `eur`
366+
- Count: `items`, `requests`, `users`
367+
368+
### When to Instrument
369+
370+
Add metrics at key decision points in your code:
371+
372+
- **Before/after critical operations**: Track success and failure rates
373+
- **At service boundaries**: Monitor external API calls, database queries
374+
- **Business logic**: Capture important business events
375+
- **Resource usage**: Track queue depths, connection pools, cache sizes
376+
377+
## Upcoming SDKs
378+
379+
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]).
380+
595 KB
Loading
391 KB
Loading

0 commit comments

Comments
 (0)