[PR #3350] [CLOSED] [plugin]: oTel Plugin with Console Metric Exporter #13022

Closed
opened 2026-04-13 08:42:22 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/3350
Author: @dagmawibabi
Created: 7/12/2025
Status: Closed

Base: mainHead: oTel


📝 Commits (5)

📊 Changes

4 files changed (+1716 additions, -116 deletions)

View changed files

📝 packages/better-auth/package.json (+5 -0)
packages/better-auth/src/plugins/otel/client.ts (+11 -0)
packages/better-auth/src/plugins/otel/index.ts (+36 -0)
📝 pnpm-lock.yaml (+1664 -116)

📄 Description

This pull request introduces a new OpenTelemetry (oTel) plugin for the better-auth package. The plugin integrates OpenTelemetry instrumentation and metrics collection into the authentication flow. The key changes include the implementation of the oTelPlugin and its corresponding client-side plugin, oTelClientPlugin.

OpenTelemetry Plugin Implementation:

  • oTelPlugin added to packages/better-auth/src/plugins/otel/index.ts:
    Implements a server-side plugin that initializes OpenTelemetry's NodeSDK with a ConsoleSpanExporter, ConsoleMetricExporter, and auto-instrumentations. It hooks into the authentication flow to log initialization and start the SDK.

  • oTelClientPlugin added to packages/better-auth/src/plugins/otel/client.ts:
    Implements a client-side plugin that references the server-side oTelPlugin and satisfies the BetterAuthClientPlugin type. This ensures compatibility with the better-auth framework.

TL:DR
You can use oTelPlugin() to view open telemetry data in your server side console.

Example Output
[#BETTER_AUTH:OTEL-Plugin] oTel has initialized

{
 descriptor: {
   name: 'http.server.duration',
   type: 'HISTOGRAM',
   description: 'measures the duration of the inbound HTTP requests',
   unit: 'ms',
   valueType: 1
 },
 dataPointType: 0,
 dataPoints: [
   {
     attributes: [Object],
     startTime: [Array],
     endTime: [Array],
     value: [Object]
   }
 ]
}
{
 descriptor: {
   name: 'http.client.duration',
   type: 'HISTOGRAM',
   description: 'measures the duration of the outbound HTTP requests',
   unit: 'ms',
   valueType: 1
 },
 dataPointType: 0,
 dataPoints: []
}
{
 descriptor: {
   name: 'db.client.connections.usage',
   type: 'UP_DOWN_COUNTER',
   description: 'The number of connections that are currently in the state referenced by the attribute "state".',
   unit: '{connections}',
   valueType: 1
 },
 dataPointType: 3,
 dataPoints: []
}
{
 descriptor: {
   name: 'http.server.duration',
   type: 'HISTOGRAM',
   description: 'measures the duration of the inbound HTTP requests',
   unit: 'ms',
   valueType: 1
 },
 dataPointType: 0,
 dataPoints: [
   {
     attributes: [Object],
     startTime: [Array],
     endTime: [Array],
     value: [Object]
   }
 ]
}
{
 descriptor: {
   name: 'http.client.duration',
   type: 'HISTOGRAM',
   description: 'measures the duration of the outbound HTTP requests',
   unit: 'ms',
   valueType: 1
 },
 dataPointType: 0,
 dataPoints: []
}
{
 descriptor: {
   name: 'db.client.connections.usage',
   type: 'UP_DOWN_COUNTER',
   description: 'The number of connections that are currently in the state referenced by the attribute "state".',
   unit: '{connections}',
   valueType: 1
 },
 dataPointType: 3,
 dataPoints: []
}
{
 descriptor: {
   name: 'http.server.duration',
   type: 'HISTOGRAM',
   description: 'measures the duration of the inbound HTTP requests',
   unit: 'ms',
   valueType: 1
 },
 dataPointType: 0,
 dataPoints: [
   {
     attributes: [Object],
     startTime: [Array],
     endTime: [Array],
     value: [Object]
   }
 ]
}
{
 descriptor: {
   name: 'http.client.duration',
   type: 'HISTOGRAM',
   description: 'measures the duration of the outbound HTTP requests',
   unit: 'ms',
   valueType: 1
 },
 dataPointType: 0,
 dataPoints: []
}
{
 descriptor: {
   name: 'db.client.connections.usage',
   type: 'UP_DOWN_COUNTER',
   description: 'The number of connections that are currently in the state referenced by the attribute "state".',
   unit: '{connections}',
   valueType: 1
 },
 dataPointType: 3,
 dataPoints: []
}


Summary by cubic

Added a new OpenTelemetry plugin to better-auth that logs authentication metrics and traces to the server console.

  • New Features
    • oTelPlugin initializes OpenTelemetry with console exporters for spans and metrics.
    • oTelClientPlugin provides client-side compatibility for the plugin system.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/better-auth/better-auth/pull/3350 **Author:** [@dagmawibabi](https://github.com/dagmawibabi) **Created:** 7/12/2025 **Status:** ❌ Closed **Base:** `main` ← **Head:** `oTel` --- ### 📝 Commits (5) - [`4bc3782`](https://github.com/better-auth/better-auth/commit/4bc3782d79d7a34b69325aede19199d82589ba38) oTel Plugin - [`06e681f`](https://github.com/better-auth/better-auth/commit/06e681fc0906a5460f34f21cfd6068f356bf887f) oTel Plugin - [`2afa597`](https://github.com/better-auth/better-auth/commit/2afa5974cb9ff7d657a91fff292f6ba8a9c3f134) oTel dependency files - [`9956a31`](https://github.com/better-auth/better-auth/commit/9956a31e263b96a48d2366b1c9f3b266dffedd29) oTel dependency files - [`bdfbeee`](https://github.com/better-auth/better-auth/commit/bdfbeee9a56881acd6c7b4f70c3ec874b6ca42ec) fix formatting issue ### 📊 Changes **4 files changed** (+1716 additions, -116 deletions) <details> <summary>View changed files</summary> 📝 `packages/better-auth/package.json` (+5 -0) ➕ `packages/better-auth/src/plugins/otel/client.ts` (+11 -0) ➕ `packages/better-auth/src/plugins/otel/index.ts` (+36 -0) 📝 `pnpm-lock.yaml` (+1664 -116) </details> ### 📄 Description This pull request introduces a new OpenTelemetry ([oTel](https://opentelemetry.io/docs/what-is-opentelemetry/)) plugin for the `better-auth` package. The plugin integrates OpenTelemetry instrumentation and metrics collection into the authentication flow. The key changes include the implementation of the `oTelPlugin` and its corresponding client-side plugin, `oTelClientPlugin`. ### OpenTelemetry Plugin Implementation: * **`oTelPlugin` added to `packages/better-auth/src/plugins/otel/index.ts`:** Implements a server-side plugin that initializes OpenTelemetry's `NodeSDK` with a `ConsoleSpanExporter`, `ConsoleMetricExporter`, and auto-instrumentations. It hooks into the authentication flow to log initialization and start the SDK. * **`oTelClientPlugin` added to `packages/better-auth/src/plugins/otel/client.ts`:** Implements a client-side plugin that references the server-side `oTelPlugin` and satisfies the `BetterAuthClientPlugin` type. This ensures compatibility with the `better-auth` framework. TL:DR You can use `oTelPlugin()` to view open telemetry data in your server side console. Example Output [#BETTER_AUTH:OTEL-Plugin] oTel has initialized ``` { descriptor: { name: 'http.server.duration', type: 'HISTOGRAM', description: 'measures the duration of the inbound HTTP requests', unit: 'ms', valueType: 1 }, dataPointType: 0, dataPoints: [ { attributes: [Object], startTime: [Array], endTime: [Array], value: [Object] } ] } { descriptor: { name: 'http.client.duration', type: 'HISTOGRAM', description: 'measures the duration of the outbound HTTP requests', unit: 'ms', valueType: 1 }, dataPointType: 0, dataPoints: [] } { descriptor: { name: 'db.client.connections.usage', type: 'UP_DOWN_COUNTER', description: 'The number of connections that are currently in the state referenced by the attribute "state".', unit: '{connections}', valueType: 1 }, dataPointType: 3, dataPoints: [] } { descriptor: { name: 'http.server.duration', type: 'HISTOGRAM', description: 'measures the duration of the inbound HTTP requests', unit: 'ms', valueType: 1 }, dataPointType: 0, dataPoints: [ { attributes: [Object], startTime: [Array], endTime: [Array], value: [Object] } ] } { descriptor: { name: 'http.client.duration', type: 'HISTOGRAM', description: 'measures the duration of the outbound HTTP requests', unit: 'ms', valueType: 1 }, dataPointType: 0, dataPoints: [] } { descriptor: { name: 'db.client.connections.usage', type: 'UP_DOWN_COUNTER', description: 'The number of connections that are currently in the state referenced by the attribute "state".', unit: '{connections}', valueType: 1 }, dataPointType: 3, dataPoints: [] } { descriptor: { name: 'http.server.duration', type: 'HISTOGRAM', description: 'measures the duration of the inbound HTTP requests', unit: 'ms', valueType: 1 }, dataPointType: 0, dataPoints: [ { attributes: [Object], startTime: [Array], endTime: [Array], value: [Object] } ] } { descriptor: { name: 'http.client.duration', type: 'HISTOGRAM', description: 'measures the duration of the outbound HTTP requests', unit: 'ms', valueType: 1 }, dataPointType: 0, dataPoints: [] } { descriptor: { name: 'db.client.connections.usage', type: 'UP_DOWN_COUNTER', description: 'The number of connections that are currently in the state referenced by the attribute "state".', unit: '{connections}', valueType: 1 }, dataPointType: 3, dataPoints: [] } ``` <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Added a new OpenTelemetry plugin to better-auth that logs authentication metrics and traces to the server console. - **New Features** - oTelPlugin initializes OpenTelemetry with console exporters for spans and metrics. - oTelClientPlugin provides client-side compatibility for the plugin system. <!-- End of auto-generated description by cubic. --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2026-04-13 08:42:22 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#13022