@arnilo/prism-observability-opentelemetry 0.0.4
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/CHANGELOG.md +11 -0
- package/LICENSE +21 -0
- package/README.md +49 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +3 -0
- package/dist/instrumentation.d.ts +95 -0
- package/dist/instrumentation.js +275 -0
- package/package.json +59 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## [Unreleased]
|
|
4
|
+
|
|
5
|
+
## [0.0.4] - 2026-07-14
|
|
6
|
+
|
|
7
|
+
- Added session attachment, metadata-only provider/tool spans, low-cardinality metrics, in-memory telemetry, disabled no-op mode, and exporter-failure isolation.
|
|
8
|
+
|
|
9
|
+
## [0.0.3]
|
|
10
|
+
|
|
11
|
+
- Initial release: `createOpenTelemetryInstrumentation`, mockable tracer/meter interfaces, and optional `@opentelemetry/api` bridge.
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Prism 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,49 @@
|
|
|
1
|
+
# @arnilo/prism-observability-opentelemetry
|
|
2
|
+
|
|
3
|
+
Optional OpenTelemetry bridge for Prism `AgentEvent` streams. Core Prism emits metadata-only provider and tool timing events; this package maps them to spans and low-cardinality metrics without pulling OpenTelemetry into `@arnilo/prism`.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @arnilo/prism @arnilo/prism-observability-opentelemetry @opentelemetry/api
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
`@opentelemetry/api` is an optional peer dependency. Pass mockable `PrismTracer` / `PrismMeter` interfaces when you want tests without the OpenTelemetry SDK.
|
|
12
|
+
|
|
13
|
+
## Usage
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
import { trace, metrics } from "@opentelemetry/api";
|
|
17
|
+
import { createOpenTelemetryInstrumentation, wrapOpenTelemetryApi } from "@arnilo/prism-observability-opentelemetry";
|
|
18
|
+
|
|
19
|
+
const { tracer, meter } = wrapOpenTelemetryApi(trace.getTracer("my-app"), metrics.getMeter("my-app"));
|
|
20
|
+
const telemetry = createOpenTelemetryInstrumentation({ tracer, meter });
|
|
21
|
+
|
|
22
|
+
const detach = telemetry.attachSession(session);
|
|
23
|
+
await session.run("hello");
|
|
24
|
+
detach();
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
Or handle events from an existing subscriber:
|
|
28
|
+
|
|
29
|
+
```ts
|
|
30
|
+
for await (const event of session.subscribe()) telemetry.handleAgentEvent(event);
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
Set `enabled: false` or omit both `tracer` and `meter` for a no-op adapter.
|
|
34
|
+
|
|
35
|
+
## Defaults
|
|
36
|
+
|
|
37
|
+
- Metadata-only spans: no prompts, tool arguments, or credentials.
|
|
38
|
+
- High-cardinality IDs (`sessionId`, `runId`, `requestId`, `toolCallId`) are span attributes, not metric labels.
|
|
39
|
+
- Metric labels are limited to `provider_id`, `outcome`, `status`, and token `kind`.
|
|
40
|
+
- Exporter failures are isolated: instrumentation catches errors and forwards them to `onExporterError` without affecting the run.
|
|
41
|
+
|
|
42
|
+
## Profile inclusion
|
|
43
|
+
|
|
44
|
+
This optional package is installed by `@arnilo/prism-sdk` and `@arnilo/prism-all`. Installation does not enable instrumentation; hosts still provide and configure telemetry APIs/exporters.
|
|
45
|
+
|
|
46
|
+
## Related
|
|
47
|
+
|
|
48
|
+
- [Observability](../../docs/observability.md)
|
|
49
|
+
- [Agent events](../../docs/agent-events.md)
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export { createInMemoryTelemetry, createOpenTelemetryInstrumentation, wrapOpenTelemetryApi, } from "./instrumentation.js";
|
|
2
|
+
export type { InMemoryTelemetry, OpenTelemetryInstrumentation, OpenTelemetryInstrumentationOptions, PrismCounter, PrismHistogram, PrismMeter, PrismSpan, PrismSpanStatus, PrismTracer, RecordedMetric, RecordedSpan, } from "./instrumentation.js";
|
|
3
|
+
export declare const packageName = "@arnilo/prism-observability-opentelemetry";
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import type { AgentEvent, AgentSession } from "@arnilo/prism";
|
|
2
|
+
export type PrismSpanStatus = "ok" | "error";
|
|
3
|
+
export interface PrismSpan {
|
|
4
|
+
setAttribute(key: string, value: string | number | boolean): void;
|
|
5
|
+
setStatus(code: PrismSpanStatus, message?: string): void;
|
|
6
|
+
end(): void;
|
|
7
|
+
}
|
|
8
|
+
export interface PrismTracer {
|
|
9
|
+
startSpan(name: string, options?: {
|
|
10
|
+
readonly attributes?: Readonly<Record<string, string | number | boolean>>;
|
|
11
|
+
}): PrismSpan;
|
|
12
|
+
}
|
|
13
|
+
export interface PrismCounter {
|
|
14
|
+
add(value: number, attributes?: Readonly<Record<string, string>>): void;
|
|
15
|
+
}
|
|
16
|
+
export interface PrismHistogram {
|
|
17
|
+
record(value: number, attributes?: Readonly<Record<string, string>>): void;
|
|
18
|
+
}
|
|
19
|
+
export interface PrismMeter {
|
|
20
|
+
createCounter(name: string, options?: {
|
|
21
|
+
readonly description?: string;
|
|
22
|
+
}): PrismCounter;
|
|
23
|
+
createHistogram(name: string, options?: {
|
|
24
|
+
readonly description?: string;
|
|
25
|
+
readonly unit?: string;
|
|
26
|
+
}): PrismHistogram;
|
|
27
|
+
}
|
|
28
|
+
export interface OpenTelemetryInstrumentationOptions {
|
|
29
|
+
readonly enabled?: boolean;
|
|
30
|
+
readonly tracer?: PrismTracer;
|
|
31
|
+
readonly meter?: PrismMeter;
|
|
32
|
+
readonly onExporterError?: (error: unknown) => void;
|
|
33
|
+
}
|
|
34
|
+
export interface OpenTelemetryInstrumentation {
|
|
35
|
+
readonly enabled: boolean;
|
|
36
|
+
handleAgentEvent(event: AgentEvent): void;
|
|
37
|
+
attachSession(session: Pick<AgentSession, "subscribe">): () => void;
|
|
38
|
+
}
|
|
39
|
+
export interface RecordedSpan {
|
|
40
|
+
readonly name: string;
|
|
41
|
+
readonly attributes: Record<string, string | number | boolean>;
|
|
42
|
+
readonly status?: {
|
|
43
|
+
readonly code: PrismSpanStatus;
|
|
44
|
+
readonly message?: string;
|
|
45
|
+
};
|
|
46
|
+
readonly ended: boolean;
|
|
47
|
+
}
|
|
48
|
+
export interface RecordedMetric {
|
|
49
|
+
readonly name: string;
|
|
50
|
+
readonly kind: "counter" | "histogram";
|
|
51
|
+
readonly value: number;
|
|
52
|
+
readonly attributes: Record<string, string>;
|
|
53
|
+
}
|
|
54
|
+
export interface InMemoryTelemetry {
|
|
55
|
+
readonly tracer: PrismTracer;
|
|
56
|
+
readonly meter: PrismMeter;
|
|
57
|
+
readonly spans: readonly RecordedSpan[];
|
|
58
|
+
readonly metrics: readonly RecordedMetric[];
|
|
59
|
+
clear(): void;
|
|
60
|
+
}
|
|
61
|
+
export declare function createInMemoryTelemetry(): InMemoryTelemetry;
|
|
62
|
+
export declare function createOpenTelemetryInstrumentation(options?: OpenTelemetryInstrumentationOptions): OpenTelemetryInstrumentation;
|
|
63
|
+
interface OpenTelemetrySpan {
|
|
64
|
+
setAttribute(key: string, value: string | number | boolean): void;
|
|
65
|
+
setStatus(status: {
|
|
66
|
+
code: number;
|
|
67
|
+
message?: string;
|
|
68
|
+
}): void;
|
|
69
|
+
end(): void;
|
|
70
|
+
}
|
|
71
|
+
interface OpenTelemetryTracer {
|
|
72
|
+
startSpan(name: string, options?: {
|
|
73
|
+
attributes?: Record<string, string | number | boolean>;
|
|
74
|
+
}): OpenTelemetrySpan;
|
|
75
|
+
}
|
|
76
|
+
interface OpenTelemetryCounter {
|
|
77
|
+
add(value: number, attributes?: Record<string, string>): void;
|
|
78
|
+
}
|
|
79
|
+
interface OpenTelemetryHistogram {
|
|
80
|
+
record(value: number, attributes?: Record<string, string>): void;
|
|
81
|
+
}
|
|
82
|
+
interface OpenTelemetryMeter {
|
|
83
|
+
createCounter(name: string, options?: {
|
|
84
|
+
description?: string;
|
|
85
|
+
}): OpenTelemetryCounter;
|
|
86
|
+
createHistogram(name: string, options?: {
|
|
87
|
+
description?: string;
|
|
88
|
+
unit?: string;
|
|
89
|
+
}): OpenTelemetryHistogram;
|
|
90
|
+
}
|
|
91
|
+
export declare function wrapOpenTelemetryApi(tracer: OpenTelemetryTracer, meter?: OpenTelemetryMeter): {
|
|
92
|
+
tracer: PrismTracer;
|
|
93
|
+
meter?: PrismMeter;
|
|
94
|
+
};
|
|
95
|
+
export {};
|
|
@@ -0,0 +1,275 @@
|
|
|
1
|
+
function spanKey(...parts) {
|
|
2
|
+
return parts.join(":");
|
|
3
|
+
}
|
|
4
|
+
function metricAttrs(attrs) {
|
|
5
|
+
return attrs;
|
|
6
|
+
}
|
|
7
|
+
export function createInMemoryTelemetry() {
|
|
8
|
+
const spans = [];
|
|
9
|
+
const metrics = [];
|
|
10
|
+
const tracer = {
|
|
11
|
+
startSpan(name, options) {
|
|
12
|
+
const record = { name, attributes: { ...(options?.attributes ?? {}) }, ended: false };
|
|
13
|
+
spans.push(record);
|
|
14
|
+
return {
|
|
15
|
+
setAttribute(key, value) {
|
|
16
|
+
record.attributes[key] = value;
|
|
17
|
+
},
|
|
18
|
+
setStatus(code, message) {
|
|
19
|
+
record.status = { code, message };
|
|
20
|
+
},
|
|
21
|
+
end() {
|
|
22
|
+
record.ended = true;
|
|
23
|
+
},
|
|
24
|
+
};
|
|
25
|
+
},
|
|
26
|
+
};
|
|
27
|
+
const meter = {
|
|
28
|
+
createCounter(name) {
|
|
29
|
+
return {
|
|
30
|
+
add(value, attributes) {
|
|
31
|
+
metrics.push({ name, kind: "counter", value, attributes: { ...(attributes ?? {}) } });
|
|
32
|
+
},
|
|
33
|
+
};
|
|
34
|
+
},
|
|
35
|
+
createHistogram(name) {
|
|
36
|
+
return {
|
|
37
|
+
record(value, attributes) {
|
|
38
|
+
metrics.push({ name, kind: "histogram", value, attributes: { ...(attributes ?? {}) } });
|
|
39
|
+
},
|
|
40
|
+
};
|
|
41
|
+
},
|
|
42
|
+
};
|
|
43
|
+
return {
|
|
44
|
+
tracer,
|
|
45
|
+
meter,
|
|
46
|
+
get spans() {
|
|
47
|
+
return spans;
|
|
48
|
+
},
|
|
49
|
+
get metrics() {
|
|
50
|
+
return metrics;
|
|
51
|
+
},
|
|
52
|
+
clear() {
|
|
53
|
+
spans.length = 0;
|
|
54
|
+
metrics.length = 0;
|
|
55
|
+
},
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
export function createOpenTelemetryInstrumentation(options = {}) {
|
|
59
|
+
const enabled = options.enabled !== false && Boolean(options.tracer ?? options.meter);
|
|
60
|
+
const onExporterError = options.onExporterError ?? (() => { });
|
|
61
|
+
const tracer = options.tracer;
|
|
62
|
+
const meter = options.meter;
|
|
63
|
+
const providerDuration = meter?.createHistogram("prism.provider.turn.duration_ms", {
|
|
64
|
+
description: "Provider turn latency",
|
|
65
|
+
unit: "ms",
|
|
66
|
+
});
|
|
67
|
+
const toolDuration = meter?.createHistogram("prism.tool.execution.duration_ms", {
|
|
68
|
+
description: "Tool execution latency",
|
|
69
|
+
unit: "ms",
|
|
70
|
+
});
|
|
71
|
+
const tokenCounter = meter?.createCounter("prism.provider.tokens", { description: "Provider token usage" });
|
|
72
|
+
const activeSpans = new Map();
|
|
73
|
+
const safe = (fn) => {
|
|
74
|
+
if (!enabled)
|
|
75
|
+
return;
|
|
76
|
+
try {
|
|
77
|
+
fn();
|
|
78
|
+
}
|
|
79
|
+
catch (error) {
|
|
80
|
+
onExporterError(error);
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
const endSpan = (key, status, message) => {
|
|
84
|
+
const span = activeSpans.get(key);
|
|
85
|
+
if (!span)
|
|
86
|
+
return;
|
|
87
|
+
span.setStatus(status, message);
|
|
88
|
+
span.end();
|
|
89
|
+
activeSpans.delete(key);
|
|
90
|
+
};
|
|
91
|
+
const handleAgentEvent = (event) => {
|
|
92
|
+
if (!enabled)
|
|
93
|
+
return;
|
|
94
|
+
switch (event.type) {
|
|
95
|
+
case "agent_started":
|
|
96
|
+
safe(() => {
|
|
97
|
+
if (!tracer)
|
|
98
|
+
return;
|
|
99
|
+
const key = spanKey("agent", event.runId);
|
|
100
|
+
activeSpans.set(key, tracer.startSpan("prism.agent.run", {
|
|
101
|
+
attributes: {
|
|
102
|
+
"prism.session_id": event.sessionId,
|
|
103
|
+
"prism.run_id": event.runId,
|
|
104
|
+
},
|
|
105
|
+
}));
|
|
106
|
+
});
|
|
107
|
+
break;
|
|
108
|
+
case "agent_finished":
|
|
109
|
+
safe(() => {
|
|
110
|
+
endSpan(spanKey("agent", event.runId), "ok");
|
|
111
|
+
if (!event.usage || !tokenCounter)
|
|
112
|
+
return;
|
|
113
|
+
tokenCounter.add(event.usage.inputTokens ?? 0, metricAttrs({ kind: "input", scope: "agent" }));
|
|
114
|
+
tokenCounter.add(event.usage.outputTokens ?? 0, metricAttrs({ kind: "output", scope: "agent" }));
|
|
115
|
+
});
|
|
116
|
+
break;
|
|
117
|
+
case "provider_turn_started":
|
|
118
|
+
safe(() => {
|
|
119
|
+
if (!tracer)
|
|
120
|
+
return;
|
|
121
|
+
const attempt = event.metadata.attempt ?? 1;
|
|
122
|
+
const key = spanKey("provider", event.runId, event.turn, attempt);
|
|
123
|
+
activeSpans.set(key, tracer.startSpan("prism.provider.turn", {
|
|
124
|
+
attributes: {
|
|
125
|
+
"prism.session_id": event.sessionId,
|
|
126
|
+
"prism.run_id": event.runId,
|
|
127
|
+
"prism.turn": event.turn,
|
|
128
|
+
"prism.provider_id": event.metadata.providerId,
|
|
129
|
+
"prism.model": event.metadata.model.model,
|
|
130
|
+
...(event.metadata.requestId ? { "prism.request_id": event.metadata.requestId } : {}),
|
|
131
|
+
...(event.metadata.attempt ? { "prism.attempt": event.metadata.attempt } : {}),
|
|
132
|
+
},
|
|
133
|
+
}));
|
|
134
|
+
});
|
|
135
|
+
break;
|
|
136
|
+
case "provider_turn_finished":
|
|
137
|
+
safe(() => {
|
|
138
|
+
const attempt = event.metadata.attempt ?? 1;
|
|
139
|
+
const key = spanKey("provider", event.runId, event.turn, attempt);
|
|
140
|
+
const span = activeSpans.get(key);
|
|
141
|
+
if (span) {
|
|
142
|
+
if (event.metadata.latencyMs !== undefined)
|
|
143
|
+
span.setAttribute("prism.latency_ms", event.metadata.latencyMs);
|
|
144
|
+
if (event.metadata.httpStatus !== undefined)
|
|
145
|
+
span.setAttribute("http.status_code", event.metadata.httpStatus);
|
|
146
|
+
if (event.error)
|
|
147
|
+
span.setStatus("error", event.error.message);
|
|
148
|
+
else
|
|
149
|
+
span.setStatus("ok");
|
|
150
|
+
span.end();
|
|
151
|
+
activeSpans.delete(key);
|
|
152
|
+
}
|
|
153
|
+
providerDuration?.record(event.metadata.latencyMs ?? 0, metricAttrs({
|
|
154
|
+
provider_id: event.metadata.providerId,
|
|
155
|
+
outcome: event.error ? "error" : "success",
|
|
156
|
+
}));
|
|
157
|
+
if (!event.usage || !tokenCounter)
|
|
158
|
+
return;
|
|
159
|
+
tokenCounter.add(event.usage.inputTokens ?? 0, metricAttrs({ provider_id: event.metadata.providerId, kind: "input" }));
|
|
160
|
+
tokenCounter.add(event.usage.outputTokens ?? 0, metricAttrs({ provider_id: event.metadata.providerId, kind: "output" }));
|
|
161
|
+
if (event.usage.cacheReadTokens) {
|
|
162
|
+
tokenCounter.add(event.usage.cacheReadTokens, metricAttrs({ provider_id: event.metadata.providerId, kind: "cache_read" }));
|
|
163
|
+
}
|
|
164
|
+
if (event.usage.cacheWriteTokens) {
|
|
165
|
+
tokenCounter.add(event.usage.cacheWriteTokens, metricAttrs({ provider_id: event.metadata.providerId, kind: "cache_write" }));
|
|
166
|
+
}
|
|
167
|
+
});
|
|
168
|
+
break;
|
|
169
|
+
case "tool_execution_started":
|
|
170
|
+
safe(() => {
|
|
171
|
+
if (!tracer)
|
|
172
|
+
return;
|
|
173
|
+
const key = spanKey("tool", event.call.id);
|
|
174
|
+
activeSpans.set(key, tracer.startSpan("prism.tool.execute", {
|
|
175
|
+
attributes: {
|
|
176
|
+
"prism.session_id": event.sessionId,
|
|
177
|
+
"prism.run_id": event.runId,
|
|
178
|
+
"prism.tool_call_id": event.call.id,
|
|
179
|
+
"prism.tool_name": event.call.name,
|
|
180
|
+
},
|
|
181
|
+
}));
|
|
182
|
+
});
|
|
183
|
+
break;
|
|
184
|
+
case "tool_execution_finished":
|
|
185
|
+
case "tool_execution_error":
|
|
186
|
+
case "tool_execution_blocked":
|
|
187
|
+
safe(() => {
|
|
188
|
+
const toolCallId = event.type === "tool_execution_finished"
|
|
189
|
+
? event.result.toolCallId
|
|
190
|
+
: event.type === "tool_execution_error"
|
|
191
|
+
? event.call.id
|
|
192
|
+
: event.toolCallId;
|
|
193
|
+
const key = spanKey("tool", toolCallId);
|
|
194
|
+
const span = activeSpans.get(key);
|
|
195
|
+
if (span) {
|
|
196
|
+
span.setAttribute("prism.tool_status", event.metadata.status);
|
|
197
|
+
span.setAttribute("prism.duration_ms", event.metadata.durationMs);
|
|
198
|
+
if (event.type === "tool_execution_finished")
|
|
199
|
+
span.setStatus("ok");
|
|
200
|
+
else
|
|
201
|
+
span.setStatus("error", event.error.message);
|
|
202
|
+
span.end();
|
|
203
|
+
activeSpans.delete(key);
|
|
204
|
+
}
|
|
205
|
+
toolDuration?.record(event.metadata.durationMs, metricAttrs({ status: event.metadata.status }));
|
|
206
|
+
});
|
|
207
|
+
break;
|
|
208
|
+
default:
|
|
209
|
+
break;
|
|
210
|
+
}
|
|
211
|
+
};
|
|
212
|
+
return {
|
|
213
|
+
enabled,
|
|
214
|
+
handleAgentEvent,
|
|
215
|
+
attachSession(session) {
|
|
216
|
+
if (!enabled)
|
|
217
|
+
return () => { };
|
|
218
|
+
const subscription = session.subscribe();
|
|
219
|
+
const iterator = subscription[Symbol.asyncIterator]();
|
|
220
|
+
let active = true;
|
|
221
|
+
void (async () => {
|
|
222
|
+
try {
|
|
223
|
+
while (active) {
|
|
224
|
+
const next = await iterator.next();
|
|
225
|
+
if (next.done)
|
|
226
|
+
break;
|
|
227
|
+
handleAgentEvent(next.value);
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
catch {
|
|
231
|
+
// subscriber closed
|
|
232
|
+
}
|
|
233
|
+
})();
|
|
234
|
+
return () => {
|
|
235
|
+
active = false;
|
|
236
|
+
void iterator.return?.();
|
|
237
|
+
};
|
|
238
|
+
},
|
|
239
|
+
};
|
|
240
|
+
}
|
|
241
|
+
const OTEL_STATUS_OK = 1;
|
|
242
|
+
const OTEL_STATUS_ERROR = 2;
|
|
243
|
+
export function wrapOpenTelemetryApi(tracer, meter) {
|
|
244
|
+
return {
|
|
245
|
+
tracer: {
|
|
246
|
+
startSpan(name, options) {
|
|
247
|
+
const span = tracer.startSpan(name, options);
|
|
248
|
+
return {
|
|
249
|
+
setAttribute(key, value) {
|
|
250
|
+
span.setAttribute(key, value);
|
|
251
|
+
},
|
|
252
|
+
setStatus(code, message) {
|
|
253
|
+
span.setStatus({ code: code === "ok" ? OTEL_STATUS_OK : OTEL_STATUS_ERROR, message });
|
|
254
|
+
},
|
|
255
|
+
end() {
|
|
256
|
+
span.end();
|
|
257
|
+
},
|
|
258
|
+
};
|
|
259
|
+
},
|
|
260
|
+
},
|
|
261
|
+
meter: meter
|
|
262
|
+
? {
|
|
263
|
+
createCounter(name, options) {
|
|
264
|
+
const counter = meter.createCounter(name, options);
|
|
265
|
+
return { add: (value, attributes) => counter.add(value, attributes) };
|
|
266
|
+
},
|
|
267
|
+
createHistogram(name, options) {
|
|
268
|
+
const histogram = meter.createHistogram(name, options);
|
|
269
|
+
return { record: (value, attributes) => histogram.record(value, attributes) };
|
|
270
|
+
},
|
|
271
|
+
}
|
|
272
|
+
: undefined,
|
|
273
|
+
};
|
|
274
|
+
}
|
|
275
|
+
//# sourceMappingURL=instrumentation.js.map
|
package/package.json
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@arnilo/prism-observability-opentelemetry",
|
|
3
|
+
"version": "0.0.4",
|
|
4
|
+
"description": "Optional OpenTelemetry adapter for Prism agent events.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"default": "./dist/index.js"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"files": [
|
|
15
|
+
"dist",
|
|
16
|
+
"!dist/__tests__",
|
|
17
|
+
"!dist/**/*.map",
|
|
18
|
+
"README.md",
|
|
19
|
+
"CHANGELOG.md"
|
|
20
|
+
],
|
|
21
|
+
"scripts": {
|
|
22
|
+
"build": "tsc -p tsconfig.json",
|
|
23
|
+
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
24
|
+
"test": "node --test dist/__tests__/*.test.js",
|
|
25
|
+
"pack:dry-run": "npm pack --dry-run"
|
|
26
|
+
},
|
|
27
|
+
"peerDependencies": {
|
|
28
|
+
"@arnilo/prism": "0.0.4"
|
|
29
|
+
},
|
|
30
|
+
"devDependencies": {
|
|
31
|
+
"@arnilo/prism": "file:../..",
|
|
32
|
+
"@opentelemetry/api": "^1.9.0"
|
|
33
|
+
},
|
|
34
|
+
"engines": {
|
|
35
|
+
"node": ">=20"
|
|
36
|
+
},
|
|
37
|
+
"license": "MIT",
|
|
38
|
+
"repository": {
|
|
39
|
+
"type": "git",
|
|
40
|
+
"url": "git+https://github.com/ashiqrniloy/prism.git",
|
|
41
|
+
"directory": "packages/observability-opentelemetry"
|
|
42
|
+
},
|
|
43
|
+
"bugs": {
|
|
44
|
+
"url": "https://github.com/ashiqrniloy/prism/issues"
|
|
45
|
+
},
|
|
46
|
+
"homepage": "https://github.com/ashiqrniloy/prism/tree/main/packages/observability-opentelemetry#readme",
|
|
47
|
+
"keywords": [
|
|
48
|
+
"prism",
|
|
49
|
+
"opentelemetry",
|
|
50
|
+
"observability",
|
|
51
|
+
"tracing",
|
|
52
|
+
"metrics",
|
|
53
|
+
"agent"
|
|
54
|
+
],
|
|
55
|
+
"sideEffects": false,
|
|
56
|
+
"publishConfig": {
|
|
57
|
+
"access": "public"
|
|
58
|
+
}
|
|
59
|
+
}
|