@ai-sdk/otel 1.0.161 → 1.0.163

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.
@@ -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
+ }
@@ -1,3 +1,4 @@
1
+ import type { OpenTelemetryIdGenerator } from './durable-span-ids';
1
2
  import type { Attributes, Tracer } from '@opentelemetry/api';
2
3
  import type { TelemetryOptions } from 'ai';
3
4
  import {
@@ -44,6 +45,9 @@ export type OpenTelemetryOptions = {
44
45
  */
45
46
  tracer?: Tracer;
46
47
 
48
+ /** The same bridge registered as the tracer provider's idGenerator and sampler. */
49
+ durable?: OpenTelemetryIdGenerator;
50
+
47
51
  /**
48
52
  * Controls root agent span names for text and object generation.
49
53
  *