@overmind-lab/trace-sdk 0.0.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 +124 -0
- package/biome.json +74 -0
- package/package.json +28 -0
- package/src/instrumentation-openai/image-wrappers.ts +546 -0
- package/src/instrumentation-openai/index.ts +757 -0
- package/src/instrumentation-openai/types.ts +34 -0
- package/src/overmind-client.ts +95 -0
package/README.md
ADDED
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
# overmind-js
|
|
2
|
+
|
|
3
|
+
JavaScript/TypeScript SDK for [Overmind](https://overmindlab.ai) — automatic LLM observability powered by OpenTelemetry.
|
|
4
|
+
|
|
5
|
+
Instrument your OpenAI calls with a single `initTracing()` call. Traces are exported to the Overmind platform with zero changes to your existing AI code.
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## Installation
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
bun add overmind-js openai
|
|
13
|
+
# or
|
|
14
|
+
npm install overmind-js openai
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
---
|
|
18
|
+
|
|
19
|
+
## Quick Start with OpenAI
|
|
20
|
+
|
|
21
|
+
```ts
|
|
22
|
+
import { OpenAI } from "openai";
|
|
23
|
+
import { OvermindClient } from "overmind-js";
|
|
24
|
+
|
|
25
|
+
// 1. Create the client
|
|
26
|
+
const overmindClient = new OvermindClient({
|
|
27
|
+
apiKey: process.env.OVERMIND_API_KEY!,
|
|
28
|
+
appName: "my fintech app",
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
// 2. Initialize tracing — must be called before any OpenAI calls
|
|
32
|
+
overmindClient.initTracing({
|
|
33
|
+
enableBatching: false,
|
|
34
|
+
enabledProviders: { openai: true },
|
|
35
|
+
instrumentations: [],
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
// 3. Use OpenAI as normal — all calls are automatically traced
|
|
39
|
+
const openai = new OpenAI({
|
|
40
|
+
apiKey: process.env.OPENAI_API_KEY,
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
const response = await openai.chat.completions.create({
|
|
44
|
+
model: "gpt-4o-mini",
|
|
45
|
+
messages: [{ role: "user", content: "Hello, how are you?" }],
|
|
46
|
+
});
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
Traces are sent automatically to `https://api.overmindlab.ai` and will appear in your Overmind dashboard.
|
|
50
|
+
|
|
51
|
+
---
|
|
52
|
+
|
|
53
|
+
## Configuration
|
|
54
|
+
|
|
55
|
+
### `OvermindClient(config)`
|
|
56
|
+
|
|
57
|
+
| Option | Type | Required | Description |
|
|
58
|
+
|---|---|---|---|
|
|
59
|
+
| `apiKey` | `string` | Yes | Your Overmind API key. Falls back to `OVERMIND_API_KEY` env var. |
|
|
60
|
+
| `appName` | `string` | No | Name of your service, shown in the dashboard. Defaults to `"overmind-js"`. |
|
|
61
|
+
| `baseUrl` | `string` | No | Override the Overmind ingest endpoint. Defaults to `OVERMIND_TRACES_URL` env var or `https://api.overmindlab.ai`. |
|
|
62
|
+
|
|
63
|
+
### `initTracing(options)`
|
|
64
|
+
|
|
65
|
+
| Option | Type | Required | Description |
|
|
66
|
+
|---|---|---|---|
|
|
67
|
+
| `enabledProviders` | `{ openai?: boolean; anthropic?: boolean }` | Yes | Which LLM providers to instrument. |
|
|
68
|
+
| `enableBatching` | `boolean` | Yes | `true` to batch spans before export (recommended for production), `false` to export immediately. |
|
|
69
|
+
| `instrumentations` | `Instrumentation[]` | No | Additional OpenTelemetry instrumentations to register. |
|
|
70
|
+
| `spanProcessors` | `SpanProcessor[]` | No | Additional span processors (e.g. custom exporters). |
|
|
71
|
+
|
|
72
|
+
---
|
|
73
|
+
|
|
74
|
+
## Environment Variables
|
|
75
|
+
|
|
76
|
+
| Variable | Description |
|
|
77
|
+
|---|---|
|
|
78
|
+
| `OVERMIND_API_KEY` | Your Overmind API key |
|
|
79
|
+
| `OVERMIND_TRACES_URL` | Override the traces ingest base URL |
|
|
80
|
+
| `DEPLOYMENT_ENVIRONMENT` | Tag traces with an environment (e.g. `production`, `staging`). Defaults to `development`. |
|
|
81
|
+
| `OPENAI_API_KEY` | Your OpenAI API key |
|
|
82
|
+
|
|
83
|
+
---
|
|
84
|
+
|
|
85
|
+
## What Gets Traced
|
|
86
|
+
|
|
87
|
+
When `enabledProviders: { openai: true }` is set, the SDK automatically captures:
|
|
88
|
+
|
|
89
|
+
- Prompts and completions
|
|
90
|
+
- Model name, temperature, top-p, max tokens
|
|
91
|
+
- Token usage
|
|
92
|
+
- Latency per request
|
|
93
|
+
- Errors and exceptions
|
|
94
|
+
|
|
95
|
+
All data is attached to OpenTelemetry spans and exported to Overmind.
|
|
96
|
+
|
|
97
|
+
---
|
|
98
|
+
|
|
99
|
+
## Production Recommendations
|
|
100
|
+
|
|
101
|
+
Enable batching in production to reduce network overhead:
|
|
102
|
+
|
|
103
|
+
```ts
|
|
104
|
+
overmindClient.initTracing({
|
|
105
|
+
enableBatching: true, // buffer spans and flush in batches
|
|
106
|
+
enabledProviders: { openai: true },
|
|
107
|
+
});
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
Use `enableBatching: false` during local development to see traces immediately.
|
|
111
|
+
|
|
112
|
+
---
|
|
113
|
+
|
|
114
|
+
## Resource Attributes
|
|
115
|
+
|
|
116
|
+
Every trace is tagged with the following attributes automatically:
|
|
117
|
+
|
|
118
|
+
| Attribute | Value |
|
|
119
|
+
|---|---|
|
|
120
|
+
| `service.name` | Value of `appName` |
|
|
121
|
+
| `service.version` | SDK version |
|
|
122
|
+
| `deployment.environment` | `DEPLOYMENT_ENVIRONMENT` env var or `"development"` |
|
|
123
|
+
| `overmind.sdk.name` | `overmind-js` |
|
|
124
|
+
| `overmind.sdk.version` | SDK version |
|
package/biome.json
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://biomejs.dev/schemas/2.4.3/schema.json",
|
|
3
|
+
"assist": {
|
|
4
|
+
"actions": {
|
|
5
|
+
"source": {
|
|
6
|
+
"organizeImports": {
|
|
7
|
+
"level": "on",
|
|
8
|
+
"options": {
|
|
9
|
+
"groups": [
|
|
10
|
+
["@opentelemetry/**"],
|
|
11
|
+
":BLANK_LINE:",
|
|
12
|
+
[":PACKAGE:", ":PACKAGE_WITH_PROTOCOL:"],
|
|
13
|
+
":BLANK_LINE:",
|
|
14
|
+
[":PATH:"],
|
|
15
|
+
":BLANK_LINE:"
|
|
16
|
+
]
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
"useSortedKeys": {
|
|
20
|
+
"level": "on",
|
|
21
|
+
"options": {}
|
|
22
|
+
},
|
|
23
|
+
"useSortedProperties": {
|
|
24
|
+
"level": "on",
|
|
25
|
+
"options": {}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
"enabled": true
|
|
30
|
+
},
|
|
31
|
+
"files": {
|
|
32
|
+
"ignoreUnknown": true,
|
|
33
|
+
"includes": ["**"]
|
|
34
|
+
},
|
|
35
|
+
"formatter": {
|
|
36
|
+
"attributePosition": "auto",
|
|
37
|
+
"enabled": true,
|
|
38
|
+
"formatWithErrors": false,
|
|
39
|
+
"indentStyle": "space",
|
|
40
|
+
"indentWidth": 2,
|
|
41
|
+
"lineEnding": "lf",
|
|
42
|
+
"lineWidth": 100
|
|
43
|
+
},
|
|
44
|
+
"javascript": {
|
|
45
|
+
"formatter": {
|
|
46
|
+
"lineWidth": 100,
|
|
47
|
+
"quoteStyle": "double",
|
|
48
|
+
"trailingCommas": "es5"
|
|
49
|
+
}
|
|
50
|
+
},
|
|
51
|
+
"json": {
|
|
52
|
+
"formatter": {
|
|
53
|
+
"trailingCommas": "none"
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
"linter": {
|
|
57
|
+
"domains": {
|
|
58
|
+
"project": "recommended",
|
|
59
|
+
"test": "recommended"
|
|
60
|
+
},
|
|
61
|
+
"enabled": true,
|
|
62
|
+
"rules": {
|
|
63
|
+
"suspicious": {
|
|
64
|
+
"noArrayIndexKey": "off",
|
|
65
|
+
"noUnknownAtRules": "off"
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
},
|
|
69
|
+
"vcs": {
|
|
70
|
+
"clientKind": "git",
|
|
71
|
+
"enabled": true,
|
|
72
|
+
"useIgnoreFile": true
|
|
73
|
+
}
|
|
74
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
{
|
|
2
|
+
"dependencies": {
|
|
3
|
+
"@opentelemetry/auto-instrumentations-node": "^0.70.0",
|
|
4
|
+
"@opentelemetry/exporter-trace-otlp-proto": "^0.212.0",
|
|
5
|
+
"@opentelemetry/instrumentation-openai": "^0.10.0",
|
|
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"
|
|
10
|
+
},
|
|
11
|
+
"devDependencies": {
|
|
12
|
+
"@biomejs/biome": "^2.4.3"
|
|
13
|
+
},
|
|
14
|
+
"name": "@overmind-lab/trace-sdk",
|
|
15
|
+
"packageManager": "bun@1.3.5",
|
|
16
|
+
"private": false,
|
|
17
|
+
"publishConfig": {
|
|
18
|
+
"access": "public",
|
|
19
|
+
"tag": "alpha"
|
|
20
|
+
},
|
|
21
|
+
"scripts": {
|
|
22
|
+
"build": "tsc",
|
|
23
|
+
"check": "biome check --write",
|
|
24
|
+
"dev": "tsx watch src/index.ts",
|
|
25
|
+
"format": "biome format --write"
|
|
26
|
+
},
|
|
27
|
+
"version": "0.0.1"
|
|
28
|
+
}
|