weflayr 0.1.0 → 0.1.2
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 +2 -12
- package/package.json +2 -2
- package/src/openai.js +4 -2
- package/src/weflayr.js +8 -7
package/README.md
CHANGED
|
@@ -19,13 +19,13 @@ npm install weflayr
|
|
|
19
19
|
|
|
20
20
|
Requires Node.js 18+ and `openai>=4.0.0`.
|
|
21
21
|
|
|
22
|
-
---
|
|
22
|
+
---
|
|
23
23
|
|
|
24
24
|
## Implementation steps
|
|
25
25
|
|
|
26
26
|
### 1. Get your credentials
|
|
27
27
|
|
|
28
|
-
Sign in at [weflayr.com](https://weflayr.com), create a **
|
|
28
|
+
Sign in at [weflayr.com](https://weflayr.com), create a **Flayr**, and copy your `client_id` and `client_secret`.
|
|
29
29
|
|
|
30
30
|
### 2. Set environment variables
|
|
31
31
|
|
|
@@ -121,16 +121,6 @@ By default, message content and prompt text are stripped before sending. Fields
|
|
|
121
121
|
|
|
122
122
|
---
|
|
123
123
|
|
|
124
|
-
## Optional: forward traces to your own collector
|
|
125
|
-
|
|
126
|
-
Set `WEFLAYR_COLLECTOR_ENDPOINT` to also send OTLP traces to a collector of your choice (e.g. Jaeger, Grafana Tempo):
|
|
127
|
-
|
|
128
|
-
```bash
|
|
129
|
-
WEFLAYR_COLLECTOR_ENDPOINT=http://localhost:4318/v1/traces
|
|
130
|
-
```
|
|
131
|
-
|
|
132
|
-
---
|
|
133
|
-
|
|
134
124
|
## Full example
|
|
135
125
|
|
|
136
126
|
```js
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "weflayr",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "Drop-in instrumented wrappers for AI clients with zero-overhead telemetry",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
"homepage": "https://weflayr.com",
|
|
31
31
|
"repository": {
|
|
32
32
|
"type": "git",
|
|
33
|
-
"url": "git+https://github.com/WeFlayr/public-mirror-js-sdk"
|
|
33
|
+
"url": "git+https://github.com/WeFlayr/public-mirror-js-sdk.git"
|
|
34
34
|
},
|
|
35
35
|
"bugs": {
|
|
36
36
|
"url": "https://github.com/WeFlayr/public-mirror-js-sdk/issues"
|
package/src/openai.js
CHANGED
|
@@ -104,11 +104,13 @@ const PATCHED_PATHS = new Set(ROUTES.map((r) => r.name));
|
|
|
104
104
|
export function instrument(client) {
|
|
105
105
|
const tracer = trace.getTracer("weflayr-openai");
|
|
106
106
|
|
|
107
|
+
const providerOpts = { provider: "openai" };
|
|
108
|
+
|
|
107
109
|
// 1. Patch all explicitly defined routes with their precise extractors.
|
|
108
110
|
for (const route of ROUTES) {
|
|
109
|
-
route.set(client, makeWrapper(route.get(client), route, tracer));
|
|
111
|
+
route.set(client, makeWrapper(route.get(client), route, tracer, providerOpts));
|
|
110
112
|
}
|
|
111
113
|
|
|
112
114
|
// 2. Wrap the whole client in a Proxy that handles anything not in ROUTES.
|
|
113
|
-
return deepFallbackProxy(client, tracer, PATCHED_PATHS);
|
|
115
|
+
return deepFallbackProxy(client, tracer, PATCHED_PATHS, "", providerOpts);
|
|
114
116
|
}
|
package/src/weflayr.js
CHANGED
|
@@ -117,13 +117,14 @@ export async function setupWeflayr() {
|
|
|
117
117
|
new BasicTracerProvider({ spanProcessors }).register();
|
|
118
118
|
}
|
|
119
119
|
|
|
120
|
-
export function makeWrapper(original, route, tracer) {
|
|
120
|
+
export function makeWrapper(original, route, tracer, { provider } = {}) {
|
|
121
121
|
return async function ({ tags: callTags, ...params }) {
|
|
122
122
|
const tags = { ...GLOBAL_TAGS, ...callTags };
|
|
123
|
+
const before = { ...(provider ? { provider } : {}), ...route.before(params) };
|
|
123
124
|
const span = tracer.startSpan(route.name, {
|
|
124
125
|
attributes: {
|
|
125
126
|
"weflayr.event_id": randomUUID(),
|
|
126
|
-
"weflayr.before": JSON.stringify(
|
|
127
|
+
"weflayr.before": JSON.stringify(before),
|
|
127
128
|
"weflayr.tags": JSON.stringify(tags),
|
|
128
129
|
},
|
|
129
130
|
});
|
|
@@ -144,7 +145,7 @@ export function makeWrapper(original, route, tracer) {
|
|
|
144
145
|
};
|
|
145
146
|
}
|
|
146
147
|
|
|
147
|
-
export function makeFallbackWrapper(fn, target, name, tracer) {
|
|
148
|
+
export function makeFallbackWrapper(fn, target, name, tracer, { provider } = {}) {
|
|
148
149
|
return function (...args) {
|
|
149
150
|
let callArgs = args;
|
|
150
151
|
let tags = GLOBAL_TAGS;
|
|
@@ -156,7 +157,7 @@ export function makeFallbackWrapper(fn, target, name, tracer) {
|
|
|
156
157
|
tags = { ...GLOBAL_TAGS, ...callTags };
|
|
157
158
|
}
|
|
158
159
|
|
|
159
|
-
const before = { model: callArgs[0]?.model };
|
|
160
|
+
const before = { ...(provider ? { provider } : {}), model: callArgs[0]?.model };
|
|
160
161
|
const span = tracer.startSpan(name, {
|
|
161
162
|
attributes: {
|
|
162
163
|
"weflayr.event_id": randomUUID(),
|
|
@@ -204,7 +205,7 @@ export function makeFallbackWrapper(fn, target, name, tracer) {
|
|
|
204
205
|
|
|
205
206
|
// Recursively wraps every function on `obj` that is not already covered by patchedPaths.
|
|
206
207
|
// `path` tracks the dotted property path (e.g. "images.generate").
|
|
207
|
-
export function deepFallbackProxy(obj, tracer, patchedPaths, path = "") {
|
|
208
|
+
export function deepFallbackProxy(obj, tracer, patchedPaths, path = "", opts = {}) {
|
|
208
209
|
return new Proxy(obj, {
|
|
209
210
|
get(target, prop) {
|
|
210
211
|
if (typeof prop !== "string") return Reflect.get(target, prop);
|
|
@@ -215,11 +216,11 @@ export function deepFallbackProxy(obj, tracer, patchedPaths, path = "") {
|
|
|
215
216
|
if (typeof val === "function") {
|
|
216
217
|
// Already patched by explicit routes — return the existing wrapper as-is.
|
|
217
218
|
if (patchedPaths.has(fullPath)) return val;
|
|
218
|
-
return makeFallbackWrapper(val, target, fullPath, tracer);
|
|
219
|
+
return makeFallbackWrapper(val, target, fullPath, tracer, opts);
|
|
219
220
|
}
|
|
220
221
|
|
|
221
222
|
if (val !== null && typeof val === "object") {
|
|
222
|
-
return deepFallbackProxy(val, tracer, patchedPaths, fullPath);
|
|
223
|
+
return deepFallbackProxy(val, tracer, patchedPaths, fullPath, opts);
|
|
223
224
|
}
|
|
224
225
|
|
|
225
226
|
return val;
|