weflayr 0.30.0 → 0.31.0
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/dist/package.json +9 -9
- package/dist/src/api/generated/facade.gen.d.ts +1436 -10
- package/dist/src/api/generated/facade.gen.js +24 -1
- package/dist/src/api/generated/index.d.ts +2 -2
- package/dist/src/api/generated/index.js +24 -1
- package/dist/src/api/generated/sdk.gen.d.ts +97 -5
- package/dist/src/api/generated/sdk.gen.js +256 -5
- package/dist/src/api/generated/types.gen.d.ts +4527 -741
- package/dist/src/instrumentation/anthropic/get_streaming_accumulation_telemetry.d.ts +6 -4
- package/dist/src/instrumentation/anthropic/get_streaming_accumulation_telemetry.js +22 -5
- package/dist/src/instrumentation/bedrock/{get_cache_telemetry.d.ts → get_cache_and_reasoning_telemetry.d.ts} +7 -0
- package/dist/src/instrumentation/bedrock/{get_cache_telemetry.js → get_cache_and_reasoning_telemetry.js} +25 -2
- package/dist/src/instrumentation/bedrock/get_streaming_output_message_telemetry.d.ts +6 -0
- package/dist/src/instrumentation/bedrock/get_streaming_output_message_telemetry.js +18 -2
- package/dist/src/instrumentation/bedrock/set_telemetry_attributes.js +2 -2
- package/dist/src/instrumentation/mistral/full_instrumentation.d.ts +10 -4
- package/dist/src/instrumentation/mistral/full_instrumentation.js +47 -14
- package/dist/src/instrumentation/mistral/get_streamed_reasoning_telemetry.d.ts +38 -0
- package/dist/src/instrumentation/mistral/get_streamed_reasoning_telemetry.js +72 -0
- package/dist/src/instrumentation/openai/get_streaming_usage.d.ts +5 -2
- package/dist/src/instrumentation/openai/get_streaming_usage.js +10 -2
- package/dist/src/otel/exporter.d.ts +1 -1
- package/dist/src/otel/span-filter.d.ts +1 -1
- package/dist/src/otel/span-processor.d.ts +1 -1
- package/dist/src/otel/span-processor.js +3 -3
- package/dist/src/propagate-metadata-to-gateway.js +38 -11
- package/dist/src/setup.js +19 -7
- package/package.json +9 -9
|
@@ -2,10 +2,15 @@
|
|
|
2
2
|
/**
|
|
3
3
|
* Send the metadata of a call to the Weflayr AI gateway in a request header.
|
|
4
4
|
*/
|
|
5
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
6
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
7
|
+
};
|
|
5
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
9
|
exports._state = exports.PUBLIC_GATEWAY_HOST = exports.WEFLAYR_METADATA_HEADER = void 0;
|
|
7
10
|
exports.buildMetadataHeaderValue = buildMetadataHeaderValue;
|
|
8
11
|
exports.enablePropagateMetadataToGateway = enablePropagateMetadataToGateway;
|
|
12
|
+
const node_fs_1 = __importDefault(require("node:fs"));
|
|
13
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
9
14
|
const api_1 = require("@opentelemetry/api");
|
|
10
15
|
const logger_1 = require("./logger");
|
|
11
16
|
const propagation_1 = require("./otel/propagation");
|
|
@@ -155,6 +160,30 @@ function addMetadataHeader(client, options) {
|
|
|
155
160
|
(0, logger_1.debug)('enablePropagateMetadataToGateway: could not add the metadata header');
|
|
156
161
|
}
|
|
157
162
|
}
|
|
163
|
+
// The ES module build sits next to the CommonJS one (`index.mjs` next to
|
|
164
|
+
// `index.js`), as openai's package exports name it.
|
|
165
|
+
function requireEsmOpenAI() {
|
|
166
|
+
const esmEntryPath = node_path_1.default.join(node_path_1.default.dirname(require.resolve('openai')), 'index.mjs');
|
|
167
|
+
// An openai version with no ES module build has only its CommonJS class.
|
|
168
|
+
if (!node_fs_1.default.existsSync(esmEntryPath)) {
|
|
169
|
+
return undefined;
|
|
170
|
+
}
|
|
171
|
+
return require(esmEntryPath).OpenAI;
|
|
172
|
+
}
|
|
173
|
+
function patchPrepareOptions(OpenAI) {
|
|
174
|
+
// `prepareOptions` is the openai client's documented hook for mutating a
|
|
175
|
+
// request's options, and it runs for every endpoint, streaming or not.
|
|
176
|
+
const originalPrepareOptions = OpenAI.prototype.prepareOptions;
|
|
177
|
+
if (typeof originalPrepareOptions !== 'function') {
|
|
178
|
+
throw new Error('weflayr.enablePropagateMetadataToGateway: the openai client has no ' +
|
|
179
|
+
'prepareOptions hook, so the installed openai version cannot send the ' +
|
|
180
|
+
'metadata header.');
|
|
181
|
+
}
|
|
182
|
+
OpenAI.prototype.prepareOptions = async function prepareOptions(options) {
|
|
183
|
+
await originalPrepareOptions.call(this, options);
|
|
184
|
+
addMetadataHeader(this, options);
|
|
185
|
+
};
|
|
186
|
+
}
|
|
158
187
|
/**
|
|
159
188
|
* Send `propagateMetadata` and `setCallName` values to the Weflayr AI gateway.
|
|
160
189
|
*
|
|
@@ -196,18 +225,16 @@ function enablePropagateMetadataToGateway(gatewayBaseUrl) {
|
|
|
196
225
|
'call the Weflayr AI gateway. Install it with: npm install openai\n' +
|
|
197
226
|
`Underlying error: ${err.message}`);
|
|
198
227
|
}
|
|
199
|
-
//
|
|
200
|
-
//
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
228
|
+
// openai ships a CommonJS and an ES module build, each with its own client
|
|
229
|
+
// class: an app writing `import OpenAI from 'openai'` gets the ES module one,
|
|
230
|
+
// which `require` never returns. Node loads that build with `require` too.
|
|
231
|
+
// It is loaded before any class is patched, so a build failing to load
|
|
232
|
+
// leaves both unpatched and a later call patches each once.
|
|
233
|
+
const esmOpenAI = requireEsmOpenAI();
|
|
234
|
+
patchPrepareOptions(OpenAI);
|
|
235
|
+
if (esmOpenAI !== undefined && esmOpenAI !== OpenAI) {
|
|
236
|
+
patchPrepareOptions(esmOpenAI);
|
|
206
237
|
}
|
|
207
|
-
OpenAI.prototype.prepareOptions = async function prepareOptions(options) {
|
|
208
|
-
await originalPrepareOptions.call(this, options);
|
|
209
|
-
addMetadataHeader(this, options);
|
|
210
|
-
};
|
|
211
238
|
exports._state.openaiClientsPatched = true;
|
|
212
239
|
(0, logger_1.debug)('enablePropagateMetadataToGateway: patched the openai client gatewayHostAndPort=%s', exports._state.gatewayHostAndPort ?? exports.PUBLIC_GATEWAY_HOST);
|
|
213
240
|
}
|
package/dist/src/setup.js
CHANGED
|
@@ -4,7 +4,9 @@ exports._state = void 0;
|
|
|
4
4
|
exports.setup = setup;
|
|
5
5
|
exports.flush = flush;
|
|
6
6
|
const api_1 = require("@opentelemetry/api");
|
|
7
|
-
const
|
|
7
|
+
const context_async_hooks_1 = require("@opentelemetry/context-async-hooks");
|
|
8
|
+
const core_1 = require("@opentelemetry/core");
|
|
9
|
+
const sdk_trace_1 = require("@opentelemetry/sdk-trace");
|
|
8
10
|
const resources_1 = require("@opentelemetry/resources");
|
|
9
11
|
const exporter_1 = require("./otel/exporter");
|
|
10
12
|
const span_processor_1 = require("./otel/span-processor");
|
|
@@ -18,7 +20,7 @@ exports._state = {
|
|
|
18
20
|
beforeExitListener: null,
|
|
19
21
|
};
|
|
20
22
|
// `trace.getTracerProvider()` returns a ProxyTracerProvider that forwards to
|
|
21
|
-
// whoever called
|
|
23
|
+
// whoever called `trace.setGlobalTracerProvider()` first. Unwrap it to reach the real provider.
|
|
22
24
|
// The delegate/registration internals aren't part of the public TracerProvider
|
|
23
25
|
// type, so this reaches into them dynamically.
|
|
24
26
|
function _unwrapTracerProvider(p) {
|
|
@@ -28,7 +30,7 @@ function _unwrapTracerProvider(p) {
|
|
|
28
30
|
}
|
|
29
31
|
return p;
|
|
30
32
|
}
|
|
31
|
-
// `
|
|
33
|
+
// The SDK `TracerProvider` has no public `addSpanProcessor` API —
|
|
32
34
|
// processors are construction-time only. To attach to a provider somebody
|
|
33
35
|
// else owns, we splice into the internal MultiSpanProcessor. This matches
|
|
34
36
|
// the actual public OTel JS guidance for composing post-construction.
|
|
@@ -47,6 +49,16 @@ function _attachProcessorToExistingProvider(provider, processor) {
|
|
|
47
49
|
}
|
|
48
50
|
return false;
|
|
49
51
|
}
|
|
52
|
+
// Registers the provider, an AsyncLocalStorage context manager (which
|
|
53
|
+
// `propagateMetadata` relies on) and the W3C trace context + baggage
|
|
54
|
+
// propagators. Each global is kept if something else already set it.
|
|
55
|
+
function _registerGlobally(tracerProvider) {
|
|
56
|
+
api_1.trace.setGlobalTracerProvider(tracerProvider);
|
|
57
|
+
api_1.context.setGlobalContextManager(new context_async_hooks_1.AsyncLocalStorageContextManager().enable());
|
|
58
|
+
api_1.propagation.setGlobalPropagator(new core_1.CompositePropagator({
|
|
59
|
+
propagators: [new core_1.W3CTraceContextPropagator(), new core_1.W3CBaggagePropagator()],
|
|
60
|
+
}));
|
|
61
|
+
}
|
|
50
62
|
/**
|
|
51
63
|
* Configure the Weflayr SDK.
|
|
52
64
|
*
|
|
@@ -88,7 +100,7 @@ function setup(options) {
|
|
|
88
100
|
});
|
|
89
101
|
// Adopt an existing TracerProvider when there is one — e.g. the user already
|
|
90
102
|
// configured Datadog/Honeycomb/OTel, or called weflayr.setup() before.
|
|
91
|
-
//
|
|
103
|
+
// trace.setGlobalTracerProvider() silently refuses to override the proxy if another
|
|
92
104
|
// provider is already wired in, so naively creating a new provider would
|
|
93
105
|
// leave our processor attached to a dead one and we'd drop every LLM span.
|
|
94
106
|
const currentTracerProvider = _unwrapTracerProvider(api_1.trace.getTracerProvider());
|
|
@@ -97,15 +109,15 @@ function setup(options) {
|
|
|
97
109
|
tracerProvider = currentTracerProvider;
|
|
98
110
|
}
|
|
99
111
|
else {
|
|
100
|
-
const
|
|
112
|
+
const sdkTracerProvider = new sdk_trace_1.TracerProvider({
|
|
101
113
|
resource: (0, resources_1.resourceFromAttributes)({
|
|
102
114
|
sdk_version: package_json_1.version,
|
|
103
115
|
sdk_language: SDK_LANGUAGE,
|
|
104
116
|
}),
|
|
105
117
|
spanProcessors: [processor],
|
|
106
118
|
});
|
|
107
|
-
|
|
108
|
-
tracerProvider =
|
|
119
|
+
_registerGlobally(sdkTracerProvider);
|
|
120
|
+
tracerProvider = sdkTracerProvider;
|
|
109
121
|
}
|
|
110
122
|
// beforeExit fires when the event loop empties on a clean exit, giving us a
|
|
111
123
|
// last async tick to drain buffered spans. It does NOT fire on process.exit()
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "weflayr",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.31.0",
|
|
4
4
|
"description": "Weflayr JS/TS SDK — instrument any LLM client",
|
|
5
5
|
"main": "dist/src/index.js",
|
|
6
6
|
"types": "dist/src/index.d.ts",
|
|
@@ -27,15 +27,16 @@
|
|
|
27
27
|
"author": "Weflayr <contact@weflayr.com>",
|
|
28
28
|
"license": "Elastic-2.0",
|
|
29
29
|
"engines": {
|
|
30
|
-
"node": ">=
|
|
30
|
+
"node": ">=22.15.0"
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@opentelemetry/api": "^1.
|
|
34
|
-
"@opentelemetry/
|
|
35
|
-
"@opentelemetry/
|
|
36
|
-
"@opentelemetry/
|
|
37
|
-
"@opentelemetry/
|
|
38
|
-
"@opentelemetry/
|
|
33
|
+
"@opentelemetry/api": "^1.10.0",
|
|
34
|
+
"@opentelemetry/context-async-hooks": "^3.0.0",
|
|
35
|
+
"@opentelemetry/core": "^3.0.0",
|
|
36
|
+
"@opentelemetry/exporter-trace-otlp-http": "^0.300.0",
|
|
37
|
+
"@opentelemetry/instrumentation": "^0.300.0",
|
|
38
|
+
"@opentelemetry/resources": "^3.0.0",
|
|
39
|
+
"@opentelemetry/sdk-trace": "^3.0.0",
|
|
39
40
|
"async-retry": "^1.3.3"
|
|
40
41
|
},
|
|
41
42
|
"overrides": {
|
|
@@ -43,7 +44,6 @@
|
|
|
43
44
|
},
|
|
44
45
|
"devDependencies": {
|
|
45
46
|
"@hey-api/openapi-ts": "^0.99.0",
|
|
46
|
-
"@opentelemetry/context-async-hooks": "^2.8.0",
|
|
47
47
|
"@types/async-retry": "^1.4.9",
|
|
48
48
|
"@types/node": "^26.1.1",
|
|
49
49
|
"eslint": "^10.8.0",
|