Skip to content

Commit 1b1cf8a

Browse files
committed
docs(metrics): remove metrics API
1 parent 3bf085d commit 1b1cf8a

8 files changed

Lines changed: 25 additions & 714 deletions

File tree

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

Lines changed: 1 addition & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ datasource db {
8686

8787
#### Viewing the connection pool size
8888

89-
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).
89+
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 Prisma Postgres Driver.
9090

9191
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.
9292

@@ -127,78 +127,6 @@ Note that the output generated by `log: ['info']` can change in any release with
127127

128128
</Admonition>
129129

130-
If you need even more insights into the size of your connection pool and the amount of in-use and idle connection, you can use the [metrics](/orm/prisma-client/observability-and-logging/metrics) feature (which is currently in Preview).
131-
132-
Consider the following example:
133-
134-
<CodeWithResult expanded="{true}">
135-
<cmd>
136-
137-
```ts
138-
import { PrismaClient } from '@prisma/client'
139-
140-
const prisma = new PrismaClient()
141-
142-
async function main() {
143-
await Promise.all([prisma.user.findMany(), prisma.post.findMany()])
144-
145-
const metrics = await prisma.$metrics.json()
146-
console.dir(metrics, { depth: Infinity })
147-
}
148-
149-
main()
150-
```
151-
152-
</cmd>
153-
<cmdResult>
154-
155-
```json no-copy
156-
{
157-
"counters": [
158-
// ...
159-
{
160-
"key": "prisma_pool_connections_open",
161-
"labels": {},
162-
"value": 2,
163-
"description": "Number of currently open Pool Connections"
164-
}
165-
],
166-
"gauges": [
167-
// ...
168-
{
169-
"key": "prisma_pool_connections_busy",
170-
"labels": {},
171-
"value": 0,
172-
"description": "Number of currently busy Pool Connections (executing a datasource query)"
173-
},
174-
{
175-
"key": "prisma_pool_connections_idle",
176-
"labels": {},
177-
"value": 21,
178-
"description": "Number of currently unused Pool Connections (waiting for the next datasource query to run)"
179-
},
180-
{
181-
"key": "prisma_pool_connections_opened_total",
182-
"labels": {},
183-
"value": 2,
184-
"description": "Total number of Pool Connections opened"
185-
}
186-
],
187-
"histograms": [
188-
/** ... **/
189-
]
190-
}
191-
```
192-
193-
</cmdResult>
194-
</CodeWithResult>
195-
196-
<Admonition type="info">
197-
198-
For more details on what is available in the metrics output, see the [About metrics](/orm/prisma-client/observability-and-logging/metrics#about-metrics) section.
199-
200-
</Admonition>
201-
202130
### Connection pool timeout
203131

204132
#### Default pool timeout

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

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -34,29 +34,25 @@ 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

39-
<Admonition type="info">
40-
41-
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).
39+
```ts
4240

43-
</Admonition>
4441

45-
```ts
42+
const total = 0
4643
const prisma = new PrismaClient().$extends({
4744
client: {
4845
$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-
},
46+
async $totalQueries() { return total; },
5947
},
48+
query: {
49+
$allModels: {
50+
async $allOperations({ query, args }) {
51+
total += 1;
52+
return query(args);
53+
},
54+
},
55+
},
6056
})
6157

6258
async function main() {

0 commit comments

Comments
 (0)