@tummycrypt/tinyland-tracing-middleware 0.2.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/dist/config.d.ts +40 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +56 -0
- package/dist/config.js.map +1 -0
- package/dist/index.d.ts +30 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +31 -0
- package/dist/index.js.map +1 -0
- package/dist/middleware.d.ts +54 -0
- package/dist/middleware.d.ts.map +1 -0
- package/dist/middleware.js +121 -0
- package/dist/middleware.js.map +1 -0
- package/dist/types.d.ts +78 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +10 -0
- package/dist/types.js.map +1 -0
- package/package.json +57 -0
package/dist/config.d.ts
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Configuration management for tracing middleware.
|
|
3
|
+
*
|
|
4
|
+
* Uses a module-level singleton to store injected dependencies.
|
|
5
|
+
* Must be called before any middleware is invoked.
|
|
6
|
+
*
|
|
7
|
+
* @module config
|
|
8
|
+
*/
|
|
9
|
+
import type { TracingMiddlewareConfig } from './types.js';
|
|
10
|
+
/**
|
|
11
|
+
* Configure the tracing middleware with injected dependencies.
|
|
12
|
+
*
|
|
13
|
+
* Must be called once at application startup before any tRPC
|
|
14
|
+
* procedures are invoked.
|
|
15
|
+
*
|
|
16
|
+
* @param config - The tracing configuration with createSpan and SpanKind
|
|
17
|
+
* @throws {Error} If config is missing required fields
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```typescript
|
|
21
|
+
* import { configure } from '@tummycrypt/tinyland-tracing-middleware';
|
|
22
|
+
* import { createSpan, SpanKind } from '@tummycrypt/tinyland-otel';
|
|
23
|
+
*
|
|
24
|
+
* configure({ createSpan, SpanKind });
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
export declare function configure(config: TracingMiddlewareConfig): void;
|
|
28
|
+
/**
|
|
29
|
+
* Retrieve the current configuration.
|
|
30
|
+
*
|
|
31
|
+
* @returns The current TracingMiddlewareConfig
|
|
32
|
+
* @throws {Error} If configure() has not been called
|
|
33
|
+
*/
|
|
34
|
+
export declare function getConfig(): TracingMiddlewareConfig;
|
|
35
|
+
/**
|
|
36
|
+
* Reset configuration to unconfigured state.
|
|
37
|
+
* Primarily useful for testing.
|
|
38
|
+
*/
|
|
39
|
+
export declare function resetConfig(): void;
|
|
40
|
+
//# sourceMappingURL=config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,YAAY,CAAC;AAI1D;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,SAAS,CAAC,MAAM,EAAE,uBAAuB,GAAG,IAAI,CAY/D;AAED;;;;;GAKG;AACH,wBAAgB,SAAS,IAAI,uBAAuB,CAQnD;AAED;;;GAGG;AACH,wBAAgB,WAAW,IAAI,IAAI,CAElC"}
|
package/dist/config.js
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Configuration management for tracing middleware.
|
|
3
|
+
*
|
|
4
|
+
* Uses a module-level singleton to store injected dependencies.
|
|
5
|
+
* Must be called before any middleware is invoked.
|
|
6
|
+
*
|
|
7
|
+
* @module config
|
|
8
|
+
*/
|
|
9
|
+
let _config = null;
|
|
10
|
+
/**
|
|
11
|
+
* Configure the tracing middleware with injected dependencies.
|
|
12
|
+
*
|
|
13
|
+
* Must be called once at application startup before any tRPC
|
|
14
|
+
* procedures are invoked.
|
|
15
|
+
*
|
|
16
|
+
* @param config - The tracing configuration with createSpan and SpanKind
|
|
17
|
+
* @throws {Error} If config is missing required fields
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```typescript
|
|
21
|
+
* import { configure } from '@tummycrypt/tinyland-tracing-middleware';
|
|
22
|
+
* import { createSpan, SpanKind } from '@tummycrypt/tinyland-otel';
|
|
23
|
+
*
|
|
24
|
+
* configure({ createSpan, SpanKind });
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
export function configure(config) {
|
|
28
|
+
if (!config.createSpan || typeof config.createSpan !== 'function') {
|
|
29
|
+
throw new Error('tinyland-tracing-middleware: configure() requires a createSpan function');
|
|
30
|
+
}
|
|
31
|
+
if (!config.SpanKind || typeof config.SpanKind.SERVER !== 'number') {
|
|
32
|
+
throw new Error('tinyland-tracing-middleware: configure() requires a SpanKind object with a numeric SERVER property');
|
|
33
|
+
}
|
|
34
|
+
_config = config;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Retrieve the current configuration.
|
|
38
|
+
*
|
|
39
|
+
* @returns The current TracingMiddlewareConfig
|
|
40
|
+
* @throws {Error} If configure() has not been called
|
|
41
|
+
*/
|
|
42
|
+
export function getConfig() {
|
|
43
|
+
if (!_config) {
|
|
44
|
+
throw new Error('tinyland-tracing-middleware: configure() must be called before using middleware. ' +
|
|
45
|
+
'Call configure({ createSpan, SpanKind }) at application startup.');
|
|
46
|
+
}
|
|
47
|
+
return _config;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Reset configuration to unconfigured state.
|
|
51
|
+
* Primarily useful for testing.
|
|
52
|
+
*/
|
|
53
|
+
export function resetConfig() {
|
|
54
|
+
_config = null;
|
|
55
|
+
}
|
|
56
|
+
//# sourceMappingURL=config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAIH,IAAI,OAAO,GAAmC,IAAI,CAAC;AAEnD;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,UAAU,SAAS,CAAC,MAA+B;IACvD,IAAI,CAAC,MAAM,CAAC,UAAU,IAAI,OAAO,MAAM,CAAC,UAAU,KAAK,UAAU,EAAE,CAAC;QAClE,MAAM,IAAI,KAAK,CACb,yEAAyE,CAC1E,CAAC;IACJ,CAAC;IACD,IAAI,CAAC,MAAM,CAAC,QAAQ,IAAI,OAAO,MAAM,CAAC,QAAQ,CAAC,MAAM,KAAK,QAAQ,EAAE,CAAC;QACnE,MAAM,IAAI,KAAK,CACb,oGAAoG,CACrG,CAAC;IACJ,CAAC;IACD,OAAO,GAAG,MAAM,CAAC;AACnB,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,SAAS;IACvB,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,MAAM,IAAI,KAAK,CACb,mFAAmF;YACnF,kEAAkE,CACnE,CAAC;IACJ,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,WAAW;IACzB,OAAO,GAAG,IAAI,CAAC;AACjB,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @tummycrypt/tinyland-tracing-middleware
|
|
3
|
+
*
|
|
4
|
+
* tRPC OpenTelemetry tracing middleware with dependency injection.
|
|
5
|
+
* Zero runtime dependencies -- tracing is injected via configure().
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* import {
|
|
10
|
+
* configure,
|
|
11
|
+
* tracingMiddleware,
|
|
12
|
+
* tracingMiddlewareSimple,
|
|
13
|
+
* tracingMiddlewareFull,
|
|
14
|
+
* } from '@tummycrypt/tinyland-tracing-middleware';
|
|
15
|
+
* import { createSpan, SpanKind } from '@tummycrypt/tinyland-otel';
|
|
16
|
+
*
|
|
17
|
+
* // At application startup
|
|
18
|
+
* configure({ createSpan, SpanKind });
|
|
19
|
+
*
|
|
20
|
+
* // In router definition
|
|
21
|
+
* export const publicProcedure = t.procedure.use(tracingMiddlewareSimple);
|
|
22
|
+
* export const debugProcedure = t.procedure.use(tracingMiddlewareFull);
|
|
23
|
+
* ```
|
|
24
|
+
*
|
|
25
|
+
* @module index
|
|
26
|
+
*/
|
|
27
|
+
export { configure, getConfig, resetConfig } from './config.js';
|
|
28
|
+
export { tracingMiddleware, tracingMiddlewareSimple, tracingMiddlewareFull, } from './middleware.js';
|
|
29
|
+
export type { Span, TracingContext, SpanKindEnum, TracingMiddlewareConfig, TracingMiddlewareOptions, MiddlewareParams, } from './types.js';
|
|
30
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAGH,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAGhE,OAAO,EACL,iBAAiB,EACjB,uBAAuB,EACvB,qBAAqB,GACtB,MAAM,iBAAiB,CAAC;AAGzB,YAAY,EACV,IAAI,EACJ,cAAc,EACd,YAAY,EACZ,uBAAuB,EACvB,wBAAwB,EACxB,gBAAgB,GACjB,MAAM,YAAY,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @tummycrypt/tinyland-tracing-middleware
|
|
3
|
+
*
|
|
4
|
+
* tRPC OpenTelemetry tracing middleware with dependency injection.
|
|
5
|
+
* Zero runtime dependencies -- tracing is injected via configure().
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* import {
|
|
10
|
+
* configure,
|
|
11
|
+
* tracingMiddleware,
|
|
12
|
+
* tracingMiddlewareSimple,
|
|
13
|
+
* tracingMiddlewareFull,
|
|
14
|
+
* } from '@tummycrypt/tinyland-tracing-middleware';
|
|
15
|
+
* import { createSpan, SpanKind } from '@tummycrypt/tinyland-otel';
|
|
16
|
+
*
|
|
17
|
+
* // At application startup
|
|
18
|
+
* configure({ createSpan, SpanKind });
|
|
19
|
+
*
|
|
20
|
+
* // In router definition
|
|
21
|
+
* export const publicProcedure = t.procedure.use(tracingMiddlewareSimple);
|
|
22
|
+
* export const debugProcedure = t.procedure.use(tracingMiddlewareFull);
|
|
23
|
+
* ```
|
|
24
|
+
*
|
|
25
|
+
* @module index
|
|
26
|
+
*/
|
|
27
|
+
// Configuration
|
|
28
|
+
export { configure, getConfig, resetConfig } from './config.js';
|
|
29
|
+
// Middleware
|
|
30
|
+
export { tracingMiddleware, tracingMiddlewareSimple, tracingMiddlewareFull, } from './middleware.js';
|
|
31
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAEH,gBAAgB;AAChB,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAEhE,aAAa;AACb,OAAO,EACL,iBAAiB,EACjB,uBAAuB,EACvB,qBAAqB,GACtB,MAAM,iBAAiB,CAAC"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* tRPC OpenTelemetry Tracing Middleware
|
|
3
|
+
*
|
|
4
|
+
* Adds distributed tracing to all tRPC procedures via dependency injection.
|
|
5
|
+
* Replaces the broken @baselime/trpc-opentelemetry-middleware
|
|
6
|
+
* which uses CommonJS-only dependencies.
|
|
7
|
+
*
|
|
8
|
+
* Architecture:
|
|
9
|
+
* - ESM-compatible, zero runtime dependencies
|
|
10
|
+
* - Tracing injected via configure() at startup
|
|
11
|
+
* - Manual span creation (no auto-instrumentation)
|
|
12
|
+
*
|
|
13
|
+
* @module middleware
|
|
14
|
+
*/
|
|
15
|
+
import type { MiddlewareParams, TracingMiddlewareOptions } from './types.js';
|
|
16
|
+
/**
|
|
17
|
+
* tRPC middleware factory for distributed tracing.
|
|
18
|
+
*
|
|
19
|
+
* Creates a span for each tRPC procedure call with:
|
|
20
|
+
* - Procedure path as span name
|
|
21
|
+
* - Input/output logging (configurable)
|
|
22
|
+
* - Session and client context attributes
|
|
23
|
+
* - Error tracking
|
|
24
|
+
* - Duration measurement
|
|
25
|
+
*
|
|
26
|
+
* @param options.collectInput - Log procedure input (default: false)
|
|
27
|
+
* @param options.collectResult - Log procedure result (default: false)
|
|
28
|
+
* @returns A tRPC-compatible middleware function
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* ```typescript
|
|
32
|
+
* import { tracingMiddleware } from '@tummycrypt/tinyland-tracing-middleware';
|
|
33
|
+
*
|
|
34
|
+
* export const publicProcedure = t.procedure.use(tracingMiddleware({
|
|
35
|
+
* collectInput: true,
|
|
36
|
+
* collectResult: true,
|
|
37
|
+
* }));
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
export declare function tracingMiddleware(options?: TracingMiddlewareOptions): (params: MiddlewareParams) => Promise<unknown>;
|
|
41
|
+
/**
|
|
42
|
+
* Simplified tracing middleware (no input/output collection).
|
|
43
|
+
*
|
|
44
|
+
* Use this for high-traffic procedures where input/output logging
|
|
45
|
+
* would generate too much data.
|
|
46
|
+
*/
|
|
47
|
+
export declare const tracingMiddlewareSimple: (params: MiddlewareParams) => Promise<unknown>;
|
|
48
|
+
/**
|
|
49
|
+
* Full tracing middleware (with input/output collection).
|
|
50
|
+
*
|
|
51
|
+
* Use this for debugging or low-traffic procedures.
|
|
52
|
+
*/
|
|
53
|
+
export declare const tracingMiddlewareFull: (params: MiddlewareParams) => Promise<unknown>;
|
|
54
|
+
//# sourceMappingURL=middleware.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"middleware.d.ts","sourceRoot":"","sources":["../src/middleware.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAGH,OAAO,KAAK,EACV,gBAAgB,EAChB,wBAAwB,EACzB,MAAM,YAAY,CAAC;AAEpB;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAgB,iBAAiB,CAC/B,OAAO,GAAE,wBAA6B,GACrC,CAAC,MAAM,EAAE,gBAAgB,KAAK,OAAO,CAAC,OAAO,CAAC,CA0EhD;AAED;;;;;GAKG;AACH,eAAO,MAAM,uBAAuB,WAlFxB,gBAAgB,KAAK,OAAO,CAAC,OAAO,CAqF9C,CAAC;AAEH;;;;GAIG;AACH,eAAO,MAAM,qBAAqB,WA5FtB,gBAAgB,KAAK,OAAO,CAAC,OAAO,CA+F9C,CAAC"}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* tRPC OpenTelemetry Tracing Middleware
|
|
3
|
+
*
|
|
4
|
+
* Adds distributed tracing to all tRPC procedures via dependency injection.
|
|
5
|
+
* Replaces the broken @baselime/trpc-opentelemetry-middleware
|
|
6
|
+
* which uses CommonJS-only dependencies.
|
|
7
|
+
*
|
|
8
|
+
* Architecture:
|
|
9
|
+
* - ESM-compatible, zero runtime dependencies
|
|
10
|
+
* - Tracing injected via configure() at startup
|
|
11
|
+
* - Manual span creation (no auto-instrumentation)
|
|
12
|
+
*
|
|
13
|
+
* @module middleware
|
|
14
|
+
*/
|
|
15
|
+
import { getConfig } from './config.js';
|
|
16
|
+
/**
|
|
17
|
+
* tRPC middleware factory for distributed tracing.
|
|
18
|
+
*
|
|
19
|
+
* Creates a span for each tRPC procedure call with:
|
|
20
|
+
* - Procedure path as span name
|
|
21
|
+
* - Input/output logging (configurable)
|
|
22
|
+
* - Session and client context attributes
|
|
23
|
+
* - Error tracking
|
|
24
|
+
* - Duration measurement
|
|
25
|
+
*
|
|
26
|
+
* @param options.collectInput - Log procedure input (default: false)
|
|
27
|
+
* @param options.collectResult - Log procedure result (default: false)
|
|
28
|
+
* @returns A tRPC-compatible middleware function
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* ```typescript
|
|
32
|
+
* import { tracingMiddleware } from '@tummycrypt/tinyland-tracing-middleware';
|
|
33
|
+
*
|
|
34
|
+
* export const publicProcedure = t.procedure.use(tracingMiddleware({
|
|
35
|
+
* collectInput: true,
|
|
36
|
+
* collectResult: true,
|
|
37
|
+
* }));
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
export function tracingMiddleware(options = {}) {
|
|
41
|
+
return async ({ ctx, next, path, type, rawInput, }) => {
|
|
42
|
+
const { createSpan, SpanKind } = getConfig();
|
|
43
|
+
const spanName = `trpc.${path}`;
|
|
44
|
+
return createSpan(spanName, async (span) => {
|
|
45
|
+
// Add procedure metadata
|
|
46
|
+
span.setAttribute('trpc.procedure', path);
|
|
47
|
+
span.setAttribute('trpc.type', type);
|
|
48
|
+
// Add session context if available
|
|
49
|
+
if (ctx.session) {
|
|
50
|
+
if (ctx.session.id) {
|
|
51
|
+
span.setAttribute('session.id', ctx.session.id);
|
|
52
|
+
}
|
|
53
|
+
if (ctx.session.userId) {
|
|
54
|
+
span.setAttribute('user.id', ctx.session.userId);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
// Add client context
|
|
58
|
+
if (ctx.client) {
|
|
59
|
+
span.setAttribute('client.ip_hash', ctx.client.ipHash);
|
|
60
|
+
span.setAttribute('client.device_type', ctx.client.deviceType);
|
|
61
|
+
if (ctx.client.browser) {
|
|
62
|
+
span.setAttribute('client.browser', ctx.client.browser.name);
|
|
63
|
+
span.setAttribute('client.os', ctx.client.browser.os);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
// Collect input (optional, can be large)
|
|
67
|
+
if (options.collectInput && rawInput) {
|
|
68
|
+
try {
|
|
69
|
+
const inputStr = JSON.stringify(rawInput);
|
|
70
|
+
if (inputStr.length < 1000) {
|
|
71
|
+
span.setAttribute('trpc.input', inputStr);
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
span.setAttribute('trpc.input_size', inputStr.length);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
catch {
|
|
78
|
+
span.setAttribute('trpc.input', '[unserializable]');
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
// Execute procedure
|
|
82
|
+
const result = await next();
|
|
83
|
+
// Collect result (optional, can be large)
|
|
84
|
+
if (options.collectResult && result) {
|
|
85
|
+
try {
|
|
86
|
+
const resultStr = JSON.stringify(result);
|
|
87
|
+
if (resultStr.length < 1000) {
|
|
88
|
+
span.setAttribute('trpc.result', resultStr);
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
span.setAttribute('trpc.result_size', resultStr.length);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
catch {
|
|
95
|
+
span.setAttribute('trpc.result', '[unserializable]');
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
return result;
|
|
99
|
+
}, { kind: SpanKind.SERVER });
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Simplified tracing middleware (no input/output collection).
|
|
104
|
+
*
|
|
105
|
+
* Use this for high-traffic procedures where input/output logging
|
|
106
|
+
* would generate too much data.
|
|
107
|
+
*/
|
|
108
|
+
export const tracingMiddlewareSimple = tracingMiddleware({
|
|
109
|
+
collectInput: false,
|
|
110
|
+
collectResult: false,
|
|
111
|
+
});
|
|
112
|
+
/**
|
|
113
|
+
* Full tracing middleware (with input/output collection).
|
|
114
|
+
*
|
|
115
|
+
* Use this for debugging or low-traffic procedures.
|
|
116
|
+
*/
|
|
117
|
+
export const tracingMiddlewareFull = tracingMiddleware({
|
|
118
|
+
collectInput: true,
|
|
119
|
+
collectResult: true,
|
|
120
|
+
});
|
|
121
|
+
//# sourceMappingURL=middleware.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"middleware.js","sourceRoot":"","sources":["../src/middleware.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAMxC;;;;;;;;;;;;;;;;;;;;;;;GAuB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AChB,CAAC,EACD,EAAE,IAAI,EAAE,QAAQ,CAAC,MAAM,EAAE,CAC1B,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC;AAED;;;;;GAKG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAG,iBAAiB,CAAC;IACvD,YAAY,EAAE,KAAK;IACnB,aAAa,EAAE,KAAK;CACrB,CAAC,CAAC;AAEH;;;;GAIG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,iBAAiB,CAAC;IACrD,YAAY,EAAE,IAAI;IAClB,aAAa,EAAE,IAAI;CACpB,CAAC,CAAC"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type definitions for tinyland-tracing-middleware
|
|
3
|
+
*
|
|
4
|
+
* All external dependencies are expressed as interfaces for dependency injection.
|
|
5
|
+
* This package has zero runtime dependencies.
|
|
6
|
+
*
|
|
7
|
+
* @module types
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* Minimal span interface for setting attributes.
|
|
11
|
+
* Compatible with OpenTelemetry Span but decoupled via DI.
|
|
12
|
+
*/
|
|
13
|
+
export interface Span {
|
|
14
|
+
setAttribute(key: string, value: string | number | boolean): void;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Tracing context representing session and client information.
|
|
18
|
+
* Consumers provide their own context shape that satisfies this interface.
|
|
19
|
+
*/
|
|
20
|
+
export interface TracingContext {
|
|
21
|
+
session?: {
|
|
22
|
+
id: string | null;
|
|
23
|
+
userId?: string | null;
|
|
24
|
+
[key: string]: unknown;
|
|
25
|
+
};
|
|
26
|
+
client?: {
|
|
27
|
+
ipHash: string;
|
|
28
|
+
deviceType: string;
|
|
29
|
+
browser?: {
|
|
30
|
+
name: string;
|
|
31
|
+
os: string;
|
|
32
|
+
[key: string]: unknown;
|
|
33
|
+
};
|
|
34
|
+
[key: string]: unknown;
|
|
35
|
+
};
|
|
36
|
+
[key: string]: unknown;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Span kind enumeration. Mirrors OpenTelemetry SpanKind
|
|
40
|
+
* but injected to avoid direct dependency.
|
|
41
|
+
*/
|
|
42
|
+
export interface SpanKindEnum {
|
|
43
|
+
SERVER: number;
|
|
44
|
+
CLIENT: number;
|
|
45
|
+
[key: string]: number;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Configuration for the tracing middleware.
|
|
49
|
+
* Injected via configure() before first use.
|
|
50
|
+
*/
|
|
51
|
+
export interface TracingMiddlewareConfig {
|
|
52
|
+
/** Factory for creating traced spans */
|
|
53
|
+
createSpan: (name: string, fn: (span: Span) => Promise<unknown>, options?: {
|
|
54
|
+
kind?: number;
|
|
55
|
+
}) => Promise<unknown>;
|
|
56
|
+
/** Span kind enumeration */
|
|
57
|
+
SpanKind: SpanKindEnum;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Options for the tracingMiddleware factory function.
|
|
61
|
+
*/
|
|
62
|
+
export interface TracingMiddlewareOptions {
|
|
63
|
+
/** Log procedure input (default: false) */
|
|
64
|
+
collectInput?: boolean;
|
|
65
|
+
/** Log procedure result (default: false) */
|
|
66
|
+
collectResult?: boolean;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* The middleware function signature compatible with tRPC middleware.
|
|
70
|
+
*/
|
|
71
|
+
export interface MiddlewareParams {
|
|
72
|
+
ctx: TracingContext;
|
|
73
|
+
next: () => Promise<unknown>;
|
|
74
|
+
path: string;
|
|
75
|
+
type: string;
|
|
76
|
+
rawInput?: unknown;
|
|
77
|
+
}
|
|
78
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH;;;GAGG;AACH,MAAM,WAAW,IAAI;IACnB,YAAY,CAAC,GAAG,EAAE,MAAM,EAAE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;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,GAAG,EAAE,cAAc,CAAC;IACpB,IAAI,EAAE,MAAM,OAAO,CAAC,OAAO,CAAC,CAAC;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type definitions for tinyland-tracing-middleware
|
|
3
|
+
*
|
|
4
|
+
* All external dependencies are expressed as interfaces for dependency injection.
|
|
5
|
+
* This package has zero runtime dependencies.
|
|
6
|
+
*
|
|
7
|
+
* @module types
|
|
8
|
+
*/
|
|
9
|
+
export {};
|
|
10
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG"}
|
package/package.json
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@tummycrypt/tinyland-tracing-middleware",
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "tRPC OpenTelemetry tracing middleware with dependency injection for span creation and context",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"license": "Zlib AND LicenseRef-Tinyland-Proprietary",
|
|
7
|
+
"main": "./dist/index.js",
|
|
8
|
+
"module": "./dist/index.js",
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"exports": {
|
|
11
|
+
".": {
|
|
12
|
+
"types": "./dist/index.d.ts",
|
|
13
|
+
"import": "./dist/index.js"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"files": [
|
|
17
|
+
"dist",
|
|
18
|
+
"LICENSE"
|
|
19
|
+
],
|
|
20
|
+
"scripts": {
|
|
21
|
+
"build": "tsc",
|
|
22
|
+
"dev": "tsc --watch",
|
|
23
|
+
"clean": "rm -rf dist",
|
|
24
|
+
"test": "vitest run",
|
|
25
|
+
"test:watch": "vitest",
|
|
26
|
+
"typecheck": "tsc --noEmit",
|
|
27
|
+
"prepublishOnly": "npm run build"
|
|
28
|
+
},
|
|
29
|
+
"keywords": [
|
|
30
|
+
"trpc",
|
|
31
|
+
"opentelemetry",
|
|
32
|
+
"tracing",
|
|
33
|
+
"middleware",
|
|
34
|
+
"observability",
|
|
35
|
+
"spans"
|
|
36
|
+
],
|
|
37
|
+
"author": "Tinyland.dev",
|
|
38
|
+
"repository": {
|
|
39
|
+
"type": "git",
|
|
40
|
+
"url": "https://github.com/tinyland-inc/tinyland.dev",
|
|
41
|
+
"directory": "packages/tinyland-tracing-middleware"
|
|
42
|
+
},
|
|
43
|
+
"dependencies": {},
|
|
44
|
+
"devDependencies": {
|
|
45
|
+
"@types/node": "^22.0.0",
|
|
46
|
+
"typescript": "^5.0.0",
|
|
47
|
+
"vitest": "^4.0.0"
|
|
48
|
+
},
|
|
49
|
+
"engines": {
|
|
50
|
+
"node": ">=22.0.0"
|
|
51
|
+
},
|
|
52
|
+
"publishConfig": {
|
|
53
|
+
"registry": "https://registry.npmjs.org/",
|
|
54
|
+
"access": "public",
|
|
55
|
+
"provenance": true
|
|
56
|
+
}
|
|
57
|
+
}
|