weflayr 0.9.0 → 0.10.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "weflayr",
3
- "version": "0.9.0",
3
+ "version": "0.10.3",
4
4
  "description": "Weflayr Node.js SDK — instrument any LLM client via JS Proxy",
5
5
  "main": "src/index.js",
6
6
  "types": "index.d.ts",
package/src/instrument.js CHANGED
@@ -3,13 +3,15 @@
3
3
  const https = require('https');
4
4
  const http = require('http');
5
5
  const { randomUUID } = require('crypto');
6
+ const { AsyncLocalStorage } = require('async_hooks');
6
7
  const { version: SDK_VERSION } = require('../package.json');
7
8
  const SDK_LANGUAGE = 'javascript';
8
9
 
9
10
  let _config = null;
10
- let _propagated = {};
11
+ const _asyncStore = new AsyncLocalStorage();
11
12
 
12
13
  function configure(intakeUrl, clientId, clientSecret, settings) {
14
+ _asyncStore.enterWith({});
13
15
  if (settings.ignore_fields && settings.allow_fields) {
14
16
  console.warn('[weflayr] both ignore_fields and allow_fields are set - no events will be sent to the intake API');
15
17
  _config = { intakeUrl, clientId, clientSecret, settings, _blocked: true };
@@ -194,7 +196,7 @@ function _extractTags(args) {
194
196
 
195
197
  const tags = {
196
198
  ...(_config.settings.default_tags || {}),
197
- ..._propagated,
199
+ ..._asyncStore.getStore(),
198
200
  ...callTags,
199
201
  };
200
202
 
@@ -202,9 +204,10 @@ function _extractTags(args) {
202
204
  }
203
205
 
204
206
  function weflayr_propagate(key, value) {
205
- _propagated[key] = value;
207
+ _asyncStore.getStore()[key] = value;
206
208
  }
207
209
 
210
+
208
211
  function _isAsyncIterable(value) {
209
212
  return value != null && typeof value[Symbol.asyncIterator] === 'function';
210
213
  }