@overmind-lab/trace-sdk 0.0.1 → 0.0.3
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 +8 -8
- package/package.json +6 -5
- package/src/overmind-client.ts +15 -10
package/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# overmind-
|
|
1
|
+
# @overmind-lab/trace-sdk
|
|
2
2
|
|
|
3
3
|
JavaScript/TypeScript SDK for [Overmind](https://overmindlab.ai) — automatic LLM observability powered by OpenTelemetry.
|
|
4
4
|
|
|
@@ -9,9 +9,9 @@ Instrument your OpenAI calls with a single `initTracing()` call. Traces are expo
|
|
|
9
9
|
## Installation
|
|
10
10
|
|
|
11
11
|
```bash
|
|
12
|
-
bun add overmind-
|
|
12
|
+
bun add @overmind-lab/trace-sdk openai
|
|
13
13
|
# or
|
|
14
|
-
npm install overmind-
|
|
14
|
+
npm install @overmind-lab/trace-sdk openai
|
|
15
15
|
```
|
|
16
16
|
|
|
17
17
|
---
|
|
@@ -20,7 +20,7 @@ npm install overmind-js openai
|
|
|
20
20
|
|
|
21
21
|
```ts
|
|
22
22
|
import { OpenAI } from "openai";
|
|
23
|
-
import { OvermindClient } from "overmind-
|
|
23
|
+
import { OvermindClient } from "@overmind-lab/trace-sdk";
|
|
24
24
|
|
|
25
25
|
// 1. Create the client
|
|
26
26
|
const overmindClient = new OvermindClient({
|
|
@@ -31,7 +31,7 @@ const overmindClient = new OvermindClient({
|
|
|
31
31
|
// 2. Initialize tracing — must be called before any OpenAI calls
|
|
32
32
|
overmindClient.initTracing({
|
|
33
33
|
enableBatching: false,
|
|
34
|
-
enabledProviders: { openai:
|
|
34
|
+
enabledProviders: { openai: OpenAI }, // this is important to patch the correct client
|
|
35
35
|
instrumentations: [],
|
|
36
36
|
});
|
|
37
37
|
|
|
@@ -64,7 +64,7 @@ Traces are sent automatically to `https://api.overmindlab.ai` and will appear in
|
|
|
64
64
|
|
|
65
65
|
| Option | Type | Required | Description |
|
|
66
66
|
|---|---|---|---|
|
|
67
|
-
| `enabledProviders` | `{ openai?:
|
|
67
|
+
| `enabledProviders` | `{ openai?: typeof OpenAI }` | Yes | Pass the imported provider class to monkey-patch. e.g. `{ openai: OpenAI }` where `OpenAI` is imported from `"openai"`. |
|
|
68
68
|
| `enableBatching` | `boolean` | Yes | `true` to batch spans before export (recommended for production), `false` to export immediately. |
|
|
69
69
|
| `instrumentations` | `Instrumentation[]` | No | Additional OpenTelemetry instrumentations to register. |
|
|
70
70
|
| `spanProcessors` | `SpanProcessor[]` | No | Additional span processors (e.g. custom exporters). |
|
|
@@ -84,7 +84,7 @@ Traces are sent automatically to `https://api.overmindlab.ai` and will appear in
|
|
|
84
84
|
|
|
85
85
|
## What Gets Traced
|
|
86
86
|
|
|
87
|
-
When `enabledProviders: { openai:
|
|
87
|
+
When `enabledProviders: { openai: OpenAI }` is set, the SDK automatically captures:
|
|
88
88
|
|
|
89
89
|
- Prompts and completions
|
|
90
90
|
- Model name, temperature, top-p, max tokens
|
|
@@ -103,7 +103,7 @@ Enable batching in production to reduce network overhead:
|
|
|
103
103
|
```ts
|
|
104
104
|
overmindClient.initTracing({
|
|
105
105
|
enableBatching: true, // buffer spans and flush in batches
|
|
106
|
-
enabledProviders: { openai:
|
|
106
|
+
enabledProviders: { openai: OpenAI },
|
|
107
107
|
});
|
|
108
108
|
```
|
|
109
109
|
|
package/package.json
CHANGED
|
@@ -4,19 +4,20 @@
|
|
|
4
4
|
"@opentelemetry/exporter-trace-otlp-proto": "^0.212.0",
|
|
5
5
|
"@opentelemetry/instrumentation-openai": "^0.10.0",
|
|
6
6
|
"@opentelemetry/sdk-node": "^0.212.0",
|
|
7
|
-
"@opentelemetry/sdk-trace-node": "^2.5.1"
|
|
8
|
-
"@traceloop/instrumentation-openai": "^0.22.5",
|
|
9
|
-
"openai": "^6.22.0"
|
|
7
|
+
"@opentelemetry/sdk-trace-node": "^2.5.1"
|
|
10
8
|
},
|
|
11
9
|
"devDependencies": {
|
|
12
10
|
"@biomejs/biome": "^2.4.3"
|
|
13
11
|
},
|
|
12
|
+
"peerDependencies": {
|
|
13
|
+
"openai": "*"
|
|
14
|
+
},
|
|
14
15
|
"name": "@overmind-lab/trace-sdk",
|
|
15
16
|
"packageManager": "bun@1.3.5",
|
|
16
17
|
"private": false,
|
|
17
18
|
"publishConfig": {
|
|
18
19
|
"access": "public",
|
|
19
|
-
"tag": "
|
|
20
|
+
"tag": "latest"
|
|
20
21
|
},
|
|
21
22
|
"scripts": {
|
|
22
23
|
"build": "tsc",
|
|
@@ -24,5 +25,5 @@
|
|
|
24
25
|
"dev": "tsx watch src/index.ts",
|
|
25
26
|
"format": "biome format --write"
|
|
26
27
|
},
|
|
27
|
-
"version": "0.0.
|
|
28
|
+
"version": "0.0.3"
|
|
28
29
|
}
|
package/src/overmind-client.ts
CHANGED
|
@@ -10,10 +10,10 @@ import {
|
|
|
10
10
|
import { ConsoleSpanExporter } from "@opentelemetry/sdk-trace-node";
|
|
11
11
|
import { ATTR_SERVICE_NAME, ATTR_SERVICE_VERSION } from "@opentelemetry/semantic-conventions";
|
|
12
12
|
|
|
13
|
-
import OpenAI from "openai";
|
|
14
|
-
import { OpenAIInstrumentation } from "./instrumentation-openai";
|
|
13
|
+
import type { OpenAI } from "openai";
|
|
15
14
|
|
|
16
15
|
import { name, version } from "../package.json";
|
|
16
|
+
import { OpenAIInstrumentation } from "./instrumentation-openai";
|
|
17
17
|
|
|
18
18
|
type OvermindClientConfig = {
|
|
19
19
|
apiKey: string;
|
|
@@ -26,6 +26,7 @@ export class OvermindClient {
|
|
|
26
26
|
private version: string = version;
|
|
27
27
|
private baseUrl: string;
|
|
28
28
|
private apiKey: string;
|
|
29
|
+
private sdk?: NodeSDK;
|
|
29
30
|
public experimentSlug?: string;
|
|
30
31
|
|
|
31
32
|
constructor(config: OvermindClientConfig) {
|
|
@@ -51,14 +52,14 @@ export class OvermindClient {
|
|
|
51
52
|
instrumentations?: Instrumentation[];
|
|
52
53
|
spanProcessors?: SpanProcessor[];
|
|
53
54
|
enableBatching: boolean;
|
|
54
|
-
enabledProviders:
|
|
55
|
+
enabledProviders: { openai: OpenAI };
|
|
55
56
|
}) {
|
|
56
|
-
const traceExporter =
|
|
57
|
+
const traceExporter = this.baseUrl
|
|
57
58
|
? new OTLPTraceExporter({
|
|
58
|
-
url: `${this.baseUrl}/api/v1/traces/create`,
|
|
59
59
|
headers: {
|
|
60
|
-
"X-API-TOKEN":
|
|
60
|
+
"X-API-TOKEN": this.apiKey,
|
|
61
61
|
},
|
|
62
|
+
url: `${this.baseUrl}/api/v1/traces/create`,
|
|
62
63
|
})
|
|
63
64
|
: new ConsoleSpanExporter();
|
|
64
65
|
|
|
@@ -80,16 +81,20 @@ export class OvermindClient {
|
|
|
80
81
|
const openaiInstrumentation = new OpenAIInstrumentation({
|
|
81
82
|
enabled: true,
|
|
82
83
|
});
|
|
83
|
-
openaiInstrumentation.manuallyInstrument(
|
|
84
|
+
openaiInstrumentation.manuallyInstrument(config.enabledProviders.openai);
|
|
84
85
|
instrumentations.push(openaiInstrumentation);
|
|
85
86
|
}
|
|
86
87
|
|
|
87
|
-
|
|
88
|
+
this.sdk = new NodeSDK({
|
|
89
|
+
instrumentations: [...instrumentations],
|
|
88
90
|
resource,
|
|
89
91
|
spanProcessors,
|
|
90
|
-
instrumentations: [...instrumentations],
|
|
91
92
|
});
|
|
92
93
|
|
|
93
|
-
|
|
94
|
+
this.sdk.start();
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
async shutdown() {
|
|
98
|
+
await this.sdk?.shutdown();
|
|
94
99
|
}
|
|
95
100
|
}
|