weflayr 0.28.0 → 0.29.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "weflayr",
3
- "version": "0.28.0",
3
+ "version": "0.29.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",
@@ -39,7 +39,7 @@
39
39
  "async-retry": "^1.3.3"
40
40
  },
41
41
  "overrides": {
42
- "js-yaml": "^4.3.1"
42
+ "js-yaml": "^4.3.2"
43
43
  },
44
44
  "devDependencies": {
45
45
  "@hey-api/openapi-ts": "^0.99.0",
@@ -14,7 +14,7 @@ exports.AiSdk = Object.freeze({
14
14
  ELEVENLABS: 'elevenlabs',
15
15
  MISTRAL: 'mistral',
16
16
  });
17
- // Allowed values for `propagateMetadata({ providerNameOverride })`: the actual AI
17
+ // Allowed values for `propagateMetadata({ providerNameOverrideIfTelemetryInstrumentation })`: the actual AI
18
18
  // providers a call can be attributed to. Unlike AiSdk this names providers,
19
19
  // not SDKs — google-genai is an SDK whose calls are labeled google or vertex,
20
20
  // and mistral can also be reached through the OpenAI SDK (OpenAI-compatible
@@ -10,14 +10,14 @@ declare const EXTRA_TAG_PREFIX = "weflayr.tag.";
10
10
  export interface PropagateMetadataOptions {
11
11
  /** Product-side feature triggering the LLM call (e.g. `"onboarding-summary"`). */
12
12
  featureName: string;
13
- /** Name of the end-user / tenant customer the call is made for. */
14
- customerName: string;
15
13
  /**
16
- * Override for the provider seen on the wire. Set this only if it differs
17
- * from the SDK auto-detected by OpenTelemetry, e.g. Mistral calls made
18
- * through the OpenAI SDK, which should be reported as `mistral`.
14
+ * Name of the end-user / tenant customer the call is made for. When
15
+ * omitted, the calls are recorded with no customer. A call sent through the
16
+ * Weflayr AI gateway can name its customer in the request body instead,
17
+ * e.g. `{ ..., weflayr: { customer_name: 'Acme' } }`, which suits a
18
+ * customer known only where the call is made.
19
19
  */
20
- providerNameOverride?: AIProviderName;
20
+ customerName?: string;
21
21
  /**
22
22
  * Arbitrary scalar key/value pairs to attach. Values must be `string`,
23
23
  * `number`, or `boolean` so they survive the ClickHouse `Map(String,
@@ -32,6 +32,15 @@ export interface PropagateMetadataOptions {
32
32
  * hexadecimal characters. When omitted, each invocation creates its own.
33
33
  */
34
34
  featureRunUuid?: string;
35
+ /**
36
+ * Override for the provider seen on the wire, for a call the SDK's telemetry
37
+ * instrumentation records. Set this only if it differs from the SDK
38
+ * auto-detected by OpenTelemetry, e.g. Mistral calls made through the OpenAI
39
+ * SDK, which should be reported as `mistral`. Ignored, with a warning, for a
40
+ * call sent through the Weflayr AI gateway, which reports the provider it
41
+ * called itself.
42
+ */
43
+ providerNameOverrideIfTelemetryInstrumentation?: AIProviderName;
35
44
  }
36
45
  export declare function getMergedMetadataFromContext(parentContext?: Context): Record<string, unknown>;
37
46
  /**
@@ -7,7 +7,8 @@
7
7
  // This file has been modified from its original form:
8
8
  // - Translated from TypeScript to JavaScript
9
9
  // - Replaced Langfuse's fixed schema with Weflayr's structured metadata
10
- // (featureName, customerName, providerNameOverride, extraTags) plus an
10
+ // (featureName, customerName, extraTags,
11
+ // providerNameOverrideIfTelemetryInstrumentation) plus an
11
12
  // auto-generated per-call uuid
12
13
  // - Added `setCallName`, a nested scope naming one LLM call
13
14
  // - Removed asBaggage cross-process propagation (not needed yet)
@@ -45,17 +46,20 @@ function getMergedMetadataFromContext(parentContext) {
45
46
  const existing = ctx.getValue(WEFLAYR_METADATA_CONTEXT_KEY);
46
47
  return existing && typeof existing === 'object' ? { ...existing } : {};
47
48
  }
48
- function _buildAttributes({ featureName, customerName, providerNameOverride, extraTags, spanUuid, }) {
49
+ function _buildAttributes({ featureName, customerName, extraTags, spanUuid, providerNameOverrideIfTelemetryInstrumentation, }) {
49
50
  const attributes = {
50
51
  [FEATURE_NAME_ATTR]: featureName,
51
- [CUSTOMER_NAME_ATTR]: customerName,
52
52
  [UUID_ATTR]: spanUuid,
53
53
  };
54
54
  for (const [key, value] of Object.entries(extraTags)) {
55
55
  attributes[`${EXTRA_TAG_PREFIX}${key}`] = value;
56
56
  }
57
- if (providerNameOverride !== undefined && providerNameOverride !== null) {
58
- attributes[BILLING_PROVIDER_ATTR] = providerNameOverride;
57
+ if (customerName !== undefined && customerName !== null) {
58
+ attributes[CUSTOMER_NAME_ATTR] = customerName;
59
+ }
60
+ if (providerNameOverrideIfTelemetryInstrumentation !== undefined &&
61
+ providerNameOverrideIfTelemetryInstrumentation !== null) {
62
+ attributes[BILLING_PROVIDER_ATTR] = providerNameOverrideIfTelemetryInstrumentation;
59
63
  }
60
64
  return attributes;
61
65
  }
@@ -74,9 +78,8 @@ function createFeatureRunUuid() {
74
78
  return (0, node_crypto_1.randomUUID)().replace(/-/g, '');
75
79
  }
76
80
  function propagateMetadata(options, fn) {
77
- const { featureName, customerName } = options ?? {};
78
- if (featureName == null || customerName == null) {
79
- throw new Error('propagateMetadata: `featureName` and `customerName` are required');
81
+ if (options?.featureName == null) {
82
+ throw new Error('propagateMetadata: `featureName` is required');
80
83
  }
81
84
  if (options.featureRunUuid !== undefined &&
82
85
  !FEATURE_RUN_UUID_PATTERN.test(options.featureRunUuid)) {
@@ -103,13 +106,13 @@ function propagateMetadata(options, fn) {
103
106
  };
104
107
  }
105
108
  function _runWithMetadata(options, fn) {
106
- const { featureName, customerName, providerNameOverride, extraTags, featureRunUuid } = options;
109
+ const { featureName, customerName, extraTags, featureRunUuid, providerNameOverrideIfTelemetryInstrumentation, } = options;
107
110
  return _runWithAttributes(_buildAttributes({
108
111
  featureName,
109
112
  customerName,
110
- providerNameOverride,
111
113
  extraTags: extraTags ?? {},
112
114
  spanUuid: featureRunUuid ?? createFeatureRunUuid(),
115
+ providerNameOverrideIfTelemetryInstrumentation,
113
116
  }), fn);
114
117
  }
115
118
  function _runWithAttributes(attributes, fn) {
@@ -63,7 +63,7 @@ function escapeNonAscii(json) {
63
63
  function buildMetadataHeaderValue() {
64
64
  const metadata = (0, propagation_1.getMergedMetadataFromContext)();
65
65
  if (propagation_1.BILLING_PROVIDER_ATTR in metadata) {
66
- process.emitWarning('propagateMetadata: `providerNameOverride` is ignored for a call sent to the ' +
66
+ process.emitWarning('propagateMetadata: `providerNameOverrideIfTelemetryInstrumentation` is ignored for a call sent to the ' +
67
67
  'Weflayr AI gateway, which reports the provider it called itself');
68
68
  }
69
69
  const payload = {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "weflayr",
3
- "version": "0.28.0",
3
+ "version": "0.29.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",
@@ -39,7 +39,7 @@
39
39
  "async-retry": "^1.3.3"
40
40
  },
41
41
  "overrides": {
42
- "js-yaml": "^4.3.1"
42
+ "js-yaml": "^4.3.2"
43
43
  },
44
44
  "devDependencies": {
45
45
  "@hey-api/openapi-ts": "^0.99.0",