@typed-sql/opentelemetry 2.0.0-rc.0
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/CHANGELOG.md +29 -0
- package/LICENSE +21 -0
- package/README.md +29 -0
- package/dist/packages/opentelemetry/src/index.d.ts +15 -0
- package/dist/packages/opentelemetry/src/index.d.ts.map +1 -0
- package/dist/packages/opentelemetry/src/index.js +87 -0
- package/dist/packages/opentelemetry/src/index.js.map +1 -0
- package/package.json +48 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# @typed-sql/opentelemetry
|
|
2
|
+
|
|
3
|
+
## 2.0.0-rc.0
|
|
4
|
+
|
|
5
|
+
### Major Changes
|
|
6
|
+
|
|
7
|
+
- 1b054b6: Add an adapter-neutral, redacted database observation lifecycle for queries, cardinality contracts,
|
|
8
|
+
batches, PostgreSQL pipelines, streams, cancellation, and nested transactions. Runtime fingerprints
|
|
9
|
+
correlate with compiler structural variants while SQL, parameter values, connection configuration,
|
|
10
|
+
and driver causes remain excluded by default. Publish the optional OpenTelemetry bridge with current
|
|
11
|
+
database semantic conventions and explicit high-cardinality or exception-capture opt-ins.
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- Updated dependencies [29afc3d]
|
|
16
|
+
- Updated dependencies [3f063f6]
|
|
17
|
+
- Updated dependencies [6a7ae58]
|
|
18
|
+
- Updated dependencies [b06fd0a]
|
|
19
|
+
- Updated dependencies [3050209]
|
|
20
|
+
- Updated dependencies [1b054b6]
|
|
21
|
+
- Updated dependencies [b4f1b6e]
|
|
22
|
+
- Updated dependencies [87189c3]
|
|
23
|
+
- Updated dependencies [e654fae]
|
|
24
|
+
- Updated dependencies [b2ec119]
|
|
25
|
+
- @typed-sql/core@2.0.0-rc.0
|
|
26
|
+
|
|
27
|
+
## 1.0.0
|
|
28
|
+
|
|
29
|
+
- Add an optional OpenTelemetry adapter for typed-sql's redacted database observation lifecycle.
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 typed-sql contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# @typed-sql/opentelemetry
|
|
2
|
+
|
|
3
|
+
Optional OpenTelemetry tracing for typed-sql's redacted database observer contract.
|
|
4
|
+
|
|
5
|
+
This package has a stable public contract. The OpenTelemetry API is an application-owned peer;
|
|
6
|
+
typed-sql does not install an SDK or exporter.
|
|
7
|
+
|
|
8
|
+
```sh
|
|
9
|
+
pnpm add @typed-sql/opentelemetry @opentelemetry/api
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
```ts
|
|
13
|
+
import { createOpenTelemetryObserver } from "@typed-sql/opentelemetry";
|
|
14
|
+
import { createPgDatabase } from "@typed-sql/postgres/pg";
|
|
15
|
+
|
|
16
|
+
const database = await createPgDatabase({
|
|
17
|
+
connectionString: process.env.DATABASE_URL!,
|
|
18
|
+
observer: createOpenTelemetryObserver(),
|
|
19
|
+
});
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
The default attributes contain a stable query fingerprint, dialect, grammar version, execution kind,
|
|
23
|
+
cardinality contract, and transaction depth. SQL text, parameter values, connection strings, driver
|
|
24
|
+
errors, batch fingerprint lists, and returned-row counts are excluded by default.
|
|
25
|
+
|
|
26
|
+
See the [observability guide](../../docs/guides/observability.md) for lifecycle semantics, opt-ins,
|
|
27
|
+
custom observers, and complete tracing setup.
|
|
28
|
+
|
|
29
|
+
MIT © typed-sql contributors
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { type Tracer } from "@opentelemetry/api";
|
|
2
|
+
import type { DatabaseObserver } from "@typed-sql/core";
|
|
3
|
+
export interface OpenTelemetryObserverOptions {
|
|
4
|
+
readonly tracer?: Tracer;
|
|
5
|
+
readonly instrumentationName?: string;
|
|
6
|
+
readonly instrumentationVersion?: string;
|
|
7
|
+
/** Opt-in because database row counts are an opt-in OpenTelemetry attribute. */
|
|
8
|
+
readonly recordReturnedRows?: boolean;
|
|
9
|
+
/** Opt-in because driver errors can contain query text or values. */
|
|
10
|
+
readonly recordExceptions?: boolean;
|
|
11
|
+
/** Opt-in because a fingerprint list can be high-cardinality for dynamic batches. */
|
|
12
|
+
readonly recordBatchFingerprints?: boolean;
|
|
13
|
+
}
|
|
14
|
+
export declare function createOpenTelemetryObserver(options?: OpenTelemetryObserverOptions): DatabaseObserver;
|
|
15
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiE,KAAK,MAAM,EAAS,MAAM,oBAAoB,CAAC;AACvH,OAAO,KAAK,EAEV,gBAAgB,EAGjB,MAAM,iBAAiB,CAAC;AAEzB,MAAM,WAAW,4BAA4B;IAC3C,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,mBAAmB,CAAC,EAAE,MAAM,CAAC;IACtC,QAAQ,CAAC,sBAAsB,CAAC,EAAE,MAAM,CAAC;IACzC,gFAAgF;IAChF,QAAQ,CAAC,kBAAkB,CAAC,EAAE,OAAO,CAAC;IACtC,qEAAqE;IACrE,QAAQ,CAAC,gBAAgB,CAAC,EAAE,OAAO,CAAC;IACpC,qFAAqF;IACrF,QAAQ,CAAC,uBAAuB,CAAC,EAAE,OAAO,CAAC;CAC5C;AA6DD,wBAAgB,2BAA2B,CAAC,OAAO,GAAE,4BAAiC,GAAG,gBAAgB,CAsBxG"}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { context, SpanKind, SpanStatusCode, trace } from "@opentelemetry/api";
|
|
2
|
+
function databaseSystem(dialect) {
|
|
3
|
+
if (dialect === "postgres")
|
|
4
|
+
return "postgresql";
|
|
5
|
+
return dialect;
|
|
6
|
+
}
|
|
7
|
+
function spanName(operation) {
|
|
8
|
+
const system = databaseSystem(operation.dialect);
|
|
9
|
+
if (operation.kind === "batch")
|
|
10
|
+
return `BATCH ${system}`;
|
|
11
|
+
if (operation.kind === "pipeline")
|
|
12
|
+
return `PIPELINE ${system}`;
|
|
13
|
+
if (operation.kind === "transaction")
|
|
14
|
+
return `TRANSACTION ${system}`;
|
|
15
|
+
return system;
|
|
16
|
+
}
|
|
17
|
+
function startAttributes(operation, options) {
|
|
18
|
+
const attributes = {
|
|
19
|
+
"db.system.name": databaseSystem(operation.dialect),
|
|
20
|
+
"typed_sql.grammar.version": operation.grammarVersion,
|
|
21
|
+
"typed_sql.operation.kind": operation.kind,
|
|
22
|
+
"typed_sql.transaction.depth": operation.transactionDepth,
|
|
23
|
+
};
|
|
24
|
+
if (operation.kind === "query") {
|
|
25
|
+
attributes["typed_sql.query.fingerprint"] = operation.fingerprint;
|
|
26
|
+
attributes["typed_sql.query.cardinality"] = operation.cardinality;
|
|
27
|
+
attributes["typed_sql.query.prepared"] = operation.prepared;
|
|
28
|
+
}
|
|
29
|
+
else if (operation.kind === "stream") {
|
|
30
|
+
attributes["typed_sql.query.fingerprint"] = operation.fingerprint;
|
|
31
|
+
attributes["typed_sql.query.prepared"] = operation.prepared;
|
|
32
|
+
}
|
|
33
|
+
else if (operation.kind === "batch" || operation.kind === "pipeline") {
|
|
34
|
+
attributes["db.operation.name"] = operation.kind === "batch" ? "BATCH" : "PIPELINE";
|
|
35
|
+
attributes["db.operation.batch.size"] = operation.size;
|
|
36
|
+
if (options.recordBatchFingerprints === true) {
|
|
37
|
+
attributes["typed_sql.query.fingerprints"] = [...operation.fingerprints];
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
else
|
|
41
|
+
attributes["db.operation.name"] = "TRANSACTION";
|
|
42
|
+
return attributes;
|
|
43
|
+
}
|
|
44
|
+
function endSpan(span, completion, options) {
|
|
45
|
+
span.setAttribute("typed_sql.duration_ms", completion.durationMilliseconds);
|
|
46
|
+
if (options.recordReturnedRows === true && completion.rowCount !== undefined) {
|
|
47
|
+
span.setAttribute("db.response.returned_rows", completion.rowCount);
|
|
48
|
+
}
|
|
49
|
+
if (completion.status !== "success") {
|
|
50
|
+
const errorType = completion.cancellationReason === "deadline"
|
|
51
|
+
? "timeout"
|
|
52
|
+
: completion.cancellationReason === "signal"
|
|
53
|
+
? "cancelled"
|
|
54
|
+
: (completion.errorType ?? "unknown");
|
|
55
|
+
span.setAttribute("error.type", errorType);
|
|
56
|
+
if (completion.cancellationReason !== undefined) {
|
|
57
|
+
span.setAttribute("typed_sql.cancellation.reason", completion.cancellationReason);
|
|
58
|
+
}
|
|
59
|
+
if (options.recordExceptions === true && completion.cause instanceof Error)
|
|
60
|
+
span.recordException(completion.cause);
|
|
61
|
+
span.setStatus({ code: SpanStatusCode.ERROR });
|
|
62
|
+
}
|
|
63
|
+
span.end();
|
|
64
|
+
}
|
|
65
|
+
export function createOpenTelemetryObserver(options = {}) {
|
|
66
|
+
const tracer = options.tracer ??
|
|
67
|
+
trace.getTracer(options.instrumentationName ?? "@typed-sql/opentelemetry", options.instrumentationVersion);
|
|
68
|
+
return Object.freeze({
|
|
69
|
+
captureErrorCause: options.recordExceptions === true,
|
|
70
|
+
start(operation) {
|
|
71
|
+
const span = tracer.startSpan(spanName(operation), {
|
|
72
|
+
kind: SpanKind.CLIENT,
|
|
73
|
+
attributes: startAttributes(operation, options),
|
|
74
|
+
});
|
|
75
|
+
const active = trace.setSpan(context.active(), span);
|
|
76
|
+
return {
|
|
77
|
+
run(callback) {
|
|
78
|
+
return context.with(active, callback);
|
|
79
|
+
},
|
|
80
|
+
end(completion) {
|
|
81
|
+
endSpan(span, completion, options);
|
|
82
|
+
},
|
|
83
|
+
};
|
|
84
|
+
},
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAmB,OAAO,EAAa,QAAQ,EAAE,cAAc,EAAe,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAoBvH,SAAS,cAAc,CAAC,OAAe;IACrC,IAAI,OAAO,KAAK,UAAU;QAAE,OAAO,YAAY,CAAC;IAChD,OAAO,OAAO,CAAC;AACjB,CAAC;AAED,SAAS,QAAQ,CAAC,SAAiC;IACjD,MAAM,MAAM,GAAG,cAAc,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC;IACjD,IAAI,SAAS,CAAC,IAAI,KAAK,OAAO;QAAE,OAAO,SAAS,MAAM,EAAE,CAAC;IACzD,IAAI,SAAS,CAAC,I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EAAE,CAAC;AACb,CAAC;AAED,MAAM,UAAU,2BAA2B,CAAC,OAAO,GAAiC,EAAE;IACpF,MAAM,MAAM,GACV,OAAO,CAAC,MAAM;QACd,KAAK,CAAC,SAAS,CAAC,OAAO,CAAC,mBAAmB,IAAI,0BAA0B,EAAE,OAAO,CAAC,sBAAsB,CAAC,CAAC;IAC7G,OAAO,MAAM,CAAC,MAAM,CAAC;QACnB,iBAAiB,EAAE,OAAO,CAAC,gBAAgB,KAAK,IAAI;QACpD,KAAK,CAAC,SAAiC;YACrC,MAAM,IAAI,GAAG,MAAM,CAAC,SAAS,CAAC,QAAQ,CAAC,SAAS,CAAC,EAAE;gBACjD,IAAI,EAAE,QAAQ,CAAC,MAAM;gBACrB,UAAU,EAAE,eAAe,CAAC,SAAS,EAAE,OAAO,CAAC;aAChD,CAAC,CAAC;YACH,MAAM,MAAM,GAAG,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,IAAI,CAAC,CAAC;YACrD,OAAO;gBACL,GAAG,CAAQ,QAAqB;oBAC9B,OAAO,OAAO,CAAC,IAAI,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;gBACxC,CAAC;gBACD,GAAG,CAAC,UAAgC;oBAClC,OAAO,CAAC,IAAI,EAAE,UAAU,EAAE,OAAO,CAAC,CAAC;gBACrC,CAAC;aACF,CAAC;QACJ,CAAC;KACF,CAAC,CAAC;AACL,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@typed-sql/opentelemetry",
|
|
3
|
+
"version": "2.0.0-rc.0",
|
|
4
|
+
"description": "Optional OpenTelemetry tracing integration for typed-sql database observers.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"author": "Lojhan",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/Lojhan/typed-sql.git",
|
|
10
|
+
"directory": "packages/opentelemetry"
|
|
11
|
+
},
|
|
12
|
+
"homepage": "https://github.com/Lojhan/typed-sql#readme",
|
|
13
|
+
"bugs": {
|
|
14
|
+
"url": "https://github.com/Lojhan/typed-sql/issues"
|
|
15
|
+
},
|
|
16
|
+
"engines": {
|
|
17
|
+
"node": ">=22.11"
|
|
18
|
+
},
|
|
19
|
+
"files": [
|
|
20
|
+
"dist/**/*.js",
|
|
21
|
+
"dist/**/*.d.ts",
|
|
22
|
+
"dist/**/*.map",
|
|
23
|
+
"README.md",
|
|
24
|
+
"LICENSE",
|
|
25
|
+
"CHANGELOG.md"
|
|
26
|
+
],
|
|
27
|
+
"publishConfig": {
|
|
28
|
+
"access": "public"
|
|
29
|
+
},
|
|
30
|
+
"typedSql": {
|
|
31
|
+
"releaseTrack": "stable"
|
|
32
|
+
},
|
|
33
|
+
"sideEffects": false,
|
|
34
|
+
"type": "module",
|
|
35
|
+
"exports": {
|
|
36
|
+
".": "./dist/packages/opentelemetry/src/index.js"
|
|
37
|
+
},
|
|
38
|
+
"dependencies": {
|
|
39
|
+
"@typed-sql/core": "2.0.0-rc.0"
|
|
40
|
+
},
|
|
41
|
+
"peerDependencies": {
|
|
42
|
+
"@opentelemetry/api": ">=1.9.0 <2"
|
|
43
|
+
},
|
|
44
|
+
"scripts": {
|
|
45
|
+
"test": "poku test --reporter=compact --enforce",
|
|
46
|
+
"coverage": "poku test --coverage=@pokujs/c8 --coverageConfig=.c8rc.json --reporter=compact --enforce"
|
|
47
|
+
}
|
|
48
|
+
}
|