Skip to content

Commit 3ef0959

Browse files
mhartingtonaidankmcalisterankur-archArthurGambyArthur Gamby
authored
docs(metrics): remove metrics API (#7248)
* DC-5044 `prisma-client-js` deprecated (#7219) * `prisma-client-js` deprecated * chore: empty commit * broken link updated * DC-5040 Env Vars via Config (#7227) * added env vars section to various pages * minor coderabbit updates * verbose removed * test removed redirect list * removed quickstart addition * converted quickstarts back * urls deprecated (#7226) * minimum version uodated (#7234) * DC-5043 Middleware removed from docs (#7233) * middleware deleted * more middleware removed * more middleware removed * coderabbit changes * docs(metrics): remove metrics API * DC-6174: Remove adapter, engine, directUrl, studio from config (#7256) * feat: add new features * fix: revert links * fix: broken links * fix: broken link * feat: restructure getting started side nav (#7245) * feat(docs): add youtube embeded link to blog post (#7220) Co-authored-by: Arthur Gamby <[email protected]> * feat(docs): add quick section to blog after the prompt (#7221) Co-authored-by: Arthur Gamby <[email protected]> * DC-5242 Astro Better-Auth Guide (#7215) * doc created * nextjs betterauth fixed * guide broken down into manageable steps * image added * Optimised images with calibre/image-actions * image updated * Optimised images with calibre/image-actions * lychee only comments on broken links * config updated * lychee updated based on CR comment * chore: trigger CI checks * ignore gnu * fix: update naming to better-auth DC-6120 * Optimised images with calibre/image-actions * chore: shorten word --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Ankur Datta <[email protected]> * feat: restructure getting started side nav * DC-5841 Removed Linkspector (#7231) * removed linkspector * retrigger * retrigger * retrigger * Update label for Prisma Postgres tab (#7236) * fix: content changes for getting started page (#7216) * fix: content changes for getting started page * fix: add redirects * getting started checkpoint * css styles fixed * updates --------- Co-authored-by: Aidan McAlister <[email protected]> Co-authored-by: Aidan McAlister <[email protected]> * DC-5820 AI Agents Served Markdown (#7237) * ai crawler check successful * ai crawlers checked * update * added anthropic * middleware update * improve detection --------- Co-authored-by: Mike Hartington <[email protected]> * feat: add prisma-orm quickstarts * fix: update times and add proper links * fix: instropspect changes * feat: add get started from prisma orm page * feat: add other orms * fix: update other tools + ppg * fix: add more clarity * fix: add prisma postgres * feat: clear migrate from early access * fix: add to existing dbs sections * Remove MCP server exploration tip (#7241) Removed tip about using Cloudflare's AI Playground for MCP server exploration, as it no longer seems to reliably work. * fix: clean-up docs files * fix: typeorm missing urls * fix: broken link * fix: update titles * fix: clear redirect loop (#7250) * fix: add generate step + sqlite fixes * fix: clean-up redirects file DC-6228 * fix: clean-up unnecessary file * fix: remove unknown word * fix: add links --------- Co-authored-by: Arthur <[email protected]> Co-authored-by: Arthur Gamby <[email protected]> Co-authored-by: Aidan McAlister <[email protected]> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Petra Donka <[email protected]> Co-authored-by: Aidan McAlister <[email protected]> Co-authored-by: Mike Hartington <[email protected]> * feat: update .env docs DC-6204 (#7259) * fix: clarify config file path better (#7261) * Update ORM docs (#7260) * update * use pg adapter instead of accelerate * update * add dotenv in prisma.config.ts * fix warning note * update * update * Update guides to use prisma.config.ts (#7243) * (feat) Update guides to use prisma.config.ts * refactor: Updated guides for Prisma 7 changes --------- Co-authored-by: Aman Varshney <[email protected]> * feat: update ppg for other dbs section (#7264) * feat: add kysley * feat: add drizzle * feat: add typeorm * fix: clean-up * feat: separate the sections better * fix: remove badges * feat: update prisma init related changes in other parts (#7267) * feat: add kysley * feat: add drizzle * feat: add typeorm * fix: clean-up * fix: update prisma init command changes * feat: update prisma cli docs * fix: clarify the usage of prisma init better * fix: add type defs * feat: add pg as a dependency * fix: broken internal link * Update docs to perform migrations with connection pooling and Prisma config (#7266) * feat: add mentions of new Prisma Studio (#7270) * feat: add mentions of new Prisma Studio * feat: add note for Studio for SQLite * Update content/100-getting-started/02-prisma-orm/100-quickstart/200-sqlite.mdx * Update content/100-getting-started/02-prisma-orm/200-add-to-existing-project/200-sqlite.mdx * fix: make prisma studio docs more accurate * fix: add missing punctuation * feat: add mention of mongo support coming for P7 (#7271) * feat: add mention of mongo support coming for mongo * fix: refinements * Update content/100-getting-started/02-prisma-orm/200-add-to-existing-project/800-mongodb.mdx * Restore content/200-orm/200-prisma-client/600-observability-and-logging/240-metrics.mdx * docs(): update based on feedback * Update content/200-orm/200-prisma-client/000-setup-and-configuration/050-databases-connections/115-connection-pool.mdx Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> --------- Co-authored-by: Aidan McAlister <[email protected]> Co-authored-by: Ankur Datta <[email protected]> Co-authored-by: Arthur <[email protected]> Co-authored-by: Arthur Gamby <[email protected]> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Petra Donka <[email protected]> Co-authored-by: Aidan McAlister <[email protected]> Co-authored-by: Aman Varshney <[email protected]> Co-authored-by: Nurul Sundarani <[email protected]> Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
1 parent d108c15 commit 3ef0959

File tree

7 files changed

+28
-288
lines changed

7 files changed

+28
-288
lines changed

content/200-orm/200-prisma-client/000-setup-and-configuration/050-databases-connections/115-connection-pool.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ datasource db {
145145

146146
#### Viewing the connection pool size
147147

148-
The number of connections Prisma Client uses can be viewed using [logging](/orm/prisma-client/observability-and-logging/logging) and [metrics](/orm/prisma-client/observability-and-logging/metrics).
148+
The number of connections Prisma Client uses can be viewed using [logging](/orm/prisma-client/observability-and-logging/logging) and built-in APIs provided by the driver adapter being used.
149149

150150
Using the `info` [logging level](/orm/reference/prisma-client-reference#log-levels), you can log the number of connections in a connection pool that are opened when Prisma Client is instantiated.
151151

content/200-orm/200-prisma-client/300-client-extensions/110-client.mdx

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -34,29 +34,28 @@ const prisma = new PrismaClient().$extends({
3434
The following example uses the `client` component to add two methods to Prisma Client:
3535

3636
- `$log` outputs a message.
37-
- `$totalQueries` returns the number of queries executed by the current client instance. It uses the [metrics](/orm/prisma-client/observability-and-logging/metrics) feature to collect this information.
37+
- `$totalQueries` returns the number of queries executed by the current client instance.
3838

3939
:::info
4040

4141
To use metrics in your project, you must enable the `metrics` feature flag in the `generator` block of your `schema.prisma` file. [Learn more](/orm/prisma-client/observability-and-logging/metrics#2-enable-the-feature-flag-in-the-prisma-schema-file).
4242

4343
:::
4444

45-
```ts
45+
const total = 0
4646
const prisma = new PrismaClient().$extends({
4747
client: {
4848
$log: (s: string) => console.log(s),
49-
async $totalQueries() {
50-
const index_prisma_client_queries_total = 0
51-
// Prisma.getExtensionContext(this) in the following block
52-
// returns the current client instance
53-
const metricsCounters = await (
54-
await Prisma.getExtensionContext(this).$metrics.json()
55-
).counters
56-
57-
return metricsCounters[index_prisma_client_queries_total].value
58-
},
49+
async $totalQueries() { return total; },
5950
},
51+
query: {
52+
$allModels: {
53+
async $allOperations({ query, args }) {
54+
total += 1;
55+
return query(args);
56+
},
57+
},
58+
},
6059
})
6160

6261
async function main() {

content/200-orm/200-prisma-client/600-observability-and-logging/240-metrics.mdx

Lines changed: 13 additions & 260 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,10 @@ toc_max_heading_level: 4
99

1010
Prisma Client metrics give you a detailed insight into how Prisma Client interacts with your database. You can use this insight to help diagnose performance issues with your application.
1111

12-
:::info
1312

14-
If you want an even more detailed insight into your Prisma Client's performance, at the level of individual operations, see [Tracing](/orm/prisma-client/observability-and-logging/opentelemetry-tracing).
13+
:::danger[`metrics` preview feature has been removed ]
1514

16-
:::
17-
18-
:::warning[`metrics` preview feature is deprecated]
19-
20-
The `metrics` preview feature has been **deprecated** as of [Prisma ORM v6.14.0](https://github.com/prisma/prisma/releases/tag/6.14.0) and will be removed in Prisma ORM v7.
21-
22-
**The `metrics` preview feature is only available in Prisma ORM versions ≤6.13.x.** If you are using Prisma ORM v6.14.0 or later, the `$metrics` API is no longer available.
23-
24-
The feature is not supported when using Prisma ORM with the [query compiler architecture](/orm/prisma-client/setup-and-configuration/no-rust-engine) (setting `engineType` to 'client' in the `generator` block of your `schema.prisma` file).
25-
26-
Metrics were originally introduced to provide insights into query and connection behavior. With the changes in the new [query compiler architecture](/orm/prisma-client/setup-and-configuration/no-rust-engine), these values no longer reflect the system reliably. Because of this, we are not continuing support for this feature.
15+
The `metrics` preview feature has been **removed** as of [Prisma ORM v7.0.0](https://github.com/prisma/prisma/releases/tag/7.0.0).
2716

2817
If you need visibility into query or connection pool behavior, we recommend using the *native metrics provided by your database driver* (for example, pool statistics) or setting up *OpenTelemetry* for a more complete observability solution.
2918

@@ -50,25 +39,15 @@ Prisma Client provides the following metrics:
5039
- `prisma_client_queries_active`: The number of currently active Prisma Client queries.
5140
- `prisma_client_queries_wait`: The number of Prisma Client queries currently waiting for a connection because all connections are in use.
5241
- `prisma_pool_connections_busy`: The number of currently busy pool connections. These pool connections are currently executing a datasource query.
53-
- `prisma_pool_connections_idle`: The number of pool connections that are not currently being used. These pool connections are waiting for the next datasource query to run.
54-
- `prisma_pool_connections_open`: The number of [pool connections](/orm/prisma-client/setup-and-configuration/databases-connections/connection-pool#default-connection-pool-size) open.
42+
/* Lines 53-55 omitted */
5543

5644
- Histograms (metrics data divided into a collection of values; we call each container in the collection a "bucket"):
57-
58-
- `prisma_client_queries_wait_histogram_ms`: The time waiting for a pool connection for all Prisma Client queries in ms.
59-
- `prisma_client_queries_duration_histogram_ms`: The execution time for all executed Prisma Client queries in ms. This includes the time taken to execute all database queries, and to carry out all database engine activities, such as joining data and transforming data to the correct format.
60-
- `prisma_datasource_queries_duration_histogram_ms`: The execution time for all executed Datasource queries in ms.
45+
/* Lines 57-61 omitted */
6146

6247
You can [add global labels to your metrics data](#global-labels) to help you group and separate your metrics, for example by infrastructure region or server.
6348

6449
## Prerequisites
6550

66-
:::warning[Version compatibility]
67-
68-
The `metrics` preview feature is **only available in Prisma ORM versions ≤6.13.x**. It has been removed in v6.14.0 and later versions.
69-
70-
:::
71-
7251
To use Prisma Client metrics, you must do the following:
7352

7453
1. [Install compatible Prisma ORM dependencies](#1-install-up-to-date-prisma-orm-dependencies).
@@ -118,167 +97,15 @@ console.log(metrics)
11897
This returns metrics as follows:
11998

12099
```json
121-
{
122-
"counters": [
123-
{
124-
"key": "prisma_client_queries_total",
125-
"labels": {},
126-
"value": 0,
127-
"description": "Total number of Prisma Client queries executed"
128-
},
129-
{
130-
"key": "prisma_datasource_queries_total",
131-
"labels": {},
132-
"value": 0,
133-
"description": "Total number of Datasource Queries executed"
134-
},
135-
{
136-
"key": "prisma_pool_connections_closed_total",
137-
"labels": {},
138-
"value": 0,
139-
"description": "Total number of Pool Connections closed"
140-
},
141-
{
142-
"key": "prisma_pool_connections_opened_total",
143-
"labels": {},
144-
"value": 1,
145-
"description": "Total number of Pool Connections opened"
146-
}
147-
...
148-
],
149-
"gauges": [
150-
...
151-
],
152-
"histograms": [
153-
...
154-
]
155-
}
100+
{/* Lines 121-154 omitted */}
156101
```
157102

158103
<details>
159104

160105
<summary>Expand to view the full output</summary>
161106

162107
```json no-copy
163-
{
164-
"counters": [
165-
{
166-
"key": "prisma_client_queries_total",
167-
"labels": {},
168-
"value": 2,
169-
"description": "Total number of Prisma Client queries executed"
170-
},
171-
{
172-
"key": "prisma_datasource_queries_total",
173-
"labels": {},
174-
"value": 5,
175-
"description": "Total number of Datasource Queries executed"
176-
},
177-
{
178-
"key": "prisma_pool_connections_open",
179-
"labels": {},
180-
"value": 1,
181-
"description": "Number of currently open Pool Connections"
182-
}
183-
],
184-
"gauges": [
185-
{
186-
"key": "prisma_client_queries_active",
187-
"labels": {},
188-
"value": 0,
189-
"description": "Number of currently active Prisma Client queries"
190-
},
191-
{
192-
"key": "prisma_client_queries_wait",
193-
"labels": {},
194-
"value": 0,
195-
"description": "Number of Prisma Client queries currently waiting for a connection"
196-
},
197-
{
198-
"key": "prisma_pool_connections_busy",
199-
"labels": {},
200-
"value": 0,
201-
"description": "Number of currently busy Pool Connections (executing a datasource query)"
202-
},
203-
{
204-
"key": "prisma_pool_connections_idle",
205-
"labels": {},
206-
"value": 21,
207-
"description": "Number of currently unused Pool Connections (waiting for the next datasource query to run)"
208-
},
209-
{
210-
"key": "prisma_pool_connections_open",
211-
"labels": {},
212-
"value": 1,
213-
"description": "Number of currently open Pool Connections"
214-
}
215-
],
216-
"histograms": [
217-
{
218-
"key": "prisma_client_queries_duration_histogram_ms",
219-
"labels": {},
220-
"value": {
221-
"buckets": [
222-
[0, 0],
223-
[1, 0],
224-
[5, 0],
225-
[10, 1],
226-
[50, 1],
227-
[100, 0],
228-
[500, 0],
229-
[1000, 0],
230-
[5000, 0],
231-
[50000, 0]
232-
],
233-
"sum": 47.430541000000005,
234-
"count": 2
235-
},
236-
"description": "Histogram of the duration of all executed Prisma Client queries in ms"
237-
},
238-
{
239-
"key": "prisma_client_queries_wait_histogram_ms",
240-
"labels": {},
241-
"value": {
242-
"buckets": [
243-
[0, 0],
244-
[1, 3],
245-
[5, 0],
246-
[10, 0],
247-
[50, 0],
248-
[100, 0],
249-
[500, 0],
250-
[1000, 0],
251-
[5000, 0],
252-
[50000, 0]
253-
],
254-
"sum": 0.0015830000000000002,
255-
"count": 3
256-
},
257-
"description": "Histogram of the wait time of all Prisma Client Queries in ms"
258-
},
259-
{
260-
"key": "prisma_datasource_queries_duration_histogram_ms",
261-
"labels": {},
262-
"value": {
263-
"buckets": [
264-
[0, 0],
265-
[1, 0],
266-
[5, 2],
267-
[10, 2],
268-
[50, 1],
269-
[100, 0],
270-
[500, 0],
271-
[1000, 0],
272-
[5000, 0],
273-
[50000, 0]
274-
],
275-
"sum": 47.134498,
276-
"count": 5
277-
},
278-
"description": "Histogram of the duration of all executed Datasource Queries in ms"
279-
}
280-
]
281-
}
108+
{/* Lines 163-280 omitted */}
282109
```
283110

284111
</details>
@@ -313,61 +140,12 @@ let statsd = new StatsD({
313140
port: 8125,
314141
})
315142

316-
const diffMetrics = (metrics: Metric<MetricHistogram>[]) => {
317-
return metrics.map((metric) => {
318-
let prev = 0;
319-
320-
const diffBuckets = metric.value.buckets.map<MetricHistogramBucket>(
321-
(values) => {
322-
const [bucket, value] = values
323-
const diff = value - prev
324-
prev = value
325-
return [bucket, diff]
326-
}
327-
)
328-
329-
metric.value.buckets = diffBuckets
330-
return metric
331-
})
332-
}
143+
const diffMetrics = (metrics: Metric<MetricHistogram>[]) => {/* Lines 316-331 omitted */}
333144

334145
let previousHistograms: Metric<MetricHistogram>[] = []
335146

336147

337-
const statsdSender = async () => {
338-
const metrics = await prisma.$metrics.json()
339-
340-
metrics.counters.forEach((counter: any) => {
341-
statsd.gauge('prisma.' + counter.key, counter.value, (...res) => {})
342-
});
343-
344-
metrics.gauges.forEach((counter: any) => {
345-
statsd.gauge('prisma.' + counter.key, counter.value, (...res) => {})
346-
})
347-
348-
if (!previousHistograms.length) {
349-
previousHistograms = diffMetrics(metrics.histograms)
350-
351-
return
352-
}
353-
354-
const diffHistograms = diffMetrics(metrics.histograms);
355-
356-
diffHistograms.forEach((diffHistogram, histogramIndex) => {
357-
diffHistogram.value.buckets.forEach((values, bucketIndex) => {
358-
const [bucket, count] = values
359-
const [_, prev] =
360-
previousHistograms[histogramIndex].value.buckets[bucketIndex]
361-
const change = count - prev
362-
363-
for (let sendTimes = 0; sendTimes < change; sendTimes++) {
364-
statsd.timing('prisma.' + diffHistograms.key, bucket)
365-
}
366-
})
367-
})
368-
369-
previousHistograms = diffHistograms
370-
}
148+
const statsdSender = async () => {/* Lines 337-369 omitted */}
371149

372150
setInterval(async () => await statsdSender(), 10000)
373151
```
@@ -500,8 +278,7 @@ prisma_datasource_queries_duration_histogram_ms_count 5
500278
Metrics of type `histogram` expose three different class of values in the Prometheus format:
501279

502280
1. Multiple cumulative counters for observation buckets. These counters are suffixed with `_bucket{le="<upper inclusive bound>"}`. For example, `prisma_datasource_queries_duration_histogram_ms` has a counter exposed as `prisma_datasource_queries_duration_histogram_ms_bucket{le="1"}`
503-
504-
When an observed value is less than or equal to the upper inclusive bound of a bucket, then Prisma Client metrics increments that bucket by 1. Suppose that you have buckets with the upper inclusive bounds 0, 1, 5, 10, and 50 respectively. If the observed value is 5 then Prisma Client metrics increments the third bucket onwards, because the value is greater than 0 and greater than 1, but less than or equal to 5, 10, and 50.
281+
/* Lines 502-504 omitted */
505282

506283
2. A single **total sum** for all observed values. This counter is suffixed with `_sum`. For example the total sum of `prisma_datasource_queries_duration_histogram_ms` is exposed as `prisma_datasource_queries_duration_histogram_ms_sum`.
507284
3. The **count** of the number of events that have been observed. This counter is suffixed with `_count`. For example the total count of `prisma_datasource_queries_duration_histogram_ms` events is exposed as `prisma_datasource_queries_duration_histogram_ms_count`.
@@ -521,7 +298,7 @@ const port = 4000
521298
const prisma = new PrismaClient()
522299

523300
app.get('/metrics', async (_req, res: Response) => {
524-
const metrics = await prisma.$metrics.prometheus()
301+
/* Lines 523-524 omitted */
525302
res.end(metrics)
526303
})
527304

@@ -545,8 +322,7 @@ const register = new prom.Registry()
545322
prom.collectDefaultMetrics({ register })
546323

547324
app.get('/metrics', async (_req, res: Response) => {
548-
const prismaMetrics = await prisma.$metrics.prometheus()
549-
const appMetrics = await register.metrics()
325+
/* Lines 547-549 omitted */
550326
res.end(prismaMetrics + appMetrics)
551327
})
552328

@@ -573,29 +349,6 @@ console.log(metrics)
573349
This returns information in the following format:
574350

575351
```json highlight=5,11;add
576-
{
577-
"counters": [
578-
{
579-
"key": "query_total_operations",
580-
//add-next-line
581-
"labels": { "server": "us_server1", "app_version": "one" },
582-
"value": 0,
583-
"description": "The total number of operations executed"
584-
},
585-
{
586-
"key": "prisma_datasource_queries_total",
587-
//add-next-line
588-
"labels": { "server": "us_server1", "app_version": "one" },
589-
"value": 0,
590-
"description": "The total number of queries executed"
591-
},
592-
...
593-
],
594-
"gauges": [
595-
...
596-
],
597-
"histograms": [
598-
...
599-
]
600-
}
352+
{/* Lines 576-599 omitted */}
601353
```
354+

0 commit comments

Comments
 (0)