@rocketflare/houston-otel 0.0.0-stage → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +172 -2
- package/dist/attributes.d.ts +16 -0
- package/dist/attributes.js +133 -0
- package/dist/genai.d.ts +97 -0
- package/dist/genai.js +200 -0
- package/dist/hono.d.ts +24 -0
- package/dist/hono.js +80 -0
- package/dist/houston.d.ts +124 -0
- package/dist/houston.js +353 -0
- package/dist/http.d.ts +8 -0
- package/dist/http.js +35 -0
- package/dist/ids.d.ts +17 -0
- package/dist/ids.js +35 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +7 -0
- package/dist/invocations.d.ts +56 -0
- package/dist/invocations.js +132 -0
- package/dist/otlp.d.ts +127 -0
- package/dist/otlp.js +83 -0
- package/dist/pino.d.ts +38 -0
- package/dist/pino.js +104 -0
- package/dist/sql-text.d.ts +25 -0
- package/dist/sql-text.js +297 -0
- package/dist/sql.d.ts +95 -0
- package/dist/sql.js +425 -0
- package/package.json +75 -4
package/dist/sql.js
ADDED
|
@@ -0,0 +1,425 @@
|
|
|
1
|
+
import { redactErrorMessage, redactSql, summarizeSql } from './sql-text.js';
|
|
2
|
+
export { redactErrorMessage, redactSql, summarizeSql } from './sql-text.js';
|
|
3
|
+
/** Default cap on `db.query.text`. */
|
|
4
|
+
export const DEFAULT_MAX_QUERY_TEXT = 2_048;
|
|
5
|
+
/** The host of a connection URL, never its credentials, path or query; undefined if it doesn't parse. */
|
|
6
|
+
export function serverAddressOf(url) {
|
|
7
|
+
if (!url)
|
|
8
|
+
return undefined;
|
|
9
|
+
try {
|
|
10
|
+
return new URL(url).hostname || undefined;
|
|
11
|
+
}
|
|
12
|
+
catch {
|
|
13
|
+
return undefined;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
const SQLSTATE = /^[0-9A-Z]{5}$/;
|
|
17
|
+
/** The SQLSTATE and a value-free message of a database error, read down its `cause` chain. */
|
|
18
|
+
export function dbErrorAttributes(error) {
|
|
19
|
+
let current = error;
|
|
20
|
+
let innermost = error;
|
|
21
|
+
for (let depth = 0; current && typeof current === 'object' && depth < 5; depth++) {
|
|
22
|
+
const code = current.code;
|
|
23
|
+
if (typeof code === 'string' && SQLSTATE.test(code))
|
|
24
|
+
return { code, type: code, message: redactErrorMessage(messageOf(current)) };
|
|
25
|
+
innermost = current;
|
|
26
|
+
current = current.cause;
|
|
27
|
+
}
|
|
28
|
+
return { type: innermost instanceof Error ? innermost.name : 'Error', message: redactErrorMessage(messageOf(innermost)) };
|
|
29
|
+
}
|
|
30
|
+
function messageOf(error) {
|
|
31
|
+
if (error instanceof Error)
|
|
32
|
+
return error.message;
|
|
33
|
+
const message = error?.message;
|
|
34
|
+
return typeof message === 'string' ? message : String(error);
|
|
35
|
+
}
|
|
36
|
+
function failed(span, error) {
|
|
37
|
+
try {
|
|
38
|
+
const { code, type, message } = dbErrorAttributes(error);
|
|
39
|
+
span.setAttributes({ 'error.type': type, 'db.response.status_code': code });
|
|
40
|
+
span.addEvent('exception', { 'exception.type': type, 'exception.message': message }); // no stack: it can quote values
|
|
41
|
+
span.setStatus('error', message);
|
|
42
|
+
}
|
|
43
|
+
catch {
|
|
44
|
+
// telemetry never changes the outcome
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
/** Rows a driver result carries: an array (postgres.js, neon without `fullResults`) or `{ rows }` (pg, neon). */
|
|
48
|
+
function returnedRows(result) {
|
|
49
|
+
if (Array.isArray(result))
|
|
50
|
+
return result.length;
|
|
51
|
+
const rows = result?.rows;
|
|
52
|
+
return Array.isArray(rows) ? rows.length : undefined;
|
|
53
|
+
}
|
|
54
|
+
function activeSpan(houston) {
|
|
55
|
+
const span = houston.activeSpan();
|
|
56
|
+
return span?.isRecording ? span : undefined;
|
|
57
|
+
}
|
|
58
|
+
// ---- spans --------------------------------------------------------------------------------------------------
|
|
59
|
+
const transactionSpans = new WeakSet();
|
|
60
|
+
const settingsOn = new WeakMap();
|
|
61
|
+
const pendingSettings = new WeakMap();
|
|
62
|
+
function addSetting(map, span, name) {
|
|
63
|
+
const names = map.get(span) ?? [];
|
|
64
|
+
if (!names.includes(name))
|
|
65
|
+
names.push(name);
|
|
66
|
+
map.set(span, names);
|
|
67
|
+
return names;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* The span for one statement about to run, or null when it gets none: houston off, no parent, transaction
|
|
71
|
+
* control, or a folded or skipped setting. `parent` overrides the active span (a driver's transaction handle).
|
|
72
|
+
*/
|
|
73
|
+
function startStatement(houston, text, options, parent) {
|
|
74
|
+
try {
|
|
75
|
+
if (!houston.enabled)
|
|
76
|
+
return null;
|
|
77
|
+
const under = parent?.isRecording ? parent : activeSpan(houston);
|
|
78
|
+
if (!under)
|
|
79
|
+
return null;
|
|
80
|
+
const summary = summarizeSql(text);
|
|
81
|
+
if (summary.kind === 'transaction')
|
|
82
|
+
return null;
|
|
83
|
+
const noise = options.noise ?? 'fold';
|
|
84
|
+
if (summary.kind === 'setting' && noise !== 'span') {
|
|
85
|
+
if (noise === 'fold' && summary.name) {
|
|
86
|
+
if (transactionSpans.has(under))
|
|
87
|
+
under.setAttribute('db.transaction.settings', [...addSetting(settingsOn, under, summary.name)]);
|
|
88
|
+
else
|
|
89
|
+
addSetting(pendingSettings, under, summary.name);
|
|
90
|
+
}
|
|
91
|
+
return null;
|
|
92
|
+
}
|
|
93
|
+
const operation = summary.kind === 'setting' ? 'SET' : summary.operation;
|
|
94
|
+
const collection = summary.kind === 'statement' ? summary.collection : undefined;
|
|
95
|
+
const querySummary = operation ? (collection ? `${operation} ${collection}` : operation) : undefined;
|
|
96
|
+
const system = options.system ?? 'postgresql';
|
|
97
|
+
const attributes = {
|
|
98
|
+
'db.system.name': system,
|
|
99
|
+
'db.operation.name': operation,
|
|
100
|
+
'db.collection.name': collection,
|
|
101
|
+
'db.query.summary': querySummary,
|
|
102
|
+
'server.address': options.serverAddress,
|
|
103
|
+
};
|
|
104
|
+
if ((options.queryText ?? houston.dbQueryText) !== false)
|
|
105
|
+
attributes['db.query.text'] = redactSql(text, options.maxQueryTextLength ?? DEFAULT_MAX_QUERY_TEXT);
|
|
106
|
+
const pending = pendingSettings.get(under);
|
|
107
|
+
if (pending) {
|
|
108
|
+
attributes['db.settings'] = pending;
|
|
109
|
+
pendingSettings.delete(under);
|
|
110
|
+
}
|
|
111
|
+
return houston.startSpan(querySummary ?? system, { kind: 'client', attributes, parent: under });
|
|
112
|
+
}
|
|
113
|
+
catch {
|
|
114
|
+
return null;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
function endStatement(span, result) {
|
|
118
|
+
try {
|
|
119
|
+
span.setAttribute('db.response.returned_rows', returnedRows(result));
|
|
120
|
+
span.end();
|
|
121
|
+
}
|
|
122
|
+
catch {
|
|
123
|
+
// telemetry never changes the outcome
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
/** Run `run` (a statement) under `span` when there is one; the result or error always reaches the caller. */
|
|
127
|
+
function settle(span, run) {
|
|
128
|
+
let pending;
|
|
129
|
+
try {
|
|
130
|
+
pending = run();
|
|
131
|
+
}
|
|
132
|
+
catch (error) {
|
|
133
|
+
if (span) {
|
|
134
|
+
failed(span, error);
|
|
135
|
+
span.end();
|
|
136
|
+
}
|
|
137
|
+
return Promise.reject(error);
|
|
138
|
+
}
|
|
139
|
+
return Promise.resolve(pending).then((result) => {
|
|
140
|
+
if (span)
|
|
141
|
+
endStatement(span, result);
|
|
142
|
+
return result;
|
|
143
|
+
}, (error) => {
|
|
144
|
+
if (span) {
|
|
145
|
+
failed(span, error);
|
|
146
|
+
span.end();
|
|
147
|
+
}
|
|
148
|
+
throw error;
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Run one statement under a CLIENT span named `<operation> <table>`, a child of the active span. `run` is
|
|
153
|
+
* called exactly once; without houston or an active span it simply runs. For drivers the adapters don't cover.
|
|
154
|
+
*/
|
|
155
|
+
export function traceQuery(houston, query, run) {
|
|
156
|
+
return settle(startStatement(houston, query.text, query), run);
|
|
157
|
+
}
|
|
158
|
+
function startTransaction(houston, options, parent, attributes = {}) {
|
|
159
|
+
try {
|
|
160
|
+
if (!houston.enabled)
|
|
161
|
+
return null;
|
|
162
|
+
const under = parent?.isRecording ? parent : activeSpan(houston);
|
|
163
|
+
if (!under)
|
|
164
|
+
return null;
|
|
165
|
+
const span = houston.startSpan('transaction', {
|
|
166
|
+
parent: under,
|
|
167
|
+
attributes: { 'db.system.name': options.system ?? 'postgresql', 'server.address': options.serverAddress, ...attributes },
|
|
168
|
+
});
|
|
169
|
+
transactionSpans.add(span);
|
|
170
|
+
return span;
|
|
171
|
+
}
|
|
172
|
+
catch {
|
|
173
|
+
return null;
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
function endTransaction(span, error) {
|
|
177
|
+
if (error !== undefined)
|
|
178
|
+
failed(span, error);
|
|
179
|
+
span.end();
|
|
180
|
+
}
|
|
181
|
+
async function inTransaction(houston, span, run) {
|
|
182
|
+
if (!span)
|
|
183
|
+
return run(null);
|
|
184
|
+
try {
|
|
185
|
+
const result = await houston.withSpan(span, () => run(span));
|
|
186
|
+
endTransaction(span);
|
|
187
|
+
return result;
|
|
188
|
+
}
|
|
189
|
+
catch (error) {
|
|
190
|
+
endTransaction(span, error);
|
|
191
|
+
throw error;
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* Run `run` (a whole transaction) under one `transaction` span, active for its statements; settings inside it
|
|
196
|
+
* are folded onto it. A throw marks it ERROR and is rethrown. No span without houston or an active span.
|
|
197
|
+
*/
|
|
198
|
+
export function traceTransaction(houston, run, options = {}) {
|
|
199
|
+
return inTransaction(houston, startTransaction(houston, options), () => run());
|
|
200
|
+
}
|
|
201
|
+
// ---- adapters (structural: no driver is imported) -----------------------------------------------------------
|
|
202
|
+
const INSTRUMENTED = Symbol.for('@rocketflare/houston-otel/sql');
|
|
203
|
+
function mark(target) {
|
|
204
|
+
if (target[INSTRUMENTED])
|
|
205
|
+
return false;
|
|
206
|
+
try {
|
|
207
|
+
Object.defineProperty(target, INSTRUMENTED, { value: true });
|
|
208
|
+
return true;
|
|
209
|
+
}
|
|
210
|
+
catch {
|
|
211
|
+
return false;
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
/** A host from a client's own options (`host`, `hosts`, `connectionString`), when it shows one. */
|
|
215
|
+
function hostOf(client) {
|
|
216
|
+
try {
|
|
217
|
+
const o = client?.options;
|
|
218
|
+
if (!o)
|
|
219
|
+
return undefined;
|
|
220
|
+
const host = Array.isArray(o.host) ? o.host[0] : o.host;
|
|
221
|
+
if (typeof host === 'string' && host && !host.startsWith('/'))
|
|
222
|
+
return host;
|
|
223
|
+
return typeof o.connectionString === 'string' ? serverAddressOf(o.connectionString) : undefined;
|
|
224
|
+
}
|
|
225
|
+
catch {
|
|
226
|
+
return undefined;
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
const withHost = (options, client) => options.serverAddress ? options : { ...options, serverAddress: hostOf(client) };
|
|
230
|
+
/**
|
|
231
|
+
* A lazily run query (postgres.js and neon run on the first `then`): patch this one object's `then`, `catch`
|
|
232
|
+
* and `finally` so the span starts when it runs, once however it's awaited, and an unawaited query handed to a
|
|
233
|
+
* batch (neon's `transaction([...])`) is never run by the tracing.
|
|
234
|
+
*/
|
|
235
|
+
function traceLazy(houston, text, query, options, parent) {
|
|
236
|
+
if (!query || typeof query.then !== 'function')
|
|
237
|
+
return query;
|
|
238
|
+
if (!parent?.isRecording && !activeSpan(houston))
|
|
239
|
+
return query;
|
|
240
|
+
const q = query;
|
|
241
|
+
const original = q.then;
|
|
242
|
+
let traced;
|
|
243
|
+
const run = () => (traced ??= settle(startStatement(houston, text, options, parent), () => original.call(q, (x) => x)));
|
|
244
|
+
const then = (onFulfilled, onRejected) => run().then(onFulfilled, onRejected);
|
|
245
|
+
try {
|
|
246
|
+
Object.defineProperty(q, 'then', { value: then, configurable: true, writable: true });
|
|
247
|
+
Object.defineProperty(q, 'catch', { value: (onRejected) => run().catch(onRejected), configurable: true, writable: true });
|
|
248
|
+
Object.defineProperty(q, 'finally', { value: (onFinally) => run().finally(onFinally), configurable: true, writable: true });
|
|
249
|
+
}
|
|
250
|
+
catch {
|
|
251
|
+
// a frozen query object: leave it untraced
|
|
252
|
+
}
|
|
253
|
+
return q;
|
|
254
|
+
}
|
|
255
|
+
/** The last function among `args`, replaced by `wrap(it)`: the callback of `begin` / `savepoint`. */
|
|
256
|
+
function wrapCallback(args, wrap) {
|
|
257
|
+
let at = args.length - 1;
|
|
258
|
+
while (at >= 0 && typeof args[at] !== 'function')
|
|
259
|
+
at--;
|
|
260
|
+
if (at < 0)
|
|
261
|
+
return args;
|
|
262
|
+
const out = [...args];
|
|
263
|
+
out[at] = wrap(args[at]);
|
|
264
|
+
return out;
|
|
265
|
+
}
|
|
266
|
+
function patchPostgresJs(houston, sql, options, parent) {
|
|
267
|
+
if (!mark(sql))
|
|
268
|
+
return sql;
|
|
269
|
+
const unsafe = sql.unsafe;
|
|
270
|
+
sql.unsafe = function (text, ...rest) {
|
|
271
|
+
return traceLazy(houston, text, unsafe.call(this, text, ...rest), options, parent);
|
|
272
|
+
};
|
|
273
|
+
const begin = sql.begin;
|
|
274
|
+
if (typeof begin === 'function') {
|
|
275
|
+
sql.begin = function (...args) {
|
|
276
|
+
const outer = parent?.isRecording ? parent : activeSpan(houston);
|
|
277
|
+
// one transaction span, unless one is already open around this call (instrumentTransactions)
|
|
278
|
+
const own = outer && transactionSpans.has(outer) ? null : startTransaction(houston, options, parent);
|
|
279
|
+
const under = own ?? outer;
|
|
280
|
+
const scoped = (fn) => ((tx) => fn(patchPostgresJs(houston, tx, options, under)));
|
|
281
|
+
return inTransaction(houston, own, () => begin.apply(this, wrapCallback(args, scoped)));
|
|
282
|
+
};
|
|
283
|
+
}
|
|
284
|
+
const savepoint = sql.savepoint;
|
|
285
|
+
if (typeof savepoint === 'function') {
|
|
286
|
+
sql.savepoint = function (...args) {
|
|
287
|
+
const scoped = (fn) => ((tx) => fn(patchPostgresJs(houston, tx, options, parent)));
|
|
288
|
+
return savepoint.apply(this, wrapCallback(args, scoped));
|
|
289
|
+
};
|
|
290
|
+
}
|
|
291
|
+
return sql;
|
|
292
|
+
}
|
|
293
|
+
/**
|
|
294
|
+
* postgres.js (`postgres(url)`): `sql.unsafe` (what drizzle runs every statement through) and the handles that
|
|
295
|
+
* `begin` and `savepoint` give their callbacks; `begin` is one `transaction` span. Mutates and returns `sql`.
|
|
296
|
+
* Tagged-template calls (`` sql`…` ``) are not traced.
|
|
297
|
+
*/
|
|
298
|
+
export function instrumentPostgresJs(houston, sql, options = {}) {
|
|
299
|
+
if (!houston.enabled)
|
|
300
|
+
return sql;
|
|
301
|
+
return patchPostgresJs(houston, sql, withHost(options, sql));
|
|
302
|
+
}
|
|
303
|
+
/**
|
|
304
|
+
* The `@neondatabase/serverless` HTTP function (`neon(url)`): its `query(text, params, opts)`, which drizzle's
|
|
305
|
+
* neon-http driver calls, and `transaction([...])`, one `transaction` span with `db.operation.batch.size`
|
|
306
|
+
* (drizzle's `db.batch`). Patch it before handing it to drizzle, which reads `query` once. Mutates and returns
|
|
307
|
+
* `sql`. Tagged-template calls (`` sql`…` ``) are not traced.
|
|
308
|
+
*/
|
|
309
|
+
export function instrumentNeonHttp(houston, sql, options = {}) {
|
|
310
|
+
if (!houston.enabled || !mark(sql))
|
|
311
|
+
return sql;
|
|
312
|
+
const query = sql.query;
|
|
313
|
+
sql.query = function (text, ...rest) {
|
|
314
|
+
return traceLazy(houston, text, query.call(this, text, ...rest), options);
|
|
315
|
+
};
|
|
316
|
+
const transaction = sql.transaction;
|
|
317
|
+
if (typeof transaction === 'function') {
|
|
318
|
+
sql.transaction = function (...args) {
|
|
319
|
+
const size = Array.isArray(args[0]) ? args[0].length : undefined;
|
|
320
|
+
const span = startTransaction(houston, options, undefined, { 'db.operation.batch.size': size });
|
|
321
|
+
return inTransaction(houston, span, () => transaction.apply(this, args));
|
|
322
|
+
};
|
|
323
|
+
}
|
|
324
|
+
return sql;
|
|
325
|
+
}
|
|
326
|
+
function textOf(arg) {
|
|
327
|
+
if (typeof arg === 'string')
|
|
328
|
+
return arg;
|
|
329
|
+
const text = arg?.text;
|
|
330
|
+
return typeof text === 'string' ? text : undefined;
|
|
331
|
+
}
|
|
332
|
+
/** BEGIN / START opens a transaction, COMMIT / END / ROLLBACK / ABORT closes it (ROLLBACK TO SAVEPOINT doesn't). */
|
|
333
|
+
function transactionControl(text) {
|
|
334
|
+
const m = /^\s*([a-z]+)(?:\s+(?:work|transaction))?(\s+to\b)?/i.exec(text);
|
|
335
|
+
const word = m?.[1].toUpperCase();
|
|
336
|
+
if (word === 'BEGIN' || word === 'START')
|
|
337
|
+
return 'open';
|
|
338
|
+
if (word === 'COMMIT' || word === 'END' || word === 'ABORT')
|
|
339
|
+
return 'close';
|
|
340
|
+
if (word === 'ROLLBACK' && !m?.[2])
|
|
341
|
+
return 'close';
|
|
342
|
+
return undefined;
|
|
343
|
+
}
|
|
344
|
+
/**
|
|
345
|
+
* `query` in its promise form. The callback form (which `pg-pool` itself uses on the client it checks out for
|
|
346
|
+
* `pool.query`) passes straight through, so nothing is spanned twice. On a client, `BEGIN` … `COMMIT` /
|
|
347
|
+
* `ROLLBACK` is one `transaction` span its statements nest under (ROLLBACK marks it ERROR).
|
|
348
|
+
*/
|
|
349
|
+
function patchPgQuery(houston, target, options, transactions) {
|
|
350
|
+
if (!mark(target))
|
|
351
|
+
return;
|
|
352
|
+
const query = target.query;
|
|
353
|
+
let open;
|
|
354
|
+
target.query = function (...args) {
|
|
355
|
+
const text = textOf(args[0]);
|
|
356
|
+
if (text === undefined || typeof args[args.length - 1] === 'function')
|
|
357
|
+
return query.apply(this, args);
|
|
358
|
+
const run = () => query.apply(this, args);
|
|
359
|
+
// a pool's queries each run on whichever client is free: only a client has a transaction
|
|
360
|
+
const control = transactions ? transactionControl(text) : undefined;
|
|
361
|
+
if (control === 'open' && !open?.span.isRecording) {
|
|
362
|
+
const outer = activeSpan(houston);
|
|
363
|
+
if (outer && transactionSpans.has(outer))
|
|
364
|
+
open = { span: outer, own: false };
|
|
365
|
+
else {
|
|
366
|
+
const span = startTransaction(houston, options);
|
|
367
|
+
open = span ? { span, own: true } : undefined;
|
|
368
|
+
}
|
|
369
|
+
return settle(null, run);
|
|
370
|
+
}
|
|
371
|
+
if (control === 'close' && open) {
|
|
372
|
+
const { span, own } = open;
|
|
373
|
+
open = undefined;
|
|
374
|
+
const rolledBack = /^\s*(rollback|abort)/i.test(text);
|
|
375
|
+
return settle(null, run).then((result) => {
|
|
376
|
+
if (own) {
|
|
377
|
+
if (rolledBack)
|
|
378
|
+
span.setStatus('error', 'rollback');
|
|
379
|
+
endTransaction(span);
|
|
380
|
+
}
|
|
381
|
+
return result;
|
|
382
|
+
}, (error) => {
|
|
383
|
+
if (own)
|
|
384
|
+
endTransaction(span, error);
|
|
385
|
+
throw error;
|
|
386
|
+
});
|
|
387
|
+
}
|
|
388
|
+
return settle(startStatement(houston, text, options, open?.span), run);
|
|
389
|
+
};
|
|
390
|
+
}
|
|
391
|
+
/**
|
|
392
|
+
* A `pg`-compatible client (`@neondatabase/serverless`'s `Client`, node-postgres): `client.query`, with
|
|
393
|
+
* `BEGIN` … `COMMIT` as one `transaction` span. Mutates and returns `client`.
|
|
394
|
+
*/
|
|
395
|
+
export function instrumentPgClient(houston, client, options = {}) {
|
|
396
|
+
if (houston.enabled)
|
|
397
|
+
patchPgQuery(houston, client, withHost(options, client), true);
|
|
398
|
+
return client;
|
|
399
|
+
}
|
|
400
|
+
/**
|
|
401
|
+
* A `pg`-compatible pool (`@neondatabase/serverless`'s `Pool`, what drizzle's neon-serverless driver takes):
|
|
402
|
+
* `pool.query` and every client it opens (`pool.connect()`, where interactive transactions run). Mutates and
|
|
403
|
+
* returns `pool`.
|
|
404
|
+
*/
|
|
405
|
+
export function instrumentPgPool(houston, pool, options = {}) {
|
|
406
|
+
if (!houston.enabled)
|
|
407
|
+
return pool;
|
|
408
|
+
const opts = withHost(options, pool);
|
|
409
|
+
patchPgQuery(houston, pool, opts, false);
|
|
410
|
+
pool.on('connect', (client) => patchPgQuery(houston, client, opts, true));
|
|
411
|
+
return pool;
|
|
412
|
+
}
|
|
413
|
+
/**
|
|
414
|
+
* `db.transaction(fn, …)` (an ORM's, for drivers the adapters don't cover) as one `transaction` span its
|
|
415
|
+
* statements nest under. The adapters' own transaction spans join it rather than nest. Mutates and returns `db`.
|
|
416
|
+
*/
|
|
417
|
+
export function instrumentTransactions(houston, db, options = {}) {
|
|
418
|
+
if (!houston.enabled)
|
|
419
|
+
return db;
|
|
420
|
+
const original = db.transaction;
|
|
421
|
+
db.transaction = function (...args) {
|
|
422
|
+
return traceTransaction(houston, () => original.apply(this, args), options);
|
|
423
|
+
};
|
|
424
|
+
return db;
|
|
425
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,77 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rocketflare/houston-otel",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "Logs, request spans, SQL spans and gen_ai spans from Cloudflare Workers to houston over OTLP/HTTP JSON, batched in waitUntil, with no runtime dependencies",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"sideEffects": false,
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"default": "./dist/index.js"
|
|
12
|
+
},
|
|
13
|
+
"./hono": {
|
|
14
|
+
"types": "./dist/hono.d.ts",
|
|
15
|
+
"default": "./dist/hono.js"
|
|
16
|
+
},
|
|
17
|
+
"./pino": {
|
|
18
|
+
"types": "./dist/pino.d.ts",
|
|
19
|
+
"default": "./dist/pino.js"
|
|
20
|
+
},
|
|
21
|
+
"./sql": {
|
|
22
|
+
"types": "./dist/sql.d.ts",
|
|
23
|
+
"default": "./dist/sql.js"
|
|
24
|
+
},
|
|
25
|
+
"./genai": {
|
|
26
|
+
"types": "./dist/genai.d.ts",
|
|
27
|
+
"default": "./dist/genai.js"
|
|
28
|
+
},
|
|
29
|
+
"./package.json": "./package.json"
|
|
30
|
+
},
|
|
31
|
+
"files": [
|
|
32
|
+
"dist",
|
|
33
|
+
"README.md"
|
|
34
|
+
],
|
|
35
|
+
"engines": {
|
|
36
|
+
"node": ">=22"
|
|
37
|
+
},
|
|
38
|
+
"keywords": [
|
|
39
|
+
"observability",
|
|
40
|
+
"opentelemetry",
|
|
41
|
+
"otlp",
|
|
42
|
+
"cloudflare-workers",
|
|
43
|
+
"hono",
|
|
44
|
+
"pino",
|
|
45
|
+
"tracing",
|
|
46
|
+
"logs"
|
|
47
|
+
],
|
|
48
|
+
"scripts": {
|
|
49
|
+
"build": "node build.mjs",
|
|
50
|
+
"prepublishOnly": "npm run build"
|
|
51
|
+
},
|
|
52
|
+
"peerDependencies": {
|
|
53
|
+
"hono": "^4.6.0",
|
|
54
|
+
"pino": ">=9"
|
|
55
|
+
},
|
|
56
|
+
"peerDependenciesMeta": {
|
|
57
|
+
"hono": {
|
|
58
|
+
"optional": true
|
|
59
|
+
},
|
|
60
|
+
"pino": {
|
|
61
|
+
"optional": true
|
|
62
|
+
}
|
|
63
|
+
},
|
|
64
|
+
"devDependencies": {
|
|
65
|
+
"hono": "^4.13.13",
|
|
66
|
+
"pino": "^10.4.0"
|
|
67
|
+
},
|
|
68
|
+
"repository": {
|
|
69
|
+
"type": "git",
|
|
70
|
+
"url": "git+https://github.com/rocketflare-dev/houston.git",
|
|
71
|
+
"directory": "otel"
|
|
72
|
+
},
|
|
73
|
+
"homepage": "https://github.com/rocketflare-dev/houston/blob/main/otel/README.md",
|
|
74
|
+
"bugs": {
|
|
75
|
+
"url": "https://github.com/rocketflare-dev/houston/issues"
|
|
76
|
+
}
|
|
77
|
+
}
|