weflayr 0.23.0 → 0.26.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/README.md +2 -2
- package/dist/{api → src/api}/generated/facade.gen.d.ts +163 -12
- package/dist/{api → src/api}/generated/facade.gen.js +10 -2
- package/dist/src/api/generated/index.d.ts +2 -0
- package/dist/{api → src/api}/generated/index.js +9 -1
- package/dist/{api → src/api}/generated/sdk.gen.d.ts +35 -3
- package/dist/{api → src/api}/generated/sdk.gen.js +88 -4
- package/{src/api/generated/types.gen.ts → dist/src/api/generated/types.gen.d.ts} +692 -116
- package/dist/{api → src/api}/makeEndpoint.js +1 -3
- package/dist/src/auto-instrument.d.ts +42 -0
- package/dist/src/auto-instrument.js +156 -0
- package/dist/src/index.d.ts +9 -0
- package/dist/src/index.js +49 -0
- package/dist/src/instrumentation/anthropic/get_cache_and_reasoning_telemetry.d.ts +20 -0
- package/dist/src/instrumentation/anthropic/get_cache_and_reasoning_telemetry.js +114 -0
- package/dist/src/instrumentation/anthropic/get_cache_config_telemetry.d.ts +28 -0
- package/dist/src/instrumentation/anthropic/get_cache_config_telemetry.js +92 -0
- package/dist/src/instrumentation/anthropic/get_streaming_accumulation_telemetry.d.ts +25 -0
- package/dist/src/instrumentation/anthropic/get_streaming_accumulation_telemetry.js +141 -0
- package/dist/src/instrumentation/anthropic/get_structured_output_schema_telemetry.d.ts +9 -0
- package/dist/src/instrumentation/anthropic/get_structured_output_schema_telemetry.js +17 -0
- package/dist/src/instrumentation/anthropic/get_tool_definitions_telemetry.d.ts +15 -0
- package/dist/src/instrumentation/anthropic/get_tool_definitions_telemetry.js +50 -0
- package/dist/src/instrumentation/anthropic/set_telemetry_attributes.d.ts +15 -0
- package/dist/src/instrumentation/anthropic/set_telemetry_attributes.js +39 -0
- package/dist/src/instrumentation/bedrock/get_cache_config_telemetry.d.ts +22 -0
- package/dist/src/instrumentation/bedrock/get_cache_config_telemetry.js +97 -0
- package/dist/src/instrumentation/bedrock/get_cache_telemetry.d.ts +22 -0
- package/dist/src/instrumentation/bedrock/get_cache_telemetry.js +102 -0
- package/dist/src/instrumentation/bedrock/get_input_message_content_telemetry.d.ts +15 -0
- package/dist/src/instrumentation/bedrock/get_input_message_content_telemetry.js +91 -0
- package/dist/src/instrumentation/bedrock/get_model_id_telemetry.d.ts +21 -0
- package/dist/src/instrumentation/bedrock/get_model_id_telemetry.js +54 -0
- package/dist/src/instrumentation/bedrock/get_reasoning_output_telemetry.d.ts +19 -0
- package/dist/src/instrumentation/bedrock/get_reasoning_output_telemetry.js +81 -0
- package/dist/src/instrumentation/bedrock/get_streaming_output_message_telemetry.d.ts +27 -0
- package/dist/src/instrumentation/bedrock/get_streaming_output_message_telemetry.js +126 -0
- package/dist/src/instrumentation/bedrock/get_tool_call_output_telemetry.d.ts +17 -0
- package/dist/src/instrumentation/bedrock/get_tool_call_output_telemetry.js +85 -0
- package/dist/src/instrumentation/bedrock/get_tool_definitions_telemetry.d.ts +15 -0
- package/dist/src/instrumentation/bedrock/get_tool_definitions_telemetry.js +68 -0
- package/dist/src/instrumentation/bedrock/set_telemetry_attributes.d.ts +18 -0
- package/dist/src/instrumentation/bedrock/set_telemetry_attributes.js +47 -0
- package/dist/src/instrumentation/cohere/get_chat_telemetry.d.ts +23 -0
- package/dist/src/instrumentation/cohere/get_chat_telemetry.js +77 -0
- package/dist/src/instrumentation/cohere/get_embeddings_telemetry.d.ts +18 -0
- package/dist/src/instrumentation/cohere/get_embeddings_telemetry.js +88 -0
- package/dist/src/instrumentation/cohere/get_structured_output_schema_telemetry.d.ts +12 -0
- package/dist/src/instrumentation/cohere/get_structured_output_schema_telemetry.js +18 -0
- package/dist/src/instrumentation/cohere/get_tool_call_output_telemetry.d.ts +31 -0
- package/dist/src/instrumentation/cohere/get_tool_call_output_telemetry.js +106 -0
- package/dist/src/instrumentation/cohere/get_tool_definitions_telemetry.d.ts +27 -0
- package/dist/src/instrumentation/cohere/get_tool_definitions_telemetry.js +75 -0
- package/dist/src/instrumentation/cohere/set_telemetry_attributes.d.ts +17 -0
- package/dist/src/instrumentation/cohere/set_telemetry_attributes.js +44 -0
- package/dist/src/instrumentation/elevenlabs/full_instrumentation.d.ts +28 -0
- package/dist/src/instrumentation/elevenlabs/full_instrumentation.js +209 -0
- package/dist/src/instrumentation/google/get_audio_telemetry.d.ts +9 -0
- package/dist/src/instrumentation/google/get_audio_telemetry.js +28 -0
- package/dist/src/instrumentation/google/get_cache_operations_telemetry.d.ts +23 -0
- package/dist/src/instrumentation/google/get_cache_operations_telemetry.js +154 -0
- package/dist/src/instrumentation/google/get_cache_telemetry.d.ts +16 -0
- package/dist/src/instrumentation/google/get_cache_telemetry.js +38 -0
- package/dist/src/instrumentation/google/get_embeddings_telemetry.d.ts +12 -0
- package/dist/src/instrumentation/google/get_embeddings_telemetry.js +85 -0
- package/dist/src/instrumentation/google/get_provider_name.d.ts +11 -0
- package/{src → dist/src}/instrumentation/google/get_provider_name.js +11 -12
- package/{src/instrumentation/google/get_reasoning_telemetry.js → dist/src/instrumentation/google/get_reasoning_telemetry.d.ts} +1 -11
- package/dist/src/instrumentation/google/get_reasoning_telemetry.js +21 -0
- package/dist/src/instrumentation/google/get_structured_output_schema_telemetry.d.ts +12 -0
- package/dist/src/instrumentation/google/get_structured_output_schema_telemetry.js +19 -0
- package/dist/src/instrumentation/google/set_telemetry_attributes.d.ts +18 -0
- package/dist/src/instrumentation/google/set_telemetry_attributes.js +98 -0
- package/dist/src/instrumentation/openai/get_audio_telemetry.d.ts +25 -0
- package/dist/src/instrumentation/openai/get_audio_telemetry.js +123 -0
- package/dist/src/instrumentation/openai/get_bedrock_mantle_telemetry.d.ts +35 -0
- package/dist/src/instrumentation/openai/get_bedrock_mantle_telemetry.js +148 -0
- package/dist/src/instrumentation/openai/get_cache_and_reasoning_telemetry.d.ts +27 -0
- package/dist/src/instrumentation/openai/get_cache_and_reasoning_telemetry.js +72 -0
- package/dist/src/instrumentation/openai/get_cache_config_telemetry.d.ts +28 -0
- package/dist/src/instrumentation/openai/get_cache_config_telemetry.js +91 -0
- package/dist/src/instrumentation/openai/get_embeddings_telemetry.d.ts +18 -0
- package/dist/src/instrumentation/openai/get_embeddings_telemetry.js +86 -0
- package/dist/src/instrumentation/openai/get_streaming_usage.d.ts +21 -0
- package/dist/src/instrumentation/openai/get_streaming_usage.js +74 -0
- package/dist/src/instrumentation/openai/get_structured_output_schema_telemetry.d.ts +12 -0
- package/dist/src/instrumentation/openai/get_structured_output_schema_telemetry.js +20 -0
- package/dist/src/instrumentation/openai/set_telemetry_attributes.d.ts +17 -0
- package/dist/src/instrumentation/openai/set_telemetry_attributes.js +47 -0
- package/dist/src/instrumentation/shared/get_structured_output_schema_telemetry.d.ts +35 -0
- package/dist/src/instrumentation/shared/get_structured_output_schema_telemetry.js +76 -0
- package/dist/src/instrumentation/vercel/full_instrumentation.d.ts +3 -0
- package/dist/src/instrumentation/vercel/full_instrumentation.js +54 -0
- package/dist/src/instrumentation/vercel/get_cache_creation_telemetry.d.ts +22 -0
- package/dist/src/instrumentation/vercel/get_cache_creation_telemetry.js +66 -0
- package/dist/src/instrumentation/vercel/get_structured_output_schema_telemetry.d.ts +24 -0
- package/dist/src/instrumentation/vercel/get_structured_output_schema_telemetry.js +84 -0
- package/dist/src/logger.d.ts +1 -0
- package/dist/src/logger.js +6 -0
- package/dist/src/otel/exporter.d.ts +19 -0
- package/dist/src/otel/exporter.js +94 -0
- package/dist/src/otel/propagation.d.ts +46 -0
- package/dist/src/otel/propagation.js +110 -0
- package/dist/src/otel/span-filter.d.ts +3 -0
- package/dist/src/otel/span-filter.js +61 -0
- package/dist/src/otel/span-processor.d.ts +55 -0
- package/dist/src/otel/span-processor.js +169 -0
- package/dist/src/otel/vercel-ai-sdk-span-filter.d.ts +12 -0
- package/dist/src/otel/vercel-ai-sdk-span-filter.js +88 -0
- package/dist/src/setup.d.ts +50 -0
- package/dist/src/setup.js +155 -0
- package/package.json +11 -5
- package/.prettierignore +0 -2
- package/.prettierrc.json +0 -7
- package/LICENSE-MIT +0 -21
- package/NOTICE +0 -12
- package/dist/api/generated/index.d.ts +0 -2
- package/dist/api/generated/types.gen.d.ts +0 -749
- package/eslint.config.mjs +0 -36
- package/index.d.ts +0 -167
- package/openapi-ts.config.mjs +0 -9
- package/scripts/generate_facade.mjs +0 -86
- package/src/api/caseConversion.ts +0 -58
- package/src/api/generated/client/client.gen.ts +0 -277
- package/src/api/generated/client/index.ts +0 -27
- package/src/api/generated/client/types.gen.ts +0 -218
- package/src/api/generated/client/utils.gen.ts +0 -316
- package/src/api/generated/client.gen.ts +0 -16
- package/src/api/generated/core/auth.gen.ts +0 -48
- package/src/api/generated/core/bodySerializer.gen.ts +0 -82
- package/src/api/generated/core/params.gen.ts +0 -178
- package/src/api/generated/core/pathSerializer.gen.ts +0 -171
- package/src/api/generated/core/queryKeySerializer.gen.ts +0 -117
- package/src/api/generated/core/serverSentEvents.gen.ts +0 -242
- package/src/api/generated/core/types.gen.ts +0 -110
- package/src/api/generated/core/utils.gen.ts +0 -140
- package/src/api/generated/facade.gen.ts +0 -68
- package/src/api/generated/index.ts +0 -4
- package/src/api/generated/sdk.gen.ts +0 -121
- package/src/api/index.ts +0 -45
- package/src/api/makeEndpoint.ts +0 -54
- package/src/auto-instrument.js +0 -171
- package/src/index.js +0 -19
- package/src/instrumentation/anthropic/get_cache_and_reasoning_telemetry.js +0 -107
- package/src/instrumentation/anthropic/get_streaming_stop_reason_telemetry.js +0 -121
- package/src/instrumentation/anthropic/get_tool_definitions_telemetry.js +0 -50
- package/src/instrumentation/anthropic/set_telemetry_attributes.js +0 -37
- package/src/instrumentation/bedrock/get_cache_telemetry.js +0 -104
- package/src/instrumentation/bedrock/get_input_message_content_telemetry.js +0 -94
- package/src/instrumentation/bedrock/get_streaming_output_message_telemetry.js +0 -87
- package/src/instrumentation/bedrock/set_telemetry_attributes.js +0 -36
- package/src/instrumentation/cohere/get_chat_telemetry.js +0 -88
- package/src/instrumentation/cohere/get_embeddings_telemetry.js +0 -107
- package/src/instrumentation/cohere/set_telemetry_attributes.js +0 -32
- package/src/instrumentation/elevenlabs/full_instrumentation.js +0 -236
- package/src/instrumentation/google/get_audio_telemetry.js +0 -30
- package/src/instrumentation/google/get_cache_telemetry.js +0 -25
- package/src/instrumentation/google/get_embeddings_telemetry.js +0 -99
- package/src/instrumentation/google/set_telemetry_attributes.js +0 -98
- package/src/instrumentation/openai/get_audio_telemetry.js +0 -149
- package/src/instrumentation/openai/get_cache_and_reasoning_telemetry.js +0 -71
- package/src/instrumentation/openai/get_embeddings_telemetry.js +0 -107
- package/src/instrumentation/openai/get_streaming_usage.js +0 -81
- package/src/instrumentation/openai/set_telemetry_attributes.js +0 -39
- package/src/instrumentation/vercel/full_instrumentation.js +0 -44
- package/src/logger.js +0 -8
- package/src/otel/exporter.js +0 -108
- package/src/otel/propagation.js +0 -133
- package/src/otel/span-filter.js +0 -69
- package/src/otel/span-processor.js +0 -162
- package/src/otel/vercel-ai-sdk-span-filter.js +0 -79
- package/src/setup.js +0 -167
- package/tests/api/index.test.js +0 -437
- package/tests/index.test.js +0 -824
- package/tests/instrumentation/anthropic/get_cache_and_reasoning_telemetry.test.js +0 -158
- package/tests/instrumentation/anthropic/get_streaming_stop_reason_telemetry.test.js +0 -117
- package/tests/instrumentation/anthropic/get_tool_definitions_telemetry.test.js +0 -82
- package/tests/instrumentation/bedrock/get_cache_telemetry.test.js +0 -102
- package/tests/instrumentation/bedrock/get_input_message_content_telemetry.test.js +0 -89
- package/tests/instrumentation/bedrock/get_streaming_output_message_telemetry.test.js +0 -87
- package/tests/instrumentation/cohere/get_chat_telemetry.test.js +0 -148
- package/tests/instrumentation/cohere/get_embeddings_telemetry.test.js +0 -132
- package/tests/instrumentation/elevenlabs/full_instrumentation.test.js +0 -258
- package/tests/instrumentation/google/get_embeddings_telemetry.test.js +0 -128
- package/tests/instrumentation/google/get_reasoning_telemetry.test.js +0 -41
- package/tests/instrumentation/google/set_telemetry_attributes.test.js +0 -219
- package/tests/instrumentation/openai/get_audio_telemetry.test.js +0 -170
- package/tests/instrumentation/openai/get_cache_and_reasoning_telemetry.test.js +0 -83
- package/tests/instrumentation/openai/get_embeddings_telemetry.test.js +0 -145
- package/tests/instrumentation/openai/get_streaming_usage.test.js +0 -105
- package/tests/instrumentation/vercel/full_instrumentation.test.js +0 -16
- package/tests/otel/vercel-ai-sdk-span-filter.test.js +0 -159
- package/tsconfig.json +0 -18
- /package/dist/{api → src/api}/caseConversion.d.ts +0 -0
- /package/dist/{api → src/api}/caseConversion.js +0 -0
- /package/dist/{api → src/api}/generated/client/client.gen.d.ts +0 -0
- /package/dist/{api → src/api}/generated/client/client.gen.js +0 -0
- /package/dist/{api → src/api}/generated/client/index.d.ts +0 -0
- /package/dist/{api → src/api}/generated/client/index.js +0 -0
- /package/dist/{api → src/api}/generated/client/types.gen.d.ts +0 -0
- /package/dist/{api → src/api}/generated/client/types.gen.js +0 -0
- /package/dist/{api → src/api}/generated/client/utils.gen.d.ts +0 -0
- /package/dist/{api → src/api}/generated/client/utils.gen.js +0 -0
- /package/dist/{api → src/api}/generated/client.gen.d.ts +0 -0
- /package/dist/{api → src/api}/generated/client.gen.js +0 -0
- /package/dist/{api → src/api}/generated/core/auth.gen.d.ts +0 -0
- /package/dist/{api → src/api}/generated/core/auth.gen.js +0 -0
- /package/dist/{api → src/api}/generated/core/bodySerializer.gen.d.ts +0 -0
- /package/dist/{api → src/api}/generated/core/bodySerializer.gen.js +0 -0
- /package/dist/{api → src/api}/generated/core/params.gen.d.ts +0 -0
- /package/dist/{api → src/api}/generated/core/params.gen.js +0 -0
- /package/dist/{api → src/api}/generated/core/pathSerializer.gen.d.ts +0 -0
- /package/dist/{api → src/api}/generated/core/pathSerializer.gen.js +0 -0
- /package/dist/{api → src/api}/generated/core/queryKeySerializer.gen.d.ts +0 -0
- /package/dist/{api → src/api}/generated/core/queryKeySerializer.gen.js +0 -0
- /package/dist/{api → src/api}/generated/core/serverSentEvents.gen.d.ts +0 -0
- /package/dist/{api → src/api}/generated/core/serverSentEvents.gen.js +0 -0
- /package/dist/{api → src/api}/generated/core/types.gen.d.ts +0 -0
- /package/dist/{api → src/api}/generated/core/types.gen.js +0 -0
- /package/dist/{api → src/api}/generated/core/utils.gen.d.ts +0 -0
- /package/dist/{api → src/api}/generated/core/utils.gen.js +0 -0
- /package/dist/{api → src/api}/generated/types.gen.js +0 -0
- /package/dist/{api → src/api}/index.d.ts +0 -0
- /package/dist/{api → src/api}/index.js +0 -0
- /package/dist/{api → src/api}/makeEndpoint.d.ts +0 -0
|
@@ -1,105 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
// Tests for the OpenAI streamed token-usage complement. It wraps the primary
|
|
4
|
-
// instrumentor's `_streamingWrapPromise` so the streamed usage chunk's counts land
|
|
5
|
-
// on the span as gen_ai.usage.* attributes.
|
|
6
|
-
|
|
7
|
-
const test = require('node:test');
|
|
8
|
-
const assert = require('node:assert/strict');
|
|
9
|
-
|
|
10
|
-
const {
|
|
11
|
-
OpenAIStreamingUsageInstrumentor,
|
|
12
|
-
} = require('../../../src/instrumentation/openai/get_streaming_usage');
|
|
13
|
-
|
|
14
|
-
function fakeSpan() {
|
|
15
|
-
const attrs = {};
|
|
16
|
-
return {
|
|
17
|
-
attrs,
|
|
18
|
-
isRecording: () => true,
|
|
19
|
-
setAttribute(key, value) {
|
|
20
|
-
attrs[key] = value;
|
|
21
|
-
},
|
|
22
|
-
};
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
test('backfills token usage from the streamed usage chunk', async () => {
|
|
26
|
-
const instrumentation = {
|
|
27
|
-
_streamingWrapPromise() {
|
|
28
|
-
return (async function* () {
|
|
29
|
-
yield { choices: [{ delta: { content: 'hi' } }] };
|
|
30
|
-
yield { usage: { prompt_tokens: 12, completion_tokens: 3, total_tokens: 15 } };
|
|
31
|
-
})();
|
|
32
|
-
},
|
|
33
|
-
};
|
|
34
|
-
new OpenAIStreamingUsageInstrumentor().instrument(instrumentation);
|
|
35
|
-
|
|
36
|
-
const span = fakeSpan();
|
|
37
|
-
const stream = instrumentation._streamingWrapPromise({ span });
|
|
38
|
-
for await (const _chunk of stream) {
|
|
39
|
-
void _chunk;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
assert.equal(span.attrs['gen_ai.usage.input_tokens'], 12);
|
|
43
|
-
assert.equal(span.attrs['gen_ai.usage.output_tokens'], 3);
|
|
44
|
-
assert.equal(span.attrs['gen_ai.usage.total_tokens'], 15);
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
test('backfills cached-prompt tokens from the streamed usage chunk', async () => {
|
|
48
|
-
const instrumentation = {
|
|
49
|
-
_streamingWrapPromise() {
|
|
50
|
-
return (async function* () {
|
|
51
|
-
yield {
|
|
52
|
-
usage: {
|
|
53
|
-
prompt_tokens: 1600,
|
|
54
|
-
completion_tokens: 2,
|
|
55
|
-
total_tokens: 1602,
|
|
56
|
-
prompt_tokens_details: { cached_tokens: 1536 },
|
|
57
|
-
},
|
|
58
|
-
};
|
|
59
|
-
})();
|
|
60
|
-
},
|
|
61
|
-
};
|
|
62
|
-
new OpenAIStreamingUsageInstrumentor().instrument(instrumentation);
|
|
63
|
-
|
|
64
|
-
const span = fakeSpan();
|
|
65
|
-
for await (const _chunk of instrumentation._streamingWrapPromise({ span })) {
|
|
66
|
-
void _chunk;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
assert.equal(span.attrs['gen_ai.usage.cache_read_input_tokens'], 1536);
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
test('re-yields every stream chunk unchanged — no telemetry collision with the payload', async () => {
|
|
73
|
-
const emitted = [
|
|
74
|
-
{ choices: [{ delta: { content: 'hel' } }] },
|
|
75
|
-
{ choices: [{ delta: { content: 'lo' } }] },
|
|
76
|
-
{ usage: { prompt_tokens: 12, completion_tokens: 3, total_tokens: 15 } },
|
|
77
|
-
];
|
|
78
|
-
const instrumentation = {
|
|
79
|
-
_streamingWrapPromise() {
|
|
80
|
-
return (async function* () {
|
|
81
|
-
for (const chunk of emitted) yield chunk;
|
|
82
|
-
})();
|
|
83
|
-
},
|
|
84
|
-
};
|
|
85
|
-
new OpenAIStreamingUsageInstrumentor().instrument(instrumentation);
|
|
86
|
-
|
|
87
|
-
const span = fakeSpan();
|
|
88
|
-
const collected = [];
|
|
89
|
-
for await (const chunk of instrumentation._streamingWrapPromise({ span })) {
|
|
90
|
-
collected.push(chunk);
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
// Same count, order, and object identity: backfillUsage re-yields each chunk by
|
|
94
|
-
// reference without copying or mutating it.
|
|
95
|
-
assert.equal(collected.length, emitted.length);
|
|
96
|
-
collected.forEach((chunk, index) => assert.equal(chunk, emitted[index]));
|
|
97
|
-
// …while still backfilling usage off the trailing chunk.
|
|
98
|
-
assert.equal(span.attrs['gen_ai.usage.output_tokens'], 3);
|
|
99
|
-
});
|
|
100
|
-
|
|
101
|
-
test('is a no-op when the instrumentor has no _streamingWrapPromise', () => {
|
|
102
|
-
const instrumentation = {};
|
|
103
|
-
new OpenAIStreamingUsageInstrumentor().instrument(instrumentation);
|
|
104
|
-
assert.equal(instrumentation._streamingWrapPromise, undefined);
|
|
105
|
-
});
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const test = require('node:test');
|
|
4
|
-
const assert = require('node:assert/strict');
|
|
5
|
-
|
|
6
|
-
const {
|
|
7
|
-
VercelAiSdkInstrumentor,
|
|
8
|
-
} = require('../../../src/instrumentation/vercel/full_instrumentation');
|
|
9
|
-
|
|
10
|
-
// The `ai` / `@ai-sdk/otel` packages are app dependencies (not installed in
|
|
11
|
-
// this repo), so instrument() must fail with an actionable install message.
|
|
12
|
-
// The success path (registerTelemetry wiring) is covered by the vercel e2e
|
|
13
|
-
// ingestion scenario.
|
|
14
|
-
test('instrument() without the ai packages installed throws an install hint', () => {
|
|
15
|
-
assert.throws(() => new VercelAiSdkInstrumentor().instrument(), /npm install ai @ai-sdk\/otel/);
|
|
16
|
-
});
|
|
@@ -1,159 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
// The Vercel AI SDK emits aggregate spans around each model call (see
|
|
4
|
-
// src/otel/vercel-ai-sdk-span-filter.js). These tests drive real spans through
|
|
5
|
-
// the WeflayrSpanProcessor and assert exactly one span per model call is
|
|
6
|
-
// exported, for both the ai >= 7 semconv shape and the legacy ai.* shape.
|
|
7
|
-
|
|
8
|
-
const test = require('node:test');
|
|
9
|
-
const assert = require('node:assert/strict');
|
|
10
|
-
const { context, trace } = require('@opentelemetry/api');
|
|
11
|
-
const { BasicTracerProvider, InMemorySpanExporter } = require('@opentelemetry/sdk-trace-base');
|
|
12
|
-
|
|
13
|
-
const { WeflayrSpanProcessor } = require('../../src/otel/span-processor');
|
|
14
|
-
|
|
15
|
-
function buildProviderWithExporter() {
|
|
16
|
-
const exporter = new InMemorySpanExporter();
|
|
17
|
-
const provider = new BasicTracerProvider({
|
|
18
|
-
spanProcessors: [new WeflayrSpanProcessor({ exporter, exportMode: 'immediate' })],
|
|
19
|
-
});
|
|
20
|
-
return { exporter, provider };
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
function startChildSpan(tracer, parentSpan, name, attributes) {
|
|
24
|
-
const parentContext = trace.setSpan(context.active(), parentSpan);
|
|
25
|
-
return tracer.startSpan(name, { attributes }, parentContext);
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
test('semconv shape: only the chat span is exported, not invoke_agent/step/tool', () => {
|
|
29
|
-
const { exporter, provider } = buildProviderWithExporter();
|
|
30
|
-
const tracer = provider.getTracer('gen_ai');
|
|
31
|
-
|
|
32
|
-
const invokeAgent = tracer.startSpan('invoke_agent openai/gpt-4o-mini', {
|
|
33
|
-
attributes: {
|
|
34
|
-
'gen_ai.operation.name': 'invoke_agent',
|
|
35
|
-
'gen_ai.usage.input_tokens': 50,
|
|
36
|
-
'gen_ai.usage.output_tokens': 15,
|
|
37
|
-
},
|
|
38
|
-
});
|
|
39
|
-
const step = startChildSpan(tracer, invokeAgent, 'step 1', {
|
|
40
|
-
'gen_ai.operation.name': 'agent_step',
|
|
41
|
-
});
|
|
42
|
-
const chat = startChildSpan(tracer, step, 'chat openai/gpt-4o-mini', {
|
|
43
|
-
'gen_ai.operation.name': 'chat',
|
|
44
|
-
'gen_ai.usage.input_tokens': 50,
|
|
45
|
-
'gen_ai.usage.output_tokens': 15,
|
|
46
|
-
});
|
|
47
|
-
const tool = startChildSpan(tracer, step, 'execute_tool get_weather', {
|
|
48
|
-
'gen_ai.operation.name': 'execute_tool',
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
chat.end();
|
|
52
|
-
tool.end();
|
|
53
|
-
step.end();
|
|
54
|
-
invokeAgent.end();
|
|
55
|
-
|
|
56
|
-
const exported = exporter.getFinishedSpans();
|
|
57
|
-
assert.equal(exported.length, 1);
|
|
58
|
-
assert.equal(exported[0].name, 'chat openai/gpt-4o-mini');
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
test('semconv shape: nested embeddings span is dropped, the outer one is exported', () => {
|
|
62
|
-
const { exporter, provider } = buildProviderWithExporter();
|
|
63
|
-
const tracer = provider.getTracer('gen_ai');
|
|
64
|
-
|
|
65
|
-
const outerEmbeddings = tracer.startSpan('embeddings openai/text-embedding-3-small', {
|
|
66
|
-
attributes: {
|
|
67
|
-
'gen_ai.operation.name': 'embeddings',
|
|
68
|
-
'gen_ai.usage.input_tokens': 2,
|
|
69
|
-
},
|
|
70
|
-
});
|
|
71
|
-
const modelCallEmbeddings = startChildSpan(
|
|
72
|
-
tracer,
|
|
73
|
-
outerEmbeddings,
|
|
74
|
-
'embeddings openai/text-embedding-3-small',
|
|
75
|
-
{
|
|
76
|
-
'gen_ai.operation.name': 'embeddings',
|
|
77
|
-
'gen_ai.usage.input_tokens': 2,
|
|
78
|
-
}
|
|
79
|
-
);
|
|
80
|
-
|
|
81
|
-
modelCallEmbeddings.end();
|
|
82
|
-
outerEmbeddings.end();
|
|
83
|
-
|
|
84
|
-
const exported = exporter.getFinishedSpans();
|
|
85
|
-
assert.equal(exported.length, 1);
|
|
86
|
-
assert.equal(exported[0].spanContext().spanId, outerEmbeddings.spanContext().spanId);
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
test('legacy shape: only ai.<fn>.do* spans are exported', () => {
|
|
90
|
-
const { exporter, provider } = buildProviderWithExporter();
|
|
91
|
-
const tracer = provider.getTracer('ai');
|
|
92
|
-
|
|
93
|
-
const outer = tracer.startSpan('ai.streamText', {
|
|
94
|
-
attributes: { 'ai.usage.inputTokens': 100 },
|
|
95
|
-
});
|
|
96
|
-
const doStream = startChildSpan(tracer, outer, 'ai.streamText.doStream', {
|
|
97
|
-
'gen_ai.usage.input_tokens': 100,
|
|
98
|
-
});
|
|
99
|
-
const toolCall = startChildSpan(tracer, outer, 'ai.toolCall', {});
|
|
100
|
-
const doEmbed = tracer.startSpan('ai.embed.doEmbed', {
|
|
101
|
-
attributes: { 'gen_ai.usage.input_tokens': 1 },
|
|
102
|
-
});
|
|
103
|
-
|
|
104
|
-
doStream.end();
|
|
105
|
-
toolCall.end();
|
|
106
|
-
doEmbed.end();
|
|
107
|
-
outer.end();
|
|
108
|
-
|
|
109
|
-
const exported = exporter.getFinishedSpans().map((span) => span.name);
|
|
110
|
-
assert.deepEqual(exported.sort(), ['ai.embed.doEmbed', 'ai.streamText.doStream']);
|
|
111
|
-
});
|
|
112
|
-
|
|
113
|
-
test('gateway provider id gets the weflayr override, direct providers do not', () => {
|
|
114
|
-
const { exporter, provider } = buildProviderWithExporter();
|
|
115
|
-
const tracer = provider.getTracer('gen_ai');
|
|
116
|
-
|
|
117
|
-
const gatewayChat = tracer.startSpan('chat openai/gpt-4o-mini', {
|
|
118
|
-
attributes: { 'gen_ai.operation.name': 'chat', 'gen_ai.provider.name': 'gateway' },
|
|
119
|
-
});
|
|
120
|
-
gatewayChat.end();
|
|
121
|
-
const directChat = tracer.startSpan('chat gpt-4o-mini', {
|
|
122
|
-
attributes: { 'gen_ai.operation.name': 'chat', 'gen_ai.provider.name': 'openai' },
|
|
123
|
-
});
|
|
124
|
-
directChat.end();
|
|
125
|
-
|
|
126
|
-
const [gatewayExported, directExported] = exporter.getFinishedSpans();
|
|
127
|
-
assert.equal(gatewayExported.attributes['weflayr.provider_name'], 'vercel_ai_gateway');
|
|
128
|
-
assert.equal(directExported.attributes['weflayr.provider_name'], undefined);
|
|
129
|
-
});
|
|
130
|
-
|
|
131
|
-
test('gateway provider id does not overwrite a propagateMetadata providerName', () => {
|
|
132
|
-
const { exporter, provider } = buildProviderWithExporter();
|
|
133
|
-
const tracer = provider.getTracer('gen_ai');
|
|
134
|
-
|
|
135
|
-
const chat = tracer.startSpan('chat openai/gpt-4o-mini', {
|
|
136
|
-
attributes: {
|
|
137
|
-
'gen_ai.operation.name': 'chat',
|
|
138
|
-
'gen_ai.provider.name': 'gateway',
|
|
139
|
-
'weflayr.provider_name': 'openai',
|
|
140
|
-
},
|
|
141
|
-
});
|
|
142
|
-
chat.end();
|
|
143
|
-
|
|
144
|
-
assert.equal(exporter.getFinishedSpans()[0].attributes['weflayr.provider_name'], 'openai');
|
|
145
|
-
});
|
|
146
|
-
|
|
147
|
-
test('non-Vercel scopes still go through the default export filter', () => {
|
|
148
|
-
const { exporter, provider } = buildProviderWithExporter();
|
|
149
|
-
|
|
150
|
-
const llmSpan = provider
|
|
151
|
-
.getTracer('@traceloop/instrumentation-openai')
|
|
152
|
-
.startSpan('openai.chat', { attributes: { 'gen_ai.system': 'openai' } });
|
|
153
|
-
llmSpan.end();
|
|
154
|
-
const unrelatedSpan = provider.getTracer('my-app').startSpan('http request');
|
|
155
|
-
unrelatedSpan.end();
|
|
156
|
-
|
|
157
|
-
const exported = exporter.getFinishedSpans().map((span) => span.name);
|
|
158
|
-
assert.deepEqual(exported, ['openai.chat']);
|
|
159
|
-
});
|
package/tsconfig.json
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
// First TypeScript module of the SDK: only src/api is compiled (to dist/);
|
|
3
|
-
// the rest of src stays plain JavaScript until it is migrated.
|
|
4
|
-
"compilerOptions": {
|
|
5
|
-
"target": "ES2022",
|
|
6
|
-
"lib": ["ES2022", "DOM", "DOM.Iterable"],
|
|
7
|
-
"module": "NodeNext",
|
|
8
|
-
"moduleResolution": "NodeNext",
|
|
9
|
-
"rootDir": "src",
|
|
10
|
-
"outDir": "dist",
|
|
11
|
-
"declaration": true,
|
|
12
|
-
"strict": true,
|
|
13
|
-
"esModuleInterop": true,
|
|
14
|
-
"skipLibCheck": true,
|
|
15
|
-
"types": ["node"]
|
|
16
|
-
},
|
|
17
|
-
"include": ["src/api"]
|
|
18
|
-
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|