@nightowlsdev/telemetry-otel 0.1.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Night Owls 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,59 @@
1
+ # @nightowlsdev/telemetry-otel
2
+
3
+ An **OTLP/HTTP** telemetry exporter for `@nightowlsdev/core`. It maps a swarm run's
4
+ `run`/`generation`/`tool` `SwarmSpan`s to OpenTelemetry spans (via
5
+ `@nightowlsdev/telemetry-core`) and ships them over OTLP to any compatible backend — Datadog,
6
+ New Relic, Honeycomb, Grafana Tempo, Jaeger, or a plain OpenTelemetry Collector — by
7
+ changing the `url` + `headers`. Generation spans carry `gen_ai.*` semantic-convention
8
+ attributes (model + input/output token usage + cost), so traces land with the LLM context
9
+ your APM already understands.
10
+
11
+ It never imports `@mastra/*` and re-exports no Mastra types (the engine wall, CONTRACTS §1).
12
+
13
+ ## Install
14
+
15
+ ```bash
16
+ pnpm add @nightowlsdev/telemetry-otel @nightowlsdev/core
17
+ ```
18
+
19
+ ## Factory
20
+
21
+ ```ts
22
+ import { otelTelemetry } from "@nightowlsdev/telemetry-otel";
23
+
24
+ const telemetry = otelTelemetry({
25
+ url: "https://otlp.example.com/v1/traces", // OTLP/HTTP traces endpoint
26
+ headers: { "x-api-key": process.env.OTLP_KEY! },
27
+ serviceName: "nightowls", // optional (default "nightowls")
28
+ resourceAttributes: { "deployment.environment": "prod" }, // optional
29
+ });
30
+ ```
31
+
32
+ Spans are exported through a `BatchSpanProcessor`; the replayer **awaits `forceFlush()`**
33
+ after each run's batch so spans aren't lost in a serverless / short-lived invocation.
34
+
35
+ ## Wiring into a swarm
36
+
37
+ ```ts
38
+ import { defineSwarm } from "@nightowlsdev/core";
39
+ import { otelTelemetry } from "@nightowlsdev/telemetry-otel";
40
+
41
+ const swarm = defineSwarm({
42
+ storage,
43
+ agents,
44
+ models: { allow: ["openai/gpt-5.5"] },
45
+ modelFactory,
46
+ cost: { maxSteps: 8, maxCostUsd: 1 },
47
+ telemetry: otelTelemetry({ url, headers }),
48
+ });
49
+ ```
50
+
51
+ `telemetry` accepts one exporter or an array — see `@nightowlsdev/telemetry-core` /
52
+ `compositeTelemetry` for multi-backend fan-out. Telemetry is **best-effort**: a throwing or
53
+ hung exporter never breaks the run (the engine exports in a `finally` and swallows export
54
+ errors).
55
+
56
+ ## Engine wall
57
+
58
+ The built `dist/index.d.ts` contains zero `@mastra` references (enforced by
59
+ `test/wall.test.ts`).
package/dist/index.cjs ADDED
@@ -0,0 +1,84 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ nightOwlsPlugin: () => nightOwlsPlugin,
24
+ otelTelemetry: () => otelTelemetry
25
+ });
26
+ module.exports = __toCommonJS(index_exports);
27
+ var import_sdk_trace_base = require("@opentelemetry/sdk-trace-base");
28
+ var import_exporter_trace_otlp_http = require("@opentelemetry/exporter-trace-otlp-http");
29
+ var import_telemetry_core = require("@nightowlsdev/telemetry-core");
30
+
31
+ // src/plugin.ts
32
+ var nightOwlsPlugin = {
33
+ name: "telemetry-otel",
34
+ version: "0.0.0",
35
+ kind: "telemetry",
36
+ pkg: "@nightowlsdev/telemetry-otel",
37
+ description: "OpenTelemetry/OTLP exporter (Datadog, Honeycomb, Grafana, New Relic, \u2026).",
38
+ env: [
39
+ {
40
+ key: "OTEL_EXPORTER_OTLP_ENDPOINT",
41
+ example: "http://localhost:4318/v1/traces",
42
+ comment: "OTLP/HTTP traces endpoint (your collector or vendor)"
43
+ },
44
+ {
45
+ key: "OTEL_EXPORTER_OTLP_HEADERS",
46
+ example: "",
47
+ comment: "optional vendor auth headers, e.g. 'x-honeycomb-team=KEY' (parse + pass via headers:)"
48
+ }
49
+ ],
50
+ config: {
51
+ import: "import { otelTelemetry } from '@nightowlsdev/telemetry-otel';",
52
+ snippet: "telemetry = [...(telemetry ?? []), otelTelemetry({ url: env.OTEL_EXPORTER_OTLP_ENDPOINT })];",
53
+ marker: "telemetry"
54
+ },
55
+ // Print-only (idempotent) — runs on init/install + `owl init telemetry-otel`. NEVER connects.
56
+ init: (ctx) => {
57
+ ctx.log(
58
+ "OTel telemetry wired (composes with any other telemetry adapter) \u2014 set OTEL_EXPORTER_OTLP_ENDPOINT (+ OTEL_EXPORTER_OTLP_HEADERS for vendor auth)."
59
+ );
60
+ },
61
+ commands: [
62
+ {
63
+ name: "info",
64
+ description: "Show the env + config this telemetry adapter contributes.",
65
+ // PURE — no network. Reads only the static manifest data.
66
+ run: (ctx) => {
67
+ ctx.log("env: OTEL_EXPORTER_OTLP_ENDPOINT, OTEL_EXPORTER_OTLP_HEADERS");
68
+ ctx.log("config: telemetry = [...(telemetry ?? []), otelTelemetry({ url })]");
69
+ }
70
+ }
71
+ ]
72
+ };
73
+
74
+ // src/index.ts
75
+ function otelTelemetry(opts = {}) {
76
+ const exporter = opts.exporter ?? new import_exporter_trace_otlp_http.OTLPTraceExporter({ url: opts.url, headers: opts.headers });
77
+ const processor = new import_sdk_trace_base.BatchSpanProcessor(exporter);
78
+ return (0, import_telemetry_core.replayerExporter)({ processor, serviceName: opts.serviceName, resourceAttributes: opts.resourceAttributes });
79
+ }
80
+ // Annotate the CommonJS export names for ESM import in node:
81
+ 0 && (module.exports = {
82
+ nightOwlsPlugin,
83
+ otelTelemetry
84
+ });
@@ -0,0 +1,68 @@
1
+ import { SpanExporter } from '@opentelemetry/sdk-trace-base';
2
+ import { TelemetryExporter } from '@nightowlsdev/core';
3
+
4
+ /**
5
+ * The Night Owls adapter plugin manifest for the OpenTelemetry/OTLP exporter. `@nightowlsdev/cli` discovers this,
6
+ * dynamic-imports it, and acts on it declaratively:
7
+ * - `env` → merged into `.env.example` (idempotent, only if the KEY is absent),
8
+ * - `config` → the `import` + wiring `snippet` inserted at the `// nightowls:telemetry` marker. Telemetry
9
+ * COMPOSES: the snippet pushes this exporter onto the `telemetry` array, so multiple
10
+ * telemetry adapters coexist (`telemetry = [...(telemetry ?? []), otelTelemetry({...})];`),
11
+ * - `init` → a print-only hook run after the wiring (it NEVER connects to a collector),
12
+ * - `commands`→ `owl telemetry-otel <cmd>` subcommands (e.g. `info` — pure, no network).
13
+ *
14
+ * This object STRUCTURALLY matches the CLI's `NightOwlsPlugin` type but does NOT import it (no dependency
15
+ * cycle): all codegen lives in `@nightowlsdev/cli`; this adapter stays data-only. The `init`/command handler
16
+ * contexts are typed STRUCTURALLY (local `Ctx`/inline shapes) — never importing `@nightowlsdev/cli`.
17
+ */
18
+ /** Structural context for this adapter's pure command handlers — matches the CLI's PluginCommandContext. */
19
+ type Ctx = {
20
+ cwd: string;
21
+ log: (m: string) => void;
22
+ args: string[];
23
+ options: Record<string, unknown>;
24
+ };
25
+ declare const nightOwlsPlugin: {
26
+ readonly name: "telemetry-otel";
27
+ readonly version: "0.0.0";
28
+ readonly kind: "telemetry";
29
+ readonly pkg: "@nightowlsdev/telemetry-otel";
30
+ readonly description: "OpenTelemetry/OTLP exporter (Datadog, Honeycomb, Grafana, New Relic, …).";
31
+ readonly env: readonly [{
32
+ readonly key: "OTEL_EXPORTER_OTLP_ENDPOINT";
33
+ readonly example: "http://localhost:4318/v1/traces";
34
+ readonly comment: "OTLP/HTTP traces endpoint (your collector or vendor)";
35
+ }, {
36
+ readonly key: "OTEL_EXPORTER_OTLP_HEADERS";
37
+ readonly example: "";
38
+ readonly comment: "optional vendor auth headers, e.g. 'x-honeycomb-team=KEY' (parse + pass via headers:)";
39
+ }];
40
+ readonly config: {
41
+ readonly import: "import { otelTelemetry } from '@nightowlsdev/telemetry-otel';";
42
+ readonly snippet: "telemetry = [...(telemetry ?? []), otelTelemetry({ url: env.OTEL_EXPORTER_OTLP_ENDPOINT })];";
43
+ readonly marker: "telemetry";
44
+ };
45
+ readonly init: (ctx: {
46
+ cwd: string;
47
+ log: (m: string) => void;
48
+ }) => void;
49
+ readonly commands: readonly [{
50
+ readonly name: "info";
51
+ readonly description: "Show the env + config this telemetry adapter contributes.";
52
+ readonly run: (ctx: Ctx) => void;
53
+ }];
54
+ };
55
+
56
+ interface OtelTelemetryOpts {
57
+ /** OTLP/HTTP traces endpoint (Datadog/New Relic/Honeycomb/Grafana/Jaeger). Default OTel Collector. */
58
+ url?: string;
59
+ headers?: Record<string, string>;
60
+ serviceName?: string;
61
+ resourceAttributes?: Record<string, string>;
62
+ /** Test/advanced override: provide a SpanExporter directly (skips OTLP construction). */
63
+ exporter?: SpanExporter;
64
+ }
65
+ /** Map Night Owls SwarmSpans to OTLP via OpenTelemetry. Best-effort; pairs with any OTLP-compatible backend. */
66
+ declare function otelTelemetry(opts?: OtelTelemetryOpts): TelemetryExporter;
67
+
68
+ export { type OtelTelemetryOpts, nightOwlsPlugin, otelTelemetry };
@@ -0,0 +1,68 @@
1
+ import { SpanExporter } from '@opentelemetry/sdk-trace-base';
2
+ import { TelemetryExporter } from '@nightowlsdev/core';
3
+
4
+ /**
5
+ * The Night Owls adapter plugin manifest for the OpenTelemetry/OTLP exporter. `@nightowlsdev/cli` discovers this,
6
+ * dynamic-imports it, and acts on it declaratively:
7
+ * - `env` → merged into `.env.example` (idempotent, only if the KEY is absent),
8
+ * - `config` → the `import` + wiring `snippet` inserted at the `// nightowls:telemetry` marker. Telemetry
9
+ * COMPOSES: the snippet pushes this exporter onto the `telemetry` array, so multiple
10
+ * telemetry adapters coexist (`telemetry = [...(telemetry ?? []), otelTelemetry({...})];`),
11
+ * - `init` → a print-only hook run after the wiring (it NEVER connects to a collector),
12
+ * - `commands`→ `owl telemetry-otel <cmd>` subcommands (e.g. `info` — pure, no network).
13
+ *
14
+ * This object STRUCTURALLY matches the CLI's `NightOwlsPlugin` type but does NOT import it (no dependency
15
+ * cycle): all codegen lives in `@nightowlsdev/cli`; this adapter stays data-only. The `init`/command handler
16
+ * contexts are typed STRUCTURALLY (local `Ctx`/inline shapes) — never importing `@nightowlsdev/cli`.
17
+ */
18
+ /** Structural context for this adapter's pure command handlers — matches the CLI's PluginCommandContext. */
19
+ type Ctx = {
20
+ cwd: string;
21
+ log: (m: string) => void;
22
+ args: string[];
23
+ options: Record<string, unknown>;
24
+ };
25
+ declare const nightOwlsPlugin: {
26
+ readonly name: "telemetry-otel";
27
+ readonly version: "0.0.0";
28
+ readonly kind: "telemetry";
29
+ readonly pkg: "@nightowlsdev/telemetry-otel";
30
+ readonly description: "OpenTelemetry/OTLP exporter (Datadog, Honeycomb, Grafana, New Relic, …).";
31
+ readonly env: readonly [{
32
+ readonly key: "OTEL_EXPORTER_OTLP_ENDPOINT";
33
+ readonly example: "http://localhost:4318/v1/traces";
34
+ readonly comment: "OTLP/HTTP traces endpoint (your collector or vendor)";
35
+ }, {
36
+ readonly key: "OTEL_EXPORTER_OTLP_HEADERS";
37
+ readonly example: "";
38
+ readonly comment: "optional vendor auth headers, e.g. 'x-honeycomb-team=KEY' (parse + pass via headers:)";
39
+ }];
40
+ readonly config: {
41
+ readonly import: "import { otelTelemetry } from '@nightowlsdev/telemetry-otel';";
42
+ readonly snippet: "telemetry = [...(telemetry ?? []), otelTelemetry({ url: env.OTEL_EXPORTER_OTLP_ENDPOINT })];";
43
+ readonly marker: "telemetry";
44
+ };
45
+ readonly init: (ctx: {
46
+ cwd: string;
47
+ log: (m: string) => void;
48
+ }) => void;
49
+ readonly commands: readonly [{
50
+ readonly name: "info";
51
+ readonly description: "Show the env + config this telemetry adapter contributes.";
52
+ readonly run: (ctx: Ctx) => void;
53
+ }];
54
+ };
55
+
56
+ interface OtelTelemetryOpts {
57
+ /** OTLP/HTTP traces endpoint (Datadog/New Relic/Honeycomb/Grafana/Jaeger). Default OTel Collector. */
58
+ url?: string;
59
+ headers?: Record<string, string>;
60
+ serviceName?: string;
61
+ resourceAttributes?: Record<string, string>;
62
+ /** Test/advanced override: provide a SpanExporter directly (skips OTLP construction). */
63
+ exporter?: SpanExporter;
64
+ }
65
+ /** Map Night Owls SwarmSpans to OTLP via OpenTelemetry. Best-effort; pairs with any OTLP-compatible backend. */
66
+ declare function otelTelemetry(opts?: OtelTelemetryOpts): TelemetryExporter;
67
+
68
+ export { type OtelTelemetryOpts, nightOwlsPlugin, otelTelemetry };
package/dist/index.js ADDED
@@ -0,0 +1,58 @@
1
+ // src/index.ts
2
+ import { BatchSpanProcessor } from "@opentelemetry/sdk-trace-base";
3
+ import { OTLPTraceExporter } from "@opentelemetry/exporter-trace-otlp-http";
4
+ import { replayerExporter } from "@nightowlsdev/telemetry-core";
5
+
6
+ // src/plugin.ts
7
+ var nightOwlsPlugin = {
8
+ name: "telemetry-otel",
9
+ version: "0.0.0",
10
+ kind: "telemetry",
11
+ pkg: "@nightowlsdev/telemetry-otel",
12
+ description: "OpenTelemetry/OTLP exporter (Datadog, Honeycomb, Grafana, New Relic, \u2026).",
13
+ env: [
14
+ {
15
+ key: "OTEL_EXPORTER_OTLP_ENDPOINT",
16
+ example: "http://localhost:4318/v1/traces",
17
+ comment: "OTLP/HTTP traces endpoint (your collector or vendor)"
18
+ },
19
+ {
20
+ key: "OTEL_EXPORTER_OTLP_HEADERS",
21
+ example: "",
22
+ comment: "optional vendor auth headers, e.g. 'x-honeycomb-team=KEY' (parse + pass via headers:)"
23
+ }
24
+ ],
25
+ config: {
26
+ import: "import { otelTelemetry } from '@nightowlsdev/telemetry-otel';",
27
+ snippet: "telemetry = [...(telemetry ?? []), otelTelemetry({ url: env.OTEL_EXPORTER_OTLP_ENDPOINT })];",
28
+ marker: "telemetry"
29
+ },
30
+ // Print-only (idempotent) — runs on init/install + `owl init telemetry-otel`. NEVER connects.
31
+ init: (ctx) => {
32
+ ctx.log(
33
+ "OTel telemetry wired (composes with any other telemetry adapter) \u2014 set OTEL_EXPORTER_OTLP_ENDPOINT (+ OTEL_EXPORTER_OTLP_HEADERS for vendor auth)."
34
+ );
35
+ },
36
+ commands: [
37
+ {
38
+ name: "info",
39
+ description: "Show the env + config this telemetry adapter contributes.",
40
+ // PURE — no network. Reads only the static manifest data.
41
+ run: (ctx) => {
42
+ ctx.log("env: OTEL_EXPORTER_OTLP_ENDPOINT, OTEL_EXPORTER_OTLP_HEADERS");
43
+ ctx.log("config: telemetry = [...(telemetry ?? []), otelTelemetry({ url })]");
44
+ }
45
+ }
46
+ ]
47
+ };
48
+
49
+ // src/index.ts
50
+ function otelTelemetry(opts = {}) {
51
+ const exporter = opts.exporter ?? new OTLPTraceExporter({ url: opts.url, headers: opts.headers });
52
+ const processor = new BatchSpanProcessor(exporter);
53
+ return replayerExporter({ processor, serviceName: opts.serviceName, resourceAttributes: opts.resourceAttributes });
54
+ }
55
+ export {
56
+ nightOwlsPlugin,
57
+ otelTelemetry
58
+ };
package/package.json ADDED
@@ -0,0 +1,53 @@
1
+ {
2
+ "name": "@nightowlsdev/telemetry-otel",
3
+ "version": "0.1.1",
4
+ "type": "module",
5
+ "license": "MIT",
6
+ "publishConfig": {
7
+ "access": "public"
8
+ },
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "git+https://github.com/cueplusplus/corale.git",
12
+ "directory": "packages/telemetry-otel"
13
+ },
14
+ "homepage": "https://github.com/cueplusplus/corale#readme",
15
+ "sideEffects": false,
16
+ "exports": {
17
+ ".": {
18
+ "types": "./dist/index.d.ts",
19
+ "import": "./dist/index.js",
20
+ "require": "./dist/index.cjs"
21
+ }
22
+ },
23
+ "main": "./dist/index.cjs",
24
+ "module": "./dist/index.js",
25
+ "types": "./dist/index.d.ts",
26
+ "files": [
27
+ "dist"
28
+ ],
29
+ "dependencies": {
30
+ "@opentelemetry/exporter-trace-otlp-http": "^0.203.0",
31
+ "@opentelemetry/sdk-trace-base": "^2.0.1",
32
+ "@nightowlsdev/telemetry-core": "0.1.2"
33
+ },
34
+ "peerDependencies": {
35
+ "@nightowlsdev/core": "0.3.0"
36
+ },
37
+ "devDependencies": {
38
+ "@opentelemetry/core": "^2.0.1",
39
+ "@types/node": "^24.12.4",
40
+ "tsup": "8.5.1",
41
+ "typescript": "6.0.3",
42
+ "vitest": "^3.2.0",
43
+ "@nightowlsdev/tsconfig": "0.0.0",
44
+ "@nightowlsdev/eslint-config": "0.0.0",
45
+ "@nightowlsdev/core": "0.3.0"
46
+ },
47
+ "scripts": {
48
+ "build": "tsup",
49
+ "typecheck": "tsc --noEmit",
50
+ "test": "vitest run",
51
+ "lint": "eslint src"
52
+ }
53
+ }