@lp-labs/trace-context 0.0.0-stage → 0.1.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/LICENSE +21 -0
- package/README.md +93 -2
- package/dist/cjs/index.d.ts +39 -0
- package/dist/cjs/index.js +108 -0
- package/dist/cjs/package.json +1 -0
- package/dist/esm/index.d.ts +39 -0
- package/dist/esm/index.js +103 -0
- package/package.json +61 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Libin Prasanth
|
|
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
CHANGED
|
@@ -1,3 +1,94 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @lp-labs/trace-context
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Bounded trace identifiers and span lifetimes with an injected context adapter. Independent,
|
|
4
|
+
zero runtime/peer dependencies, MIT, Node >=18; ESM and CommonJS with strict declarations.
|
|
5
|
+
|
|
6
|
+
## Install and quickstart
|
|
7
|
+
|
|
8
|
+
```sh
|
|
9
|
+
npm install @lp-labs/trace-context
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
```js
|
|
13
|
+
import { webcrypto } from 'node:crypto';
|
|
14
|
+
import { createTracer, parseTraceparent, formatTraceparent } from '@lp-labs/trace-context';
|
|
15
|
+
|
|
16
|
+
let current;
|
|
17
|
+
let time = 0;
|
|
18
|
+
const tracer = createTracer({
|
|
19
|
+
randomFill: (bytes) => webcrypto.getRandomValues(bytes),
|
|
20
|
+
clock: () => time++,
|
|
21
|
+
adapter: {
|
|
22
|
+
get: () => current,
|
|
23
|
+
run(context, work) {
|
|
24
|
+
const previous = current;
|
|
25
|
+
current = context;
|
|
26
|
+
try {
|
|
27
|
+
return work();
|
|
28
|
+
} finally {
|
|
29
|
+
current = previous;
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
});
|
|
34
|
+
const parent = parseTraceparent('00-1234567890abcdef1234567890abcdef-1234567890abcdef-01');
|
|
35
|
+
const span = tracer.start('订单', parent);
|
|
36
|
+
tracer.run(span, () => console.log(formatTraceparent(tracer.current())));
|
|
37
|
+
console.log(span.end().durationMs);
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
CommonJS: `const { createTracer } = require('@lp-labs/trace-context')`.
|
|
41
|
+
|
|
42
|
+
## API and types
|
|
43
|
+
|
|
44
|
+
- `parseTraceparent(header: string): TraceContext` accepts **only** the 55-character W3C
|
|
45
|
+
version-00 subset: lowercase hexadecimal, nonzero 32-digit trace ID, nonzero 16-digit
|
|
46
|
+
span ID, flags `00` or `01`. Whitespace, future versions, additional fields and other
|
|
47
|
+
flag bits are rejected. No tracestate or baggage implementation.
|
|
48
|
+
- `formatTraceparent(context: TraceContext): string` validates and serializes that subset.
|
|
49
|
+
- `TraceContext`: readonly `traceId: string`, `spanId: string`, `sampled: boolean`.
|
|
50
|
+
- `createTracer(options: TracerOptions): Tracer`: requires `adapter: ContextAdapter`;
|
|
51
|
+
optional `clock: () => number` defaults to `performance.now()`, optional
|
|
52
|
+
`randomFill: (bytes: Uint8Array) => void` defaults to platform `crypto.getRandomValues`.
|
|
53
|
+
- `ContextAdapter`: `get(): TraceContext | undefined`, generic
|
|
54
|
+
`run<T>(context: TraceContext, work: () => T): T`. Supply your own async-local adapter
|
|
55
|
+
if needed. The quickstart adapter is **synchronous only**; the package does not
|
|
56
|
+
guarantee async propagation or implicitly end spans.
|
|
57
|
+
- `Tracer.current()` returns an immutable validated snapshot or undefined.
|
|
58
|
+
`start(name: string, parent?: TraceContext): Span` inherits current context by default,
|
|
59
|
+
retains trace ID/sampling and generates a child span ID. Root spans are unsampled.
|
|
60
|
+
Names accept 1–256 UTF-16 units, Unicode preserved exactly.
|
|
61
|
+
`run<T>(span: Span, work: () => T): T` delegates to the adapter.
|
|
62
|
+
- `Span`: readonly `name`, `context`, `parentSpanId: string | undefined`, `startedAt: number`;
|
|
63
|
+
`end(): SpanResult` caches the first successful immutable result.
|
|
64
|
+
- `SpanResult`: the same fields plus `endedAt: number`, `durationMs: number`.
|
|
65
|
+
Clock values must be finite and end cannot precede start.
|
|
66
|
+
|
|
67
|
+
## Errors, customization and limits
|
|
68
|
+
|
|
69
|
+
Invalid contexts, callbacks, adapters, names or clocks throw `TypeError`; backwards clocks
|
|
70
|
+
and duration overflow throw `RangeError`. Missing secure platform randomness or an all-zero
|
|
71
|
+
generated ID throws `Error`. Injected adapter, clock and random-source exceptions propagate;
|
|
72
|
+
do not put sensitive data in their errors. Invalid span end attempts may be retried.
|
|
73
|
+
|
|
74
|
+
Custom random fillers **must fill every byte cryptographically securely**. No `Math.random`
|
|
75
|
+
fallback, retries or uniqueness guarantee. Node runtimes without global crypto should inject
|
|
76
|
+
`node:crypto` as shown. No exporter, network calls, sampling engine, active span registry or
|
|
77
|
+
background tasks. Per-span storage is constant; callers own span/context retention.
|
|
78
|
+
Identifiers and names can be linkable: never encode personal data, secrets or baggage.
|
|
79
|
+
Only identifiers propagate; this is not a privacy filter or complete W3C implementation.
|
|
80
|
+
|
|
81
|
+
## Development
|
|
82
|
+
|
|
83
|
+
`npm ci --offline`, `npm run build`, `npm run typecheck`, `npm test`,
|
|
84
|
+
`npm run format`, `npm run format:check`. `npm run prepack` rebuilds.
|
|
85
|
+
TypeScript ^5.9.3 and Prettier ^3.6.2 are development-only. Dual output is in `dist/esm`
|
|
86
|
+
and `dist/cjs`; both bare-import `.mts`/`.cts` consumers are checked.
|
|
87
|
+
|
|
88
|
+
## Support
|
|
89
|
+
|
|
90
|
+
If this library is useful to you, consider supporting its maintenance with a [donation via PayPal](https://www.paypal.me/LibinPrasanth).
|
|
91
|
+
|
|
92
|
+
## Author
|
|
93
|
+
|
|
94
|
+
Created by [Libin Prasanth](https://www.linkedin.com/in/libinprasanth/). Connect on LinkedIn for updates and discussion.
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
export interface TraceContext {
|
|
2
|
+
readonly traceId: string;
|
|
3
|
+
readonly spanId: string;
|
|
4
|
+
readonly sampled: boolean;
|
|
5
|
+
}
|
|
6
|
+
export interface ContextAdapter {
|
|
7
|
+
get(): TraceContext | undefined;
|
|
8
|
+
run<T>(context: TraceContext, work: () => T): T;
|
|
9
|
+
}
|
|
10
|
+
export interface Span {
|
|
11
|
+
readonly name: string;
|
|
12
|
+
readonly context: TraceContext;
|
|
13
|
+
readonly parentSpanId: string | undefined;
|
|
14
|
+
readonly startedAt: number;
|
|
15
|
+
end(): SpanResult;
|
|
16
|
+
}
|
|
17
|
+
export interface SpanResult {
|
|
18
|
+
readonly name: string;
|
|
19
|
+
readonly context: TraceContext;
|
|
20
|
+
readonly parentSpanId: string | undefined;
|
|
21
|
+
readonly startedAt: number;
|
|
22
|
+
readonly endedAt: number;
|
|
23
|
+
readonly durationMs: number;
|
|
24
|
+
}
|
|
25
|
+
export interface TracerOptions {
|
|
26
|
+
readonly adapter: ContextAdapter;
|
|
27
|
+
readonly clock?: () => number;
|
|
28
|
+
/** Must fill every byte with cryptographically secure randomness. */
|
|
29
|
+
readonly randomFill?: (bytes: Uint8Array) => void;
|
|
30
|
+
}
|
|
31
|
+
export interface Tracer {
|
|
32
|
+
current(): TraceContext | undefined;
|
|
33
|
+
start(name: string, parent?: TraceContext): Span;
|
|
34
|
+
run<T>(span: Span, work: () => T): T;
|
|
35
|
+
}
|
|
36
|
+
/** Only version 00, lowercase hex, and flags 00/01 are supported. */
|
|
37
|
+
export declare function parseTraceparent(header: string): TraceContext;
|
|
38
|
+
export declare function formatTraceparent(value: TraceContext): string;
|
|
39
|
+
export declare function createTracer(options: TracerOptions): Tracer;
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parseTraceparent = parseTraceparent;
|
|
4
|
+
exports.formatTraceparent = formatTraceparent;
|
|
5
|
+
exports.createTracer = createTracer;
|
|
6
|
+
function context(value) {
|
|
7
|
+
if (!value ||
|
|
8
|
+
typeof value.traceId !== 'string' ||
|
|
9
|
+
typeof value.spanId !== 'string' ||
|
|
10
|
+
!/^[0-9a-f]{32}$/.test(value.traceId) ||
|
|
11
|
+
/^0+$/.test(value.traceId) ||
|
|
12
|
+
!/^[0-9a-f]{16}$/.test(value.spanId) ||
|
|
13
|
+
/^0+$/.test(value.spanId) ||
|
|
14
|
+
typeof value.sampled !== 'boolean')
|
|
15
|
+
throw new TypeError('Invalid trace context.');
|
|
16
|
+
return Object.freeze({ traceId: value.traceId, spanId: value.spanId, sampled: value.sampled });
|
|
17
|
+
}
|
|
18
|
+
/** Only version 00, lowercase hex, and flags 00/01 are supported. */
|
|
19
|
+
function parseTraceparent(header) {
|
|
20
|
+
if (typeof header !== 'string' || !/^00-[0-9a-f]{32}-[0-9a-f]{16}-0[01]$/.test(header))
|
|
21
|
+
throw new TypeError('Unsupported or invalid traceparent.');
|
|
22
|
+
return context({
|
|
23
|
+
traceId: header.slice(3, 35),
|
|
24
|
+
spanId: header.slice(36, 52),
|
|
25
|
+
sampled: header.slice(53) === '01',
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
function formatTraceparent(value) {
|
|
29
|
+
const validated = context(value);
|
|
30
|
+
return `00-${validated.traceId}-${validated.spanId}-${validated.sampled ? '01' : '00'}`;
|
|
31
|
+
}
|
|
32
|
+
function createTracer(options) {
|
|
33
|
+
if (!options ||
|
|
34
|
+
typeof options.adapter?.get !== 'function' ||
|
|
35
|
+
typeof options.adapter.run !== 'function')
|
|
36
|
+
throw new TypeError('A context adapter is required.');
|
|
37
|
+
if (options.clock !== undefined && typeof options.clock !== 'function')
|
|
38
|
+
throw new TypeError('Invalid clock.');
|
|
39
|
+
if (options.randomFill !== undefined && typeof options.randomFill !== 'function')
|
|
40
|
+
throw new TypeError('Invalid random source.');
|
|
41
|
+
const adapter = options.adapter;
|
|
42
|
+
const clock = options.clock ?? (() => performance.now());
|
|
43
|
+
const fill = options.randomFill ??
|
|
44
|
+
((bytes) => {
|
|
45
|
+
if (!globalThis.crypto?.getRandomValues)
|
|
46
|
+
throw new Error('Secure randomness is unavailable.');
|
|
47
|
+
globalThis.crypto.getRandomValues(bytes);
|
|
48
|
+
});
|
|
49
|
+
const now = () => {
|
|
50
|
+
const value = clock();
|
|
51
|
+
if (typeof value !== 'number' || !Number.isFinite(value))
|
|
52
|
+
throw new TypeError('Clock must return a finite number.');
|
|
53
|
+
return value;
|
|
54
|
+
};
|
|
55
|
+
const id = (length) => {
|
|
56
|
+
const bytes = new Uint8Array(length);
|
|
57
|
+
fill(bytes);
|
|
58
|
+
if (bytes.every((byte) => byte === 0))
|
|
59
|
+
throw new Error('Random source produced an all-zero ID.');
|
|
60
|
+
return Array.from(bytes, (byte) => byte.toString(16).padStart(2, '0')).join('');
|
|
61
|
+
};
|
|
62
|
+
const current = () => {
|
|
63
|
+
const value = adapter.get();
|
|
64
|
+
return value === undefined ? undefined : context(value);
|
|
65
|
+
};
|
|
66
|
+
return {
|
|
67
|
+
current,
|
|
68
|
+
start(name, parent = current()) {
|
|
69
|
+
if (typeof name !== 'string' || name.length === 0 || name.length > 256)
|
|
70
|
+
throw new TypeError('Span name must contain 1 to 256 UTF-16 units.');
|
|
71
|
+
const ancestor = parent === undefined ? undefined : context(parent);
|
|
72
|
+
const child = context({
|
|
73
|
+
traceId: ancestor?.traceId ?? id(16),
|
|
74
|
+
spanId: id(8),
|
|
75
|
+
sampled: ancestor?.sampled ?? false,
|
|
76
|
+
});
|
|
77
|
+
const startedAt = now();
|
|
78
|
+
let result;
|
|
79
|
+
return Object.freeze({
|
|
80
|
+
name,
|
|
81
|
+
context: child,
|
|
82
|
+
parentSpanId: ancestor?.spanId,
|
|
83
|
+
startedAt,
|
|
84
|
+
end() {
|
|
85
|
+
if (result)
|
|
86
|
+
return result;
|
|
87
|
+
const endedAt = now();
|
|
88
|
+
if (endedAt < startedAt || !Number.isFinite(endedAt - startedAt))
|
|
89
|
+
throw new RangeError('Clock moved backwards or duration overflowed.');
|
|
90
|
+
result = Object.freeze({
|
|
91
|
+
name,
|
|
92
|
+
context: child,
|
|
93
|
+
parentSpanId: ancestor?.spanId,
|
|
94
|
+
startedAt,
|
|
95
|
+
endedAt,
|
|
96
|
+
durationMs: endedAt - startedAt,
|
|
97
|
+
});
|
|
98
|
+
return result;
|
|
99
|
+
},
|
|
100
|
+
});
|
|
101
|
+
},
|
|
102
|
+
run(span, work) {
|
|
103
|
+
if (!span || typeof work !== 'function')
|
|
104
|
+
throw new TypeError('Span and callback are required.');
|
|
105
|
+
return adapter.run(context(span.context), work);
|
|
106
|
+
},
|
|
107
|
+
};
|
|
108
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type":"commonjs"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
export interface TraceContext {
|
|
2
|
+
readonly traceId: string;
|
|
3
|
+
readonly spanId: string;
|
|
4
|
+
readonly sampled: boolean;
|
|
5
|
+
}
|
|
6
|
+
export interface ContextAdapter {
|
|
7
|
+
get(): TraceContext | undefined;
|
|
8
|
+
run<T>(context: TraceContext, work: () => T): T;
|
|
9
|
+
}
|
|
10
|
+
export interface Span {
|
|
11
|
+
readonly name: string;
|
|
12
|
+
readonly context: TraceContext;
|
|
13
|
+
readonly parentSpanId: string | undefined;
|
|
14
|
+
readonly startedAt: number;
|
|
15
|
+
end(): SpanResult;
|
|
16
|
+
}
|
|
17
|
+
export interface SpanResult {
|
|
18
|
+
readonly name: string;
|
|
19
|
+
readonly context: TraceContext;
|
|
20
|
+
readonly parentSpanId: string | undefined;
|
|
21
|
+
readonly startedAt: number;
|
|
22
|
+
readonly endedAt: number;
|
|
23
|
+
readonly durationMs: number;
|
|
24
|
+
}
|
|
25
|
+
export interface TracerOptions {
|
|
26
|
+
readonly adapter: ContextAdapter;
|
|
27
|
+
readonly clock?: () => number;
|
|
28
|
+
/** Must fill every byte with cryptographically secure randomness. */
|
|
29
|
+
readonly randomFill?: (bytes: Uint8Array) => void;
|
|
30
|
+
}
|
|
31
|
+
export interface Tracer {
|
|
32
|
+
current(): TraceContext | undefined;
|
|
33
|
+
start(name: string, parent?: TraceContext): Span;
|
|
34
|
+
run<T>(span: Span, work: () => T): T;
|
|
35
|
+
}
|
|
36
|
+
/** Only version 00, lowercase hex, and flags 00/01 are supported. */
|
|
37
|
+
export declare function parseTraceparent(header: string): TraceContext;
|
|
38
|
+
export declare function formatTraceparent(value: TraceContext): string;
|
|
39
|
+
export declare function createTracer(options: TracerOptions): Tracer;
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
function context(value) {
|
|
2
|
+
if (!value ||
|
|
3
|
+
typeof value.traceId !== 'string' ||
|
|
4
|
+
typeof value.spanId !== 'string' ||
|
|
5
|
+
!/^[0-9a-f]{32}$/.test(value.traceId) ||
|
|
6
|
+
/^0+$/.test(value.traceId) ||
|
|
7
|
+
!/^[0-9a-f]{16}$/.test(value.spanId) ||
|
|
8
|
+
/^0+$/.test(value.spanId) ||
|
|
9
|
+
typeof value.sampled !== 'boolean')
|
|
10
|
+
throw new TypeError('Invalid trace context.');
|
|
11
|
+
return Object.freeze({ traceId: value.traceId, spanId: value.spanId, sampled: value.sampled });
|
|
12
|
+
}
|
|
13
|
+
/** Only version 00, lowercase hex, and flags 00/01 are supported. */
|
|
14
|
+
export function parseTraceparent(header) {
|
|
15
|
+
if (typeof header !== 'string' || !/^00-[0-9a-f]{32}-[0-9a-f]{16}-0[01]$/.test(header))
|
|
16
|
+
throw new TypeError('Unsupported or invalid traceparent.');
|
|
17
|
+
return context({
|
|
18
|
+
traceId: header.slice(3, 35),
|
|
19
|
+
spanId: header.slice(36, 52),
|
|
20
|
+
sampled: header.slice(53) === '01',
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
export function formatTraceparent(value) {
|
|
24
|
+
const validated = context(value);
|
|
25
|
+
return `00-${validated.traceId}-${validated.spanId}-${validated.sampled ? '01' : '00'}`;
|
|
26
|
+
}
|
|
27
|
+
export function createTracer(options) {
|
|
28
|
+
if (!options ||
|
|
29
|
+
typeof options.adapter?.get !== 'function' ||
|
|
30
|
+
typeof options.adapter.run !== 'function')
|
|
31
|
+
throw new TypeError('A context adapter is required.');
|
|
32
|
+
if (options.clock !== undefined && typeof options.clock !== 'function')
|
|
33
|
+
throw new TypeError('Invalid clock.');
|
|
34
|
+
if (options.randomFill !== undefined && typeof options.randomFill !== 'function')
|
|
35
|
+
throw new TypeError('Invalid random source.');
|
|
36
|
+
const adapter = options.adapter;
|
|
37
|
+
const clock = options.clock ?? (() => performance.now());
|
|
38
|
+
const fill = options.randomFill ??
|
|
39
|
+
((bytes) => {
|
|
40
|
+
if (!globalThis.crypto?.getRandomValues)
|
|
41
|
+
throw new Error('Secure randomness is unavailable.');
|
|
42
|
+
globalThis.crypto.getRandomValues(bytes);
|
|
43
|
+
});
|
|
44
|
+
const now = () => {
|
|
45
|
+
const value = clock();
|
|
46
|
+
if (typeof value !== 'number' || !Number.isFinite(value))
|
|
47
|
+
throw new TypeError('Clock must return a finite number.');
|
|
48
|
+
return value;
|
|
49
|
+
};
|
|
50
|
+
const id = (length) => {
|
|
51
|
+
const bytes = new Uint8Array(length);
|
|
52
|
+
fill(bytes);
|
|
53
|
+
if (bytes.every((byte) => byte === 0))
|
|
54
|
+
throw new Error('Random source produced an all-zero ID.');
|
|
55
|
+
return Array.from(bytes, (byte) => byte.toString(16).padStart(2, '0')).join('');
|
|
56
|
+
};
|
|
57
|
+
const current = () => {
|
|
58
|
+
const value = adapter.get();
|
|
59
|
+
return value === undefined ? undefined : context(value);
|
|
60
|
+
};
|
|
61
|
+
return {
|
|
62
|
+
current,
|
|
63
|
+
start(name, parent = current()) {
|
|
64
|
+
if (typeof name !== 'string' || name.length === 0 || name.length > 256)
|
|
65
|
+
throw new TypeError('Span name must contain 1 to 256 UTF-16 units.');
|
|
66
|
+
const ancestor = parent === undefined ? undefined : context(parent);
|
|
67
|
+
const child = context({
|
|
68
|
+
traceId: ancestor?.traceId ?? id(16),
|
|
69
|
+
spanId: id(8),
|
|
70
|
+
sampled: ancestor?.sampled ?? false,
|
|
71
|
+
});
|
|
72
|
+
const startedAt = now();
|
|
73
|
+
let result;
|
|
74
|
+
return Object.freeze({
|
|
75
|
+
name,
|
|
76
|
+
context: child,
|
|
77
|
+
parentSpanId: ancestor?.spanId,
|
|
78
|
+
startedAt,
|
|
79
|
+
end() {
|
|
80
|
+
if (result)
|
|
81
|
+
return result;
|
|
82
|
+
const endedAt = now();
|
|
83
|
+
if (endedAt < startedAt || !Number.isFinite(endedAt - startedAt))
|
|
84
|
+
throw new RangeError('Clock moved backwards or duration overflowed.');
|
|
85
|
+
result = Object.freeze({
|
|
86
|
+
name,
|
|
87
|
+
context: child,
|
|
88
|
+
parentSpanId: ancestor?.spanId,
|
|
89
|
+
startedAt,
|
|
90
|
+
endedAt,
|
|
91
|
+
durationMs: endedAt - startedAt,
|
|
92
|
+
});
|
|
93
|
+
return result;
|
|
94
|
+
},
|
|
95
|
+
});
|
|
96
|
+
},
|
|
97
|
+
run(span, work) {
|
|
98
|
+
if (!span || typeof work !== 'function')
|
|
99
|
+
throw new TypeError('Span and callback are required.');
|
|
100
|
+
return adapter.run(context(span.context), work);
|
|
101
|
+
},
|
|
102
|
+
};
|
|
103
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,63 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lp-labs/trace-context",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Bounded, explicit trace-context utilities with injected adapters and deterministic policies.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"main": "./dist/cjs/index.js",
|
|
8
|
+
"module": "./dist/esm/index.js",
|
|
9
|
+
"types": "./dist/esm/index.d.ts",
|
|
10
|
+
"exports": {
|
|
11
|
+
".": {
|
|
12
|
+
"import": {
|
|
13
|
+
"types": "./dist/esm/index.d.ts",
|
|
14
|
+
"default": "./dist/esm/index.js"
|
|
15
|
+
},
|
|
16
|
+
"require": {
|
|
17
|
+
"types": "./dist/cjs/index.d.ts",
|
|
18
|
+
"default": "./dist/cjs/index.js"
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
"./package.json": "./package.json"
|
|
22
|
+
},
|
|
23
|
+
"files": [
|
|
24
|
+
"dist",
|
|
25
|
+
"README.md",
|
|
26
|
+
"LICENSE"
|
|
27
|
+
],
|
|
28
|
+
"sideEffects": false,
|
|
29
|
+
"engines": {
|
|
30
|
+
"node": "\u003e=18"
|
|
31
|
+
},
|
|
32
|
+
"scripts": {
|
|
33
|
+
"build": "node scripts/build.mjs",
|
|
34
|
+
"typecheck": "npm run build \u0026\u0026 node scripts/check-types.mjs",
|
|
35
|
+
"test": "npm run build \u0026\u0026 node --test tests/*.test.mjs",
|
|
36
|
+
"format": "prettier --write src scripts tests *.json README.md",
|
|
37
|
+
"format:check": "prettier --check src scripts tests *.json README.md",
|
|
38
|
+
"prepack": "npm run build"
|
|
39
|
+
},
|
|
40
|
+
"devDependencies": {
|
|
41
|
+
"typescript": "^5.9.3",
|
|
42
|
+
"prettier": "^3.6.2"
|
|
43
|
+
},
|
|
44
|
+
"prettier": {
|
|
45
|
+
"singleQuote": true,
|
|
46
|
+
"semi": true,
|
|
47
|
+
"trailingComma": "all",
|
|
48
|
+
"printWidth": 100,
|
|
49
|
+
"endOfLine": "lf"
|
|
50
|
+
},
|
|
51
|
+
"publishConfig": {
|
|
52
|
+
"access": "public",
|
|
53
|
+
"registry": "https://registry.npmjs.org/"
|
|
54
|
+
},
|
|
55
|
+
"author": {
|
|
56
|
+
"name": "Libin Prasanth",
|
|
57
|
+
"url": "https://www.linkedin.com/in/libinprasanth/"
|
|
58
|
+
},
|
|
59
|
+
"funding": {
|
|
60
|
+
"type": "paypal",
|
|
61
|
+
"url": "https://www.paypal.me/LibinPrasanth"
|
|
62
|
+
}
|
|
63
|
+
}
|