@mark1russell7/otel-ts 0.8.0 → 0.8.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 +1 -1
- package/dist/context.d.ts +6 -3
- package/dist/context.d.ts.map +1 -1
- package/dist/context.js +10 -4
- package/dist/context.js.map +1 -1
- package/package.json +1 -1
- package/src/context.ts +11 -5
package/README.md
CHANGED
|
@@ -232,7 +232,7 @@ The rules:
|
|
|
232
232
|
- `withInternalCall(fn)` marks the calls that `fn` starts as internal calls. `isInternalCall()` reads the mark.
|
|
233
233
|
- `incomingContext(headers, { trust })` gives the context of an incoming call, for its handler. It reads the headers of `node:http` or the `Headers` of a Fetch `Request`, from the root context. Start the handler in it: `context.with(incomingContext(req.headers, { trust }), handler)`. The option `trust` tells how much of the context of the caller stays:
|
|
234
234
|
- `"all"`: the trace and the baggage, for a caller that passed its check.
|
|
235
|
-
- `"trace"` (the default): the trace only. The baggage of the caller goes.
|
|
235
|
+
- `"trace"` (the default): the trace only. The baggage of the caller goes, and each key that a propagator of the program read from the headers goes too.
|
|
236
236
|
- `"none"`: nothing. The call starts a new trace, for a public edge.
|
|
237
237
|
|
|
238
238
|
In the browser, `init()` registers the context when `tracing` is on (the default):
|
package/dist/context.d.ts
CHANGED
|
@@ -94,7 +94,8 @@ export type IncomingHeaders = IncomingHeaderRecord | Headers;
|
|
|
94
94
|
/**
|
|
95
95
|
* How much of the context of a caller a server keeps:
|
|
96
96
|
* - "all": the trace and the baggage, for a caller that passed its check.
|
|
97
|
-
* - "trace": the trace only
|
|
97
|
+
* - "trace": the trace only, that is the span context of the caller (its trace id, span id, flags and trace state).
|
|
98
|
+
* Each other value that the propagator reads goes: the baggage, and each key of a propagator of the program.
|
|
98
99
|
* - "none": nothing. The call starts a new trace from the root context, for a public edge.
|
|
99
100
|
* The W3C trace context lets a server restart the trace of a caller that it does not trust.
|
|
100
101
|
*/
|
|
@@ -108,8 +109,10 @@ export interface IncomingContextOptions {
|
|
|
108
109
|
* The context of an incoming call, for its handler (docs/CONTEXT-DESIGN.md, section 5). The propagator that
|
|
109
110
|
* the program registers reads the trace context and the baggage from the headers. The read starts from the
|
|
110
111
|
* root context, thus the call gets no value of the context that runs the server. The option `trust` tells
|
|
111
|
-
* how much of the context of the caller stays: "all", "trace" (the default) or "none".
|
|
112
|
-
*
|
|
112
|
+
* how much of the context of the caller stays: "all", "trace" (the default) or "none". With "trace", the result
|
|
113
|
+
* holds only the span context that the propagator read. A propagator of the program that reads the baggage
|
|
114
|
+
* header, or another header, into a key of its own thus gives that key to a trusted call only. Without a
|
|
115
|
+
* registered propagator, the result is the root context.
|
|
113
116
|
*/
|
|
114
117
|
export declare function incomingContext(headers: IncomingHeaders, options?: IncomingContextOptions): Context;
|
|
115
118
|
//# sourceMappingURL=context.d.ts.map
|
package/dist/context.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../src/context.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AACH,OAAO,
|
|
1
|
+
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../src/context.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AACH,OAAO,EAA+D,KAAK,OAAO,EAAsB,MAAM,oBAAoB,CAAC;AAEnI,iGAAiG;AACjG,MAAM,MAAM,qBAAqB,GAAG,KAAK,GAAG,MAAM,CAAC;AAEnD,yGAAyG;AACzG,MAAM,MAAM,qBAAqB,GAAG,UAAU,GAAG,MAAM,CAAC;AAExD,mCAAmC;AACnC,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,WAAW,EAAE,qBAAqB,CAAC;IAC5C,QAAQ,CAAC,SAAS,EAAE,qBAAqB,CAAC;IAC1C,6DAA6D;IAC7D,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;CAC7B;AAED,wDAAwD;AACxD,MAAM,WAAW,cAAc;IA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AAE,MAAM,CAAC,GAAG,CAAC,CAEpE;AAED,uFAAuF;AACvF,wBAAgB,WAAW,CAAC,MAAM,EAAE,aAAa,EAAE,IAAI,GAAE,OAA0B,GAAG,OAAO,CAkB5F;AAMD,iFAAiF;AACjF,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,GAAE,OAA0B,GAAG,MAAM,GAAG,SAAS,CAI9F;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,IAAI,GAAE,OAA0B,GAAG,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAQhG;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,CAAC,EAAE,EAAE,EAAE,MAAM,CAAC,GAAG,CAAC,CAElD;AAED,qEAAqE;AACrE,wBAAgB,cAAc,CAAC,IAAI,GAAE,OAA0B,GAAG,OAAO,CAExE;AAED,qGAAqG;AACrG,MAAM,MAAM,oBAAoB,GAAG,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,MAAM,EAAE,GAAG,SAAS,CAAC,CAAC,CAAC;AAEpG,uGAAuG;AACvG,MAAM,MAAM,eAAe,GAAG,oBAAoB,GAAG,OAAO,CAAC;AAE7D;;;;;;;GAOG;AACH,MAAM,MAAM,aAAa,GAAG,KAAK,GAAG,OAAO,GAAG,MAAM,CAAC;AAErD,uCAAuC;AACvC,MAAM,WAAW,sBAAsB;IACrC,qFAAqF;IACrF,QAAQ,CAAC,KAAK,CAAC,EAAE,aAAa,CAAC;CAChC;AAoBD;;;;;;;;GAQG;AACH,wBAAgB,eAAe,CAAC,OAAO,EAAE,eAAe,EAAE,OAAO,GAAE,sBAA2B,GAAG,OAAO,CAavG"}
|
package/dist/context.js
CHANGED
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
*
|
|
17
17
|
* @packageDocumentation
|
|
18
18
|
*/
|
|
19
|
-
import { context, createContextKey, propagation, ROOT_CONTEXT } from "@opentelemetry/api";
|
|
19
|
+
import { context, createContextKey, propagation, ROOT_CONTEXT, trace } from "@opentelemetry/api";
|
|
20
20
|
/** The default of `maxLength` */
|
|
21
21
|
export const DEFAULT_MAX_LENGTH = 256;
|
|
22
22
|
/*
|
|
@@ -185,8 +185,10 @@ const isFetchHeaders = (headers) => typeof headers.get === "function";
|
|
|
185
185
|
* The context of an incoming call, for its handler (docs/CONTEXT-DESIGN.md, section 5). The propagator that
|
|
186
186
|
* the program registers reads the trace context and the baggage from the headers. The read starts from the
|
|
187
187
|
* root context, thus the call gets no value of the context that runs the server. The option `trust` tells
|
|
188
|
-
* how much of the context of the caller stays: "all", "trace" (the default) or "none".
|
|
189
|
-
*
|
|
188
|
+
* how much of the context of the caller stays: "all", "trace" (the default) or "none". With "trace", the result
|
|
189
|
+
* holds only the span context that the propagator read. A propagator of the program that reads the baggage
|
|
190
|
+
* header, or another header, into a key of its own thus gives that key to a trusted call only. Without a
|
|
191
|
+
* registered propagator, the result is the root context.
|
|
190
192
|
*/
|
|
191
193
|
export function incomingContext(headers, options = {}) {
|
|
192
194
|
const trust = options.trust ?? "trace";
|
|
@@ -198,6 +200,10 @@ export function incomingContext(headers, options = {}) {
|
|
|
198
200
|
const read = isFetchHeaders(headers)
|
|
199
201
|
? propagation.extract(ROOT_CONTEXT, headers, fetchGetter)
|
|
200
202
|
: propagation.extract(ROOT_CONTEXT, headers, recordGetter);
|
|
201
|
-
|
|
203
|
+
if (trust === "all")
|
|
204
|
+
return read;
|
|
205
|
+
// Only the span context stays. Before, only the W3C baggage went, and each other key of the propagator stayed.
|
|
206
|
+
const span = trace.getSpanContext(read);
|
|
207
|
+
return span === undefined ? ROOT_CONTEXT : trace.setSpanContext(ROOT_CONTEXT, span);
|
|
202
208
|
}
|
|
203
209
|
//# sourceMappingURL=context.js.map
|
package/dist/context.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context.js","sourceRoot":"","sources":["../src/context.ts"],"names":[],"mappings":"AA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AkC,EAAE;IAC5F,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,IAAI,OAAO,CAAC;IACvC,IAAI,KAAK,KAAK,KAAK,IAAI,KAAK,KAAK,OAAO,IAAI,KAAK,KAAK,MAAM,EAAE,CAAC;QAC7D,MAAM,IAAI,SAAS,CAAC,cAAc,MAAM,CAAC,KAAK,CAAC,mCAAmC,CAAC,CAAC;IACtF,CAAC;IACD,IAAI,KAAK,KAAK,MAAM;QAAE,OAAO,YAAY,CAAC;IAC1C,MAAM,IAAI,GAAG,cAAc,CAAC,OAAO,CAAC;QAClC,CAAC,CAAC,WAAW,CAAC,OAAO,CAAC,YAAY,EAAE,OAAO,EAAE,WAAW,CAAC;QACzD,CAAC,CAAC,WAAW,CAAC,OAAO,CAAC,YAAY,EAAE,OAAO,EAAE,YAAY,CAAC,CAAC;IAC7D,IAAI,KAAK,KAAK,KAAK;QAAE,OAAO,IAAI,CAAC;IACjC,+GAA+G;IAC/G,MAAM,IAAI,GAAG,KAAK,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC;IACxC,OAAO,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,KAAK,CAAC,cAAc,CAAC,YAAY,EAAE,IAAI,CAAC,CAAC;AACtF,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://json.schemastore.org/package",
|
|
3
3
|
"name": "@mark1russell7/otel-ts",
|
|
4
|
-
"version": "0.8.
|
|
4
|
+
"version": "0.8.1",
|
|
5
5
|
"description": "Frontend observability in one init() call — OpenTelemetry + Grafana Faro for any TypeScript web app",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"author": "Mark Russell (https://github.com/mark1russell7)",
|
package/src/context.ts
CHANGED
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
*
|
|
17
17
|
* @packageDocumentation
|
|
18
18
|
*/
|
|
19
|
-
import { context, createContextKey, propagation, ROOT_CONTEXT, type Context, type TextMapGetter } from "@opentelemetry/api";
|
|
19
|
+
import { context, createContextKey, propagation, ROOT_CONTEXT, trace, type Context, type TextMapGetter } from "@opentelemetry/api";
|
|
20
20
|
|
|
21
21
|
/** How many distinct values a key has: "low" may become a metric attribute, "high" never does */
|
|
22
22
|
export type ContextKeyCardinality = "low" | "high";
|
|
@@ -215,7 +215,8 @@ export type IncomingHeaders = IncomingHeaderRecord | Headers;
|
|
|
215
215
|
/**
|
|
216
216
|
* How much of the context of a caller a server keeps:
|
|
217
217
|
* - "all": the trace and the baggage, for a caller that passed its check.
|
|
218
|
-
* - "trace": the trace only
|
|
218
|
+
* - "trace": the trace only, that is the span context of the caller (its trace id, span id, flags and trace state).
|
|
219
|
+
* Each other value that the propagator reads goes: the baggage, and each key of a propagator of the program.
|
|
219
220
|
* - "none": nothing. The call starts a new trace from the root context, for a public edge.
|
|
220
221
|
* The W3C trace context lets a server restart the trace of a caller that it does not trust.
|
|
221
222
|
*/
|
|
@@ -249,8 +250,10 @@ const isFetchHeaders = (headers: IncomingHeaders): headers is Headers => typeof
|
|
|
249
250
|
* The context of an incoming call, for its handler (docs/CONTEXT-DESIGN.md, section 5). The propagator that
|
|
250
251
|
* the program registers reads the trace context and the baggage from the headers. The read starts from the
|
|
251
252
|
* root context, thus the call gets no value of the context that runs the server. The option `trust` tells
|
|
252
|
-
* how much of the context of the caller stays: "all", "trace" (the default) or "none".
|
|
253
|
-
*
|
|
253
|
+
* how much of the context of the caller stays: "all", "trace" (the default) or "none". With "trace", the result
|
|
254
|
+
* holds only the span context that the propagator read. A propagator of the program that reads the baggage
|
|
255
|
+
* header, or another header, into a key of its own thus gives that key to a trusted call only. Without a
|
|
256
|
+
* registered propagator, the result is the root context.
|
|
254
257
|
*/
|
|
255
258
|
export function incomingContext(headers: IncomingHeaders, options: IncomingContextOptions = {}): Context {
|
|
256
259
|
const trust = options.trust ?? "trace";
|
|
@@ -261,5 +264,8 @@ export function incomingContext(headers: IncomingHeaders, options: IncomingConte
|
|
|
261
264
|
const read = isFetchHeaders(headers)
|
|
262
265
|
? propagation.extract(ROOT_CONTEXT, headers, fetchGetter)
|
|
263
266
|
: propagation.extract(ROOT_CONTEXT, headers, recordGetter);
|
|
264
|
-
|
|
267
|
+
if (trust === "all") return read;
|
|
268
|
+
// Only the span context stays. Before, only the W3C baggage went, and each other key of the propagator stayed.
|
|
269
|
+
const span = trace.getSpanContext(read);
|
|
270
|
+
return span === undefined ? ROOT_CONTEXT : trace.setSpanContext(ROOT_CONTEXT, span);
|
|
265
271
|
}
|