@mark1russell7/otel-ts 0.10.4 → 0.10.5
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 +17 -1
- package/dist/node-export.d.ts +40 -0
- package/dist/node-export.d.ts.map +1 -0
- package/dist/node-export.js +13 -0
- package/dist/node-export.js.map +1 -0
- package/package.json +6 -1
- package/src/node-export.ts +46 -0
package/README.md
CHANGED
|
@@ -551,7 +551,23 @@ export const telemetry = startNodeContext({
|
|
|
551
551
|
- No span leaves the process. A test gives `spanProcessors` with the exporter of its capture.
|
|
552
552
|
- It adds no listener for a signal. Call `telemetry.shutdown()` in the last stage of the service.
|
|
553
553
|
|
|
554
|
-
`startNodeContext()` and `startNodeTelemetry()` refuse each other: only one part of a program registers the context.
|
|
554
|
+
`startNodeContext()` and `startNodeTelemetry()` refuse each other: only one part of a program registers the context.
|
|
555
|
+
|
|
556
|
+
To export the spans with no SDK of `sdk-node`, give the processors of the entry `@mark1russell7/otel-ts/node/export`. The entry loads the exporters, so import it only when the program exports:
|
|
557
|
+
|
|
558
|
+
```ts
|
|
559
|
+
import { startNodeContext } from "@mark1russell7/otel-ts/node/context";
|
|
560
|
+
|
|
561
|
+
const spanProcessors = process.env["OTEL_EXPORTER_OTLP_ENDPOINT"]
|
|
562
|
+
? (await import("@mark1russell7/otel-ts/node/export")).exportSpanProcessors()
|
|
563
|
+
: [];
|
|
564
|
+
export const telemetry = startNodeContext({ serviceName: "my-tool", spanProcessors });
|
|
565
|
+
```
|
|
566
|
+
|
|
567
|
+
- The processors are those of `/node`: the context processor, then one processor for each exporter of `OTEL_TRACES_EXPORTER` (`otlp`, `console` or `none`), with the protocol of `OTEL_EXPORTER_OTLP_PROTOCOL`.
|
|
568
|
+
- With no value in `OTEL_EXPORTER_OTLP_ENDPOINT`, `exportSpanProcessors()` gives no processor. The option `exporter` exports to an exporter of the program.
|
|
569
|
+
- `telemetry.shutdown()` flushes the spans. A command line calls it before it ends.
|
|
570
|
+
- For the logs and the metrics, and for the instrumentations, import `startNodeTelemetry()` from `/node` in place of `startNodeContext()`.
|
|
555
571
|
|
|
556
572
|
### A service of `@mark1russell7/service`
|
|
557
573
|
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The entry `@mark1russell7/otel-ts/node/export`: the span processors that export the spans of a program that
|
|
3
|
+
* starts the context with `startNodeContext()` of the entry `/node/context`, with no SDK of `@opentelemetry/sdk-node`.
|
|
4
|
+
*
|
|
5
|
+
* The processors are those of the entry `/node`: the context processor, then one processor for each exporter of
|
|
6
|
+
* `OTEL_TRACES_EXPORTER`, with the protocol of `OTEL_EXPORTER_OTLP_TRACES_PROTOCOL` or `OTEL_EXPORTER_OTLP_PROTOCOL`.
|
|
7
|
+
* This entry loads the exporters. Thus a program that exports only with an endpoint imports it with `import()`
|
|
8
|
+
* when `OTEL_EXPORTER_OTLP_ENDPOINT` has a value:
|
|
9
|
+
*
|
|
10
|
+
* ```ts no-run
|
|
11
|
+
* import { startNodeContext } from "@mark1russell7/otel-ts/node/context";
|
|
12
|
+
*
|
|
13
|
+
* const spanProcessors = process.env["OTEL_EXPORTER_OTLP_ENDPOINT"]
|
|
14
|
+
* ? (await import("@mark1russell7/otel-ts/node/export")).exportSpanProcessors()
|
|
15
|
+
* : [];
|
|
16
|
+
* const telemetry = startNodeContext({ serviceName: "my-tool", spanProcessors });
|
|
17
|
+
* // The work of the program, then:
|
|
18
|
+
* await telemetry.shutdown();
|
|
19
|
+
* ```
|
|
20
|
+
*
|
|
21
|
+
* @packageDocumentation
|
|
22
|
+
*/
|
|
23
|
+
import type { SpanExporter, SpanProcessor } from "@opentelemetry/sdk-trace";
|
|
24
|
+
/** The options of `exportSpanProcessors()` */
|
|
25
|
+
export interface ExportSpanOptions {
|
|
26
|
+
/**
|
|
27
|
+
* The environment of `OTEL_EXPORTER_OTLP_ENDPOINT`, of the exporter names and of the protocols. Default:
|
|
28
|
+
* `process.env`. An OTLP exporter reads its endpoint, headers and timeout from `process.env`, not from this object.
|
|
29
|
+
*/
|
|
30
|
+
env?: NodeJS.ProcessEnv;
|
|
31
|
+
/** The trace exporter. With it, the processors export to it, also with no endpoint. Default: the exporters of the variables. */
|
|
32
|
+
exporter?: SpanExporter;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* The span processors that export the spans, for the option `spanProcessors` of `startNodeContext()`. With no
|
|
36
|
+
* value in `OTEL_EXPORTER_OTLP_ENDPOINT` and no `exporter`, it gives no processor, as the entry `/node` exports
|
|
37
|
+
* nothing then. `OTEL_TRACES_EXPORTER=none` also gives no processor. The `shutdown()` of the context flushes them.
|
|
38
|
+
*/
|
|
39
|
+
export declare function exportSpanProcessors(options?: ExportSpanOptions): SpanProcessor[];
|
|
40
|
+
//# sourceMappingURL=node-export.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"node-export.d.ts","sourceRoot":"","sources":["../src/node-export.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,OAAO,KAAK,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAG5E,8CAA8C;AAC9C,MAAM,WAAW,iBAAiB;IAChC;;;OAGG;IACH,GAAG,CAAC,EAAE,MAAM,CAAC,UAAU,CAAC;IACxB,gIAAgI;IAChI,QAAQ,CAAC,EAAE,YAAY,CAAC;CACzB;AAED;;;;GAIG;AACH,wBAAgB,oBAAoB,CAAC,OAAO,GAAE,iBAAsB,GAAG,aAAa,EAAE,CAIrF"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { nodeSpanProcessors } from "./node-exporters.js";
|
|
2
|
+
/**
|
|
3
|
+
* The span processors that export the spans, for the option `spanProcessors` of `startNodeContext()`. With no
|
|
4
|
+
* value in `OTEL_EXPORTER_OTLP_ENDPOINT` and no `exporter`, it gives no processor, as the entry `/node` exports
|
|
5
|
+
* nothing then. `OTEL_TRACES_EXPORTER=none` also gives no processor. The `shutdown()` of the context flushes them.
|
|
6
|
+
*/
|
|
7
|
+
export function exportSpanProcessors(options = {}) {
|
|
8
|
+
const env = options.env ?? process.env;
|
|
9
|
+
if (options.exporter === undefined && !env["OTEL_EXPORTER_OTLP_ENDPOINT"])
|
|
10
|
+
return [];
|
|
11
|
+
return nodeSpanProcessors(env, options.exporter);
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=node-export.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"node-export.js","sourceRoot":"","sources":["../src/node-export.ts"],"names":[],"mappings":"AAuBA,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AAazD;;;;GAIG;AACH,MAAM,UAAU,oBAAoB,CAAC,UAA6B,EAAE;IAClE,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,IAAI,OAAO,CAAC,GAAG,CAAC;IACvC,IAAI,OAAO,CAAC,QAAQ,KAAK,SAAS,IAAI,CAAC,GAAG,CAAC,6BAA6B,CAAC;QAAE,OAAO,EAAE,CAAC;IACrF,OAAO,kBAAkB,CAAC,GAAG,EAAE,OAAO,CAAC,QAAQ,CAAC,CAAC;AACnD,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.10.
|
|
4
|
+
"version": "0.10.5",
|
|
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)",
|
|
@@ -55,6 +55,11 @@
|
|
|
55
55
|
"import": "./dist/node-context.js",
|
|
56
56
|
"default": "./dist/node-context.js"
|
|
57
57
|
},
|
|
58
|
+
"./node/export": {
|
|
59
|
+
"types": "./dist/node-export.d.ts",
|
|
60
|
+
"import": "./dist/node-export.js",
|
|
61
|
+
"default": "./dist/node-export.js"
|
|
62
|
+
},
|
|
58
63
|
"./node/testing": {
|
|
59
64
|
"types": "./dist/node-testing.d.ts",
|
|
60
65
|
"import": "./dist/node-testing.js",
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The entry `@mark1russell7/otel-ts/node/export`: the span processors that export the spans of a program that
|
|
3
|
+
* starts the context with `startNodeContext()` of the entry `/node/context`, with no SDK of `@opentelemetry/sdk-node`.
|
|
4
|
+
*
|
|
5
|
+
* The processors are those of the entry `/node`: the context processor, then one processor for each exporter of
|
|
6
|
+
* `OTEL_TRACES_EXPORTER`, with the protocol of `OTEL_EXPORTER_OTLP_TRACES_PROTOCOL` or `OTEL_EXPORTER_OTLP_PROTOCOL`.
|
|
7
|
+
* This entry loads the exporters. Thus a program that exports only with an endpoint imports it with `import()`
|
|
8
|
+
* when `OTEL_EXPORTER_OTLP_ENDPOINT` has a value:
|
|
9
|
+
*
|
|
10
|
+
* ```ts no-run
|
|
11
|
+
* import { startNodeContext } from "@mark1russell7/otel-ts/node/context";
|
|
12
|
+
*
|
|
13
|
+
* const spanProcessors = process.env["OTEL_EXPORTER_OTLP_ENDPOINT"]
|
|
14
|
+
* ? (await import("@mark1russell7/otel-ts/node/export")).exportSpanProcessors()
|
|
15
|
+
* : [];
|
|
16
|
+
* const telemetry = startNodeContext({ serviceName: "my-tool", spanProcessors });
|
|
17
|
+
* // The work of the program, then:
|
|
18
|
+
* await telemetry.shutdown();
|
|
19
|
+
* ```
|
|
20
|
+
*
|
|
21
|
+
* @packageDocumentation
|
|
22
|
+
*/
|
|
23
|
+
import type { SpanExporter, SpanProcessor } from "@opentelemetry/sdk-trace";
|
|
24
|
+
import { nodeSpanProcessors } from "./node-exporters.js";
|
|
25
|
+
|
|
26
|
+
/** The options of `exportSpanProcessors()` */
|
|
27
|
+
export interface ExportSpanOptions {
|
|
28
|
+
/**
|
|
29
|
+
* The environment of `OTEL_EXPORTER_OTLP_ENDPOINT`, of the exporter names and of the protocols. Default:
|
|
30
|
+
* `process.env`. An OTLP exporter reads its endpoint, headers and timeout from `process.env`, not from this object.
|
|
31
|
+
*/
|
|
32
|
+
env?: NodeJS.ProcessEnv;
|
|
33
|
+
/** The trace exporter. With it, the processors export to it, also with no endpoint. Default: the exporters of the variables. */
|
|
34
|
+
exporter?: SpanExporter;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* The span processors that export the spans, for the option `spanProcessors` of `startNodeContext()`. With no
|
|
39
|
+
* value in `OTEL_EXPORTER_OTLP_ENDPOINT` and no `exporter`, it gives no processor, as the entry `/node` exports
|
|
40
|
+
* nothing then. `OTEL_TRACES_EXPORTER=none` also gives no processor. The `shutdown()` of the context flushes them.
|
|
41
|
+
*/
|
|
42
|
+
export function exportSpanProcessors(options: ExportSpanOptions = {}): SpanProcessor[] {
|
|
43
|
+
const env = options.env ?? process.env;
|
|
44
|
+
if (options.exporter === undefined && !env["OTEL_EXPORTER_OTLP_ENDPOINT"]) return [];
|
|
45
|
+
return nodeSpanProcessors(env, options.exporter);
|
|
46
|
+
}
|