File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11import { getSecret } from "../utils/secret" ;
22import { DEFAULT_DB_IDLE_TIMEOUT_MS , DEFAULT_DB_POOL_MAX } from "./config" ;
33
4- const createBunSqlClient = ( url : string ) => {
5- const { SQL } = require ( "bun" ) as typeof Bun ;
6- return new SQL ( {
7- url,
8- max : DEFAULT_DB_POOL_MAX ,
9- idleTimeout : DEFAULT_DB_IDLE_TIMEOUT_MS / 1_000 ,
10- } ) ;
11- } ;
12-
134export const GREPTIME_HOST = ( await getSecret ( "GREPTIME_HOST" ) ) ?? "localhost" ;
145
15- let _client : ReturnType < typeof createBunSqlClient > ;
6+ let _client : Bun . SQL ;
167
178/** Lazily created so BunSqlInstrumentation wraps `bun:sql` before the first `new SQL()` call. */
189export const getGreptimeSqlClient = ( ) =>
19- ( _client ??= createBunSqlClient ( `postgres://${ GREPTIME_HOST } :4003/public` ) ) ;
10+ ( _client ??= new ( require ( "bun" ) as typeof Bun ) . SQL ( {
11+ url : `postgres://${ GREPTIME_HOST } :4003/public` ,
12+ max : DEFAULT_DB_POOL_MAX ,
13+ idleTimeout : DEFAULT_DB_IDLE_TIMEOUT_MS / 1_000 ,
14+ } ) ) ;
2015
21- export type BunSqlClient = ReturnType < typeof createBunSqlClient > ;
16+ export type BunSqlClient = Bun . SQL ;
Original file line number Diff line number Diff line change @@ -87,9 +87,9 @@ export const getOtelConfig = (serviceName: string): ElysiaOpenTelemetryOptions =
8787 enhancedDatabaseReporting : false ,
8888 } ) ;
8989
90- // Bun loads all static ESM imports before any module body runs, so RITM hooks
91- // never fire for pg (https://github.com/oven-sh/bun/issues/3775). Patch it
92- // directly so the NodeSDK can produce spans and call setMeterProvider() on it .
90+ // In Bun, pg is already loaded via @prisma/adapter-pg before OTel's module-load
91+ // hooks can patch it. Patch pg.Client directly as a workaround, while still
92+ // passing the instrumentation to NodeSDK so providers are configured correctly .
9393 try {
9494 // oxlint-disable no-unsafe-assignment no-unsafe-call no-unsafe-member-access
9595 const { createRequire } = require ( "module" ) ;
You can’t perform that action at this time.
0 commit comments