@ai-sdk/otel 1.0.162 → 1.0.164

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": "@ai-sdk/otel",
3
- "version": "1.0.162",
3
+ "version": "1.0.164",
4
4
  "type": "module",
5
5
  "license": "Apache-2.0",
6
6
  "sideEffects": false,
@@ -26,12 +26,12 @@
26
26
  }
27
27
  },
28
28
  "dependencies": {
29
- "@ai-sdk/provider": "4.0.35",
29
+ "@ai-sdk/provider": "4.0.36",
30
30
  "@opentelemetry/api": "1.9.1",
31
- "ai": "7.0.162"
31
+ "ai": "7.0.164"
32
32
  },
33
33
  "devDependencies": {
34
- "@ai-sdk/provider-utils": "5.0.74",
34
+ "@ai-sdk/provider-utils": "5.0.75",
35
35
  "@opentelemetry/sdk-metrics": "2.8.0",
36
36
  "@opentelemetry/sdk-trace-base": "2.7.1",
37
37
  "@types/node": "22.19.19",
@@ -50,6 +50,7 @@ import type {
50
50
  import { assembleOperationName } from './assemble-operation-name';
51
51
  import { getBaseTelemetryAttributes } from './get-base-telemetry-attributes';
52
52
  import { getProviderUsageAttributes } from './provider-usage-attributes';
53
+ import { redactToolDefinition } from './redact-tool-definition';
53
54
  import { sanitizeAttributeValue } from './sanitize-attribute-value';
54
55
  import {
55
56
  stringifyForTelemetry,
@@ -664,7 +665,10 @@ export class LegacyOpenTelemetry implements Telemetry {
664
665
  : undefined,
665
666
  },
666
667
  'ai.prompt.tools': {
667
- input: () => event.stepTools?.map(tool => JSON.stringify(tool)),
668
+ input: () =>
669
+ event.stepTools?.map(tool =>
670
+ JSON.stringify(redactToolDefinition(tool)),
671
+ ),
668
672
  },
669
673
  'ai.prompt.toolChoice': {
670
674
  input: () =>
@@ -60,7 +60,9 @@ import {
60
60
  } from './gen-ai-format-messages';
61
61
  import { stringifyDecisionStateForTelemetry } from './stringify-for-telemetry';
62
62
  import { recordErrorOnSpan } from './record-span';
63
+ import { redactToolDefinition } from './redact-tool-definition';
63
64
  import { getProviderUsageAttributes } from './provider-usage-attributes';
65
+ import { getServerAttributes } from './server-attributes';
64
66
  import { sanitizeAttributes } from './sanitize-attribute-value';
65
67
  import { selectAttributes } from './select-attributes';
66
68
  import {
@@ -886,6 +888,7 @@ export class OpenTelemetry implements Telemetry {
886
888
 
887
889
  state.inferenceSpan.setAttributes(
888
890
  selectAttributes(telemetry, {
891
+ ...getServerAttributes(event.request.url),
889
892
  'gen_ai.response.finish_reasons': [event.finishReason],
890
893
  'gen_ai.response.id': event.response.id,
891
894
  'gen_ai.response.model': event.response.modelId,
@@ -1083,7 +1086,8 @@ export class OpenTelemetry implements Telemetry {
1083
1086
 
1084
1087
  const { telemetry } = state;
1085
1088
  const providerName = mapProviderName(event.provider);
1086
- state.inferenceToolDefinitions = event.tools;
1089
+ const toolDefinitions = event.tools?.map(redactToolDefinition);
1090
+ state.inferenceToolDefinitions = toolDefinitions;
1087
1091
  state.inferenceMetrics = {
1088
1092
  startTime: performance.now(),
1089
1093
  startTimestamp: getEventTimestamp(event),
@@ -1133,7 +1137,8 @@ export class OpenTelemetry implements Telemetry {
1133
1137
  },
1134
1138
  },
1135
1139
  'gen_ai.tool.definitions': {
1136
- input: () => (event.tools ? JSON.stringify(event.tools) : undefined),
1140
+ input: () =>
1141
+ toolDefinitions ? JSON.stringify(toolDefinitions) : undefined,
1137
1142
  },
1138
1143
  });
1139
1144
 
@@ -1207,6 +1212,7 @@ export class OpenTelemetry implements Telemetry {
1207
1212
  state.inferenceSpan.setAttributes(
1208
1213
  selectAttributes(telemetry, {
1209
1214
  ...getGenAIClientPerformanceAttributes(event.performance),
1215
+ ...getServerAttributes(event.request?.url),
1210
1216
  'gen_ai.provider.name': providerName,
1211
1217
  'gen_ai.response.finish_reasons': [event.finishReason],
1212
1218
  'gen_ai.response.id': event.responseId,
@@ -0,0 +1,65 @@
1
+ /** Remove provider credentials from a telemetry-only copy of a tool definition. */
2
+ export function redactToolDefinition(
3
+ tool: Record<string, unknown>,
4
+ ): Record<string, unknown> {
5
+ if (tool.type !== 'provider') {
6
+ return tool;
7
+ }
8
+
9
+ const args = tool.args;
10
+ if (!isRecord(args)) return tool;
11
+
12
+ if (tool.id === 'openai.mcp') {
13
+ return {
14
+ ...tool,
15
+ args: {
16
+ ...args,
17
+ ...(args.authorization != null ? { authorization: '[redacted]' } : {}),
18
+ ...(isRecord(args.headers)
19
+ ? {
20
+ headers: Object.fromEntries(
21
+ Object.keys(args.headers).map(name => [name, '[redacted]']),
22
+ ),
23
+ }
24
+ : {}),
25
+ },
26
+ };
27
+ }
28
+
29
+ const containerKey =
30
+ tool.id === 'openai.code_interpreter'
31
+ ? 'container'
32
+ : tool.id === 'openai.shell'
33
+ ? 'environment'
34
+ : undefined;
35
+ if (containerKey == null) return tool;
36
+
37
+ const container = args[containerKey];
38
+ if (!isRecord(container)) return tool;
39
+ const networkPolicy = container.networkPolicy;
40
+ if (!isRecord(networkPolicy) || !Array.isArray(networkPolicy.domainSecrets)) {
41
+ return tool;
42
+ }
43
+
44
+ return {
45
+ ...tool,
46
+ args: {
47
+ ...args,
48
+ [containerKey]: {
49
+ ...container,
50
+ networkPolicy: {
51
+ ...networkPolicy,
52
+ domainSecrets: networkPolicy.domainSecrets.map(secret =>
53
+ isRecord(secret) && 'value' in secret
54
+ ? { ...secret, value: '[redacted]' }
55
+ : secret,
56
+ ),
57
+ },
58
+ },
59
+ },
60
+ };
61
+ }
62
+
63
+ function isRecord(value: unknown): value is Record<string, unknown> {
64
+ return value != null && typeof value === 'object' && !Array.isArray(value);
65
+ }
@@ -0,0 +1,26 @@
1
+ /** Only record the known transport destination, never infer a provider backend. */
2
+ export function getServerAttributes(url: string | undefined): {
3
+ 'server.address'?: string;
4
+ 'server.port'?: number;
5
+ } {
6
+ if (url == null) return {};
7
+
8
+ try {
9
+ const endpoint = new URL(url);
10
+ if (endpoint.protocol !== 'http:' && endpoint.protocol !== 'https:') {
11
+ return {};
12
+ }
13
+
14
+ return {
15
+ 'server.address': endpoint.hostname.replace(/^\[|\]$/g, ''),
16
+ 'server.port':
17
+ endpoint.port !== ''
18
+ ? Number(endpoint.port)
19
+ : endpoint.protocol === 'https:'
20
+ ? 443
21
+ : 80,
22
+ };
23
+ } catch {
24
+ return {};
25
+ }
26
+ }