Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
e35e705
DC-5044 `prisma-client-js` deprecated (#7219)
aidankmcalister Nov 4, 2025
f8c32d1
DC-5040 Env Vars via Config (#7227)
aidankmcalister Nov 5, 2025
87eba65
urls deprecated (#7226)
aidankmcalister Nov 5, 2025
ac89f6a
minimum version uodated (#7234)
aidankmcalister Nov 7, 2025
3bf085d
DC-5043 Middleware removed from docs (#7233)
aidankmcalister Nov 7, 2025
1b1cf8a
docs(metrics): remove metrics API
mhartington Nov 11, 2025
a4cffaf
DC-6174: Remove adapter, engine, directUrl, studio from config (#7256)
ankur-arch Nov 15, 2025
c2671d7
feat: restructure getting started side nav (#7245)
ankur-arch Nov 15, 2025
32e3082
feat: update .env docs DC-6204 (#7259)
ankur-arch Nov 17, 2025
1db29fe
fix: clarify config file path better (#7261)
ankur-arch Nov 17, 2025
8d21ba4
Update ORM docs (#7260)
AmanVarshney01 Nov 17, 2025
a72eb21
Update guides to use prisma.config.ts (#7243)
nurul3101 Nov 17, 2025
05b7cb0
feat: update ppg for other dbs section (#7264)
ankur-arch Nov 17, 2025
5c857d7
feat: update prisma init related changes in other parts (#7267)
ankur-arch Nov 17, 2025
f489364
Update docs to perform migrations with connection pooling and Prisma …
AmanVarshney01 Nov 17, 2025
50b8d99
feat: add mentions of new Prisma Studio (#7270)
ankur-arch Nov 17, 2025
311bc16
feat: add mention of mongo support coming for P7 (#7271)
ankur-arch Nov 17, 2025
7e77180
Restore content/200-orm/200-prisma-client/600-observability-and-loggi…
mhartington Nov 18, 2025
ef1bea8
docs(): update based on feedback
mhartington Nov 18, 2025
e65a404
Merge branch 'prisma-7' into metrics-removal-v2
mhartington Nov 18, 2025
83ccec0
Update content/200-orm/200-prisma-client/000-setup-and-configuration/…
mhartington Nov 18, 2025
8c77313
Merge branch 'prisma-7' into metrics-removal-v2
AmanVarshney01 Nov 19, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ datasource db {

#### Viewing the connection pool size

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).
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.

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.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,29 +34,28 @@ const prisma = new PrismaClient().$extends({
The following example uses the `client` component to add two methods to Prisma Client:

- `$log` outputs a message.
- `$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.
- `$totalQueries` returns the number of queries executed by the current client instance.

:::info

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).

:::

```ts
const total = 0
const prisma = new PrismaClient().$extends({
client: {
$log: (s: string) => console.log(s),
async $totalQueries() {
const index_prisma_client_queries_total = 0
// Prisma.getExtensionContext(this) in the following block
// returns the current client instance
const metricsCounters = await (
await Prisma.getExtensionContext(this).$metrics.json()
).counters

return metricsCounters[index_prisma_client_queries_total].value
},
async $totalQueries() { return total; },
},
query: {
$allModels: {
async $allOperations({ query, args }) {
total += 1;
return query(args);
},
},
},
})

async function main() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,10 @@ toc_max_heading_level: 4

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.

:::info

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).
:::danger[`metrics` preview feature has been removed ]

:::

:::warning[`metrics` preview feature is deprecated]

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.

**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.

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).

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.
The `metrics` preview feature has been **removed** as of [Prisma ORM v7.0.0](https://github.com/prisma/prisma/releases/tag/7.0.0).

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.

Expand All @@ -50,25 +39,15 @@ Prisma Client provides the following metrics:
- `prisma_client_queries_active`: The number of currently active Prisma Client queries.
- `prisma_client_queries_wait`: The number of Prisma Client queries currently waiting for a connection because all connections are in use.
- `prisma_pool_connections_busy`: The number of currently busy pool connections. These pool connections are currently executing a datasource query.
- `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.
- `prisma_pool_connections_open`: The number of [pool connections](/orm/prisma-client/setup-and-configuration/databases-connections/connection-pool#default-connection-pool-size) open.
/* Lines 53-55 omitted */

- Histograms (metrics data divided into a collection of values; we call each container in the collection a "bucket"):

- `prisma_client_queries_wait_histogram_ms`: The time waiting for a pool connection for all Prisma Client queries in ms.
- `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.
- `prisma_datasource_queries_duration_histogram_ms`: The execution time for all executed Datasource queries in ms.
/* Lines 57-61 omitted */

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.

## Prerequisites

:::warning[Version compatibility]

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.

:::

To use Prisma Client metrics, you must do the following:

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

```json
{
"counters": [
{
"key": "prisma_client_queries_total",
"labels": {},
"value": 0,
"description": "Total number of Prisma Client queries executed"
},
{
"key": "prisma_datasource_queries_total",
"labels": {},
"value": 0,
"description": "Total number of Datasource Queries executed"
},
{
"key": "prisma_pool_connections_closed_total",
"labels": {},
"value": 0,
"description": "Total number of Pool Connections closed"
},
{
"key": "prisma_pool_connections_opened_total",
"labels": {},
"value": 1,
"description": "Total number of Pool Connections opened"
}
...
],
"gauges": [
...
],
"histograms": [
...
]
}
{/* Lines 121-154 omitted */}
```

<details>

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

```json no-copy
{
"counters": [
{
"key": "prisma_client_queries_total",
"labels": {},
"value": 2,
"description": "Total number of Prisma Client queries executed"
},
{
"key": "prisma_datasource_queries_total",
"labels": {},
"value": 5,
"description": "Total number of Datasource Queries executed"
},
{
"key": "prisma_pool_connections_open",
"labels": {},
"value": 1,
"description": "Number of currently open Pool Connections"
}
],
"gauges": [
{
"key": "prisma_client_queries_active",
"labels": {},
"value": 0,
"description": "Number of currently active Prisma Client queries"
},
{
"key": "prisma_client_queries_wait",
"labels": {},
"value": 0,
"description": "Number of Prisma Client queries currently waiting for a connection"
},
{
"key": "prisma_pool_connections_busy",
"labels": {},
"value": 0,
"description": "Number of currently busy Pool Connections (executing a datasource query)"
},
{
"key": "prisma_pool_connections_idle",
"labels": {},
"value": 21,
"description": "Number of currently unused Pool Connections (waiting for the next datasource query to run)"
},
{
"key": "prisma_pool_connections_open",
"labels": {},
"value": 1,
"description": "Number of currently open Pool Connections"
}
],
"histograms": [
{
"key": "prisma_client_queries_duration_histogram_ms",
"labels": {},
"value": {
"buckets": [
[0, 0],
[1, 0],
[5, 0],
[10, 1],
[50, 1],
[100, 0],
[500, 0],
[1000, 0],
[5000, 0],
[50000, 0]
],
"sum": 47.430541000000005,
"count": 2
},
"description": "Histogram of the duration of all executed Prisma Client queries in ms"
},
{
"key": "prisma_client_queries_wait_histogram_ms",
"labels": {},
"value": {
"buckets": [
[0, 0],
[1, 3],
[5, 0],
[10, 0],
[50, 0],
[100, 0],
[500, 0],
[1000, 0],
[5000, 0],
[50000, 0]
],
"sum": 0.0015830000000000002,
"count": 3
},
"description": "Histogram of the wait time of all Prisma Client Queries in ms"
},
{
"key": "prisma_datasource_queries_duration_histogram_ms",
"labels": {},
"value": {
"buckets": [
[0, 0],
[1, 0],
[5, 2],
[10, 2],
[50, 1],
[100, 0],
[500, 0],
[1000, 0],
[5000, 0],
[50000, 0]
],
"sum": 47.134498,
"count": 5
},
"description": "Histogram of the duration of all executed Datasource Queries in ms"
}
]
}
{/* Lines 163-280 omitted */}
```

</details>
Expand Down Expand Up @@ -313,61 +140,12 @@ let statsd = new StatsD({
port: 8125,
})

const diffMetrics = (metrics: Metric<MetricHistogram>[]) => {
return metrics.map((metric) => {
let prev = 0;

const diffBuckets = metric.value.buckets.map<MetricHistogramBucket>(
(values) => {
const [bucket, value] = values
const diff = value - prev
prev = value
return [bucket, diff]
}
)

metric.value.buckets = diffBuckets
return metric
})
}
const diffMetrics = (metrics: Metric<MetricHistogram>[]) => {/* Lines 316-331 omitted */}

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


const statsdSender = async () => {
const metrics = await prisma.$metrics.json()

metrics.counters.forEach((counter: any) => {
statsd.gauge('prisma.' + counter.key, counter.value, (...res) => {})
});

metrics.gauges.forEach((counter: any) => {
statsd.gauge('prisma.' + counter.key, counter.value, (...res) => {})
})

if (!previousHistograms.length) {
previousHistograms = diffMetrics(metrics.histograms)

return
}

const diffHistograms = diffMetrics(metrics.histograms);

diffHistograms.forEach((diffHistogram, histogramIndex) => {
diffHistogram.value.buckets.forEach((values, bucketIndex) => {
const [bucket, count] = values
const [_, prev] =
previousHistograms[histogramIndex].value.buckets[bucketIndex]
const change = count - prev

for (let sendTimes = 0; sendTimes < change; sendTimes++) {
statsd.timing('prisma.' + diffHistograms.key, bucket)
}
})
})

previousHistograms = diffHistograms
}
const statsdSender = async () => {/* Lines 337-369 omitted */}

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

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"}`

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.
/* Lines 502-504 omitted */

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`.
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`.
Expand All @@ -521,7 +298,7 @@ const port = 4000
const prisma = new PrismaClient()

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

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

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

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

```json highlight=5,11;add
{
"counters": [
{
"key": "query_total_operations",
//add-next-line
"labels": { "server": "us_server1", "app_version": "one" },
"value": 0,
"description": "The total number of operations executed"
},
{
"key": "prisma_datasource_queries_total",
//add-next-line
"labels": { "server": "us_server1", "app_version": "one" },
"value": 0,
"description": "The total number of queries executed"
},
...
],
"gauges": [
...
],
"histograms": [
...
]
}
{/* Lines 576-599 omitted */}
```

Loading
Loading