weflayr 0.24.0 → 0.26.1
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/package.json +51 -0
- package/dist/{api → src/api}/generated/facade.gen.d.ts +86 -12
- package/dist/{api → src/api}/generated/facade.gen.js +4 -2
- package/dist/src/api/generated/index.d.ts +2 -0
- package/dist/{api → src/api}/generated/index.js +3 -1
- package/dist/{api → src/api}/generated/sdk.gen.d.ts +11 -3
- package/dist/{api → src/api}/generated/sdk.gen.js +34 -4
- package/{src/api/generated/types.gen.ts → dist/src/api/generated/types.gen.d.ts} +436 -153
- 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/{src → dist/src}/instrumentation/google/get_cache_telemetry.js +18 -19
- 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 +12 -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 -1005
- package/eslint.config.mjs +0 -36
- package/index.d.ts +0 -170
- 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 -104
- package/src/api/generated/index.ts +0 -4
- package/src/api/generated/sdk.gen.ts +0 -175
- package/src/api/index.ts +0 -45
- package/src/api/makeEndpoint.ts +0 -54
- package/src/auto-instrument.js +0 -172
- package/src/index.js +0 -19
- package/src/instrumentation/anthropic/get_cache_and_reasoning_telemetry.js +0 -118
- package/src/instrumentation/anthropic/get_cache_config_telemetry.js +0 -90
- package/src/instrumentation/anthropic/get_streaming_stop_reason_telemetry.js +0 -121
- package/src/instrumentation/anthropic/get_tool_definitions_telemetry.js +0 -55
- package/src/instrumentation/anthropic/set_telemetry_attributes.js +0 -39
- package/src/instrumentation/bedrock/get_cache_config_telemetry.js +0 -106
- package/src/instrumentation/bedrock/get_cache_telemetry.js +0 -109
- 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 -40
- 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_operations_telemetry.js +0 -171
- package/src/instrumentation/google/get_embeddings_telemetry.js +0 -99
- package/src/instrumentation/google/set_telemetry_attributes.js +0 -104
- 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_cache_config_telemetry.js +0 -63
- 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 -41
- package/src/instrumentation/vercel/full_instrumentation.js +0 -52
- package/src/instrumentation/vercel/get_cache_creation_telemetry.js +0 -70
- package/src/logger.js +0 -8
- package/src/otel/exporter.js +0 -108
- package/src/otel/propagation.js +0 -146
- package/src/otel/span-filter.js +0 -69
- package/src/otel/span-processor.js +0 -170
- 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 -884
- package/tests/instrumentation/anthropic/get_cache_and_reasoning_telemetry.test.js +0 -181
- package/tests/instrumentation/anthropic/get_cache_config_telemetry.test.js +0 -92
- package/tests/instrumentation/anthropic/get_streaming_stop_reason_telemetry.test.js +0 -117
- package/tests/instrumentation/anthropic/get_tool_definitions_telemetry.test.js +0 -97
- package/tests/instrumentation/bedrock/get_cache_config_telemetry.test.js +0 -107
- package/tests/instrumentation/bedrock/get_cache_telemetry.test.js +0 -118
- 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_cache_operations_telemetry.test.js +0 -130
- 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_cache_config_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/instrumentation/vercel/get_cache_creation_telemetry.test.js +0 -96
- 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,181 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
// Tests for the Anthropic cached-prompt token complement. It wraps the primary
|
|
4
|
-
// instrumentor's `_endSpan({ span, type, result })` to stamp
|
|
5
|
-
// gen_ai.usage.cache_read_input_tokens / cache_creation_input_tokens from the
|
|
6
|
-
// response's `usage.cache_read_input_tokens` / `cache_creation_input_tokens`.
|
|
7
|
-
|
|
8
|
-
const test = require('node:test');
|
|
9
|
-
const assert = require('node:assert/strict');
|
|
10
|
-
|
|
11
|
-
const {
|
|
12
|
-
AnthropicPromptCachingInstrumentor,
|
|
13
|
-
} = require('../../../src/instrumentation/anthropic/get_cache_and_reasoning_telemetry');
|
|
14
|
-
|
|
15
|
-
function fakeSpan() {
|
|
16
|
-
const attrs = {};
|
|
17
|
-
return {
|
|
18
|
-
attrs,
|
|
19
|
-
isRecording: () => true,
|
|
20
|
-
setAttribute(key, value) {
|
|
21
|
-
attrs[key] = value;
|
|
22
|
-
},
|
|
23
|
-
};
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
test('stamps cache write and still calls the original _endSpan', () => {
|
|
27
|
-
const calls = [];
|
|
28
|
-
const instrumentation = {
|
|
29
|
-
_endSpan(args) {
|
|
30
|
-
calls.push(args);
|
|
31
|
-
},
|
|
32
|
-
};
|
|
33
|
-
new AnthropicPromptCachingInstrumentor().instrument(instrumentation);
|
|
34
|
-
|
|
35
|
-
const span = fakeSpan();
|
|
36
|
-
instrumentation._endSpan({
|
|
37
|
-
span,
|
|
38
|
-
type: 'completion',
|
|
39
|
-
result: {
|
|
40
|
-
usage: { input_tokens: 10, cache_creation_input_tokens: 5269, cache_read_input_tokens: 0 },
|
|
41
|
-
},
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
assert.equal(span.attrs['gen_ai.usage.cache_creation_input_tokens'], 5269);
|
|
45
|
-
assert.equal(span.attrs['gen_ai.usage.cache_read_input_tokens'], undefined);
|
|
46
|
-
assert.equal(calls.length, 1);
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
test('stamps cache read on a warm call', () => {
|
|
50
|
-
const instrumentation = { _endSpan() {} };
|
|
51
|
-
new AnthropicPromptCachingInstrumentor().instrument(instrumentation);
|
|
52
|
-
|
|
53
|
-
const span = fakeSpan();
|
|
54
|
-
instrumentation._endSpan({
|
|
55
|
-
span,
|
|
56
|
-
type: 'completion',
|
|
57
|
-
result: {
|
|
58
|
-
usage: { input_tokens: 10, cache_creation_input_tokens: 0, cache_read_input_tokens: 5271 },
|
|
59
|
-
},
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
assert.equal(span.attrs['gen_ai.usage.cache_read_input_tokens'], 5271);
|
|
63
|
-
assert.equal(span.attrs['gen_ai.usage.cache_creation_input_tokens'], undefined);
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
test('stamps usage.cache_creation verbatim', () => {
|
|
67
|
-
const instrumentation = { _endSpan() {} };
|
|
68
|
-
new AnthropicPromptCachingInstrumentor().instrument(instrumentation);
|
|
69
|
-
|
|
70
|
-
const span = fakeSpan();
|
|
71
|
-
instrumentation._endSpan({
|
|
72
|
-
span,
|
|
73
|
-
type: 'completion',
|
|
74
|
-
result: {
|
|
75
|
-
usage: {
|
|
76
|
-
input_tokens: 10,
|
|
77
|
-
cache_creation_input_tokens: 5300,
|
|
78
|
-
cache_creation: { ephemeral_5m_input_tokens: 4000, ephemeral_1h_input_tokens: 1300 },
|
|
79
|
-
},
|
|
80
|
-
},
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
assert.deepEqual(JSON.parse(span.attrs['weflayr.cache.creation']), {
|
|
84
|
-
ephemeral_5m_input_tokens: 4000,
|
|
85
|
-
ephemeral_1h_input_tokens: 1300,
|
|
86
|
-
});
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
test('sets nothing for an uncached call', () => {
|
|
90
|
-
const instrumentation = { _endSpan() {} };
|
|
91
|
-
new AnthropicPromptCachingInstrumentor().instrument(instrumentation);
|
|
92
|
-
|
|
93
|
-
const span = fakeSpan();
|
|
94
|
-
instrumentation._endSpan({ span, type: 'completion', result: { usage: { input_tokens: 13 } } });
|
|
95
|
-
|
|
96
|
-
assert.equal(span.attrs['gen_ai.usage.cache_read_input_tokens'], undefined);
|
|
97
|
-
assert.equal(span.attrs['gen_ai.usage.cache_creation_input_tokens'], undefined);
|
|
98
|
-
});
|
|
99
|
-
|
|
100
|
-
test('stamps extended thinking tokens from output_tokens_details', () => {
|
|
101
|
-
const instrumentation = { _endSpan() {} };
|
|
102
|
-
new AnthropicPromptCachingInstrumentor().instrument(instrumentation);
|
|
103
|
-
|
|
104
|
-
const span = fakeSpan();
|
|
105
|
-
instrumentation._endSpan({
|
|
106
|
-
span,
|
|
107
|
-
type: 'completion',
|
|
108
|
-
result: { usage: { input_tokens: 10, output_tokens_details: { thinking_tokens: 150 } } },
|
|
109
|
-
});
|
|
110
|
-
|
|
111
|
-
assert.equal(span.attrs['gen_ai.usage.output_tokens_details.thinking_tokens'], 150);
|
|
112
|
-
});
|
|
113
|
-
|
|
114
|
-
test('stamps cache + raw input from the streamed message_start usage', async () => {
|
|
115
|
-
const instrumentation = {
|
|
116
|
-
_endSpan() {},
|
|
117
|
-
_streamingWrapPromise() {
|
|
118
|
-
return (async function* () {
|
|
119
|
-
yield {
|
|
120
|
-
type: 'message_start',
|
|
121
|
-
message: {
|
|
122
|
-
usage: {
|
|
123
|
-
input_tokens: 10,
|
|
124
|
-
cache_read_input_tokens: 5270,
|
|
125
|
-
cache_creation_input_tokens: 0,
|
|
126
|
-
},
|
|
127
|
-
},
|
|
128
|
-
};
|
|
129
|
-
yield { type: 'content_block_delta', delta: { text: 'OK' } };
|
|
130
|
-
})();
|
|
131
|
-
},
|
|
132
|
-
};
|
|
133
|
-
new AnthropicPromptCachingInstrumentor().instrument(instrumentation);
|
|
134
|
-
|
|
135
|
-
const span = fakeSpan();
|
|
136
|
-
for await (const _chunk of instrumentation._streamingWrapPromise('client', 'mod', { span })) {
|
|
137
|
-
void _chunk;
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
assert.equal(span.attrs['gen_ai.usage.cache_read_input_tokens'], 5270);
|
|
141
|
-
assert.equal(span.attrs['gen_ai.usage.input_tokens'], 10);
|
|
142
|
-
});
|
|
143
|
-
|
|
144
|
-
test('re-yields every stream chunk unchanged — no telemetry collision with the payload', async () => {
|
|
145
|
-
const emitted = [
|
|
146
|
-
{
|
|
147
|
-
type: 'message_start',
|
|
148
|
-
message: { usage: { input_tokens: 10, cache_read_input_tokens: 5270 } },
|
|
149
|
-
},
|
|
150
|
-
{ type: 'content_block_delta', delta: { text: 'O' } },
|
|
151
|
-
{ type: 'content_block_delta', delta: { text: 'K' } },
|
|
152
|
-
];
|
|
153
|
-
const instrumentation = {
|
|
154
|
-
_endSpan() {},
|
|
155
|
-
_streamingWrapPromise() {
|
|
156
|
-
return (async function* () {
|
|
157
|
-
for (const chunk of emitted) yield chunk;
|
|
158
|
-
})();
|
|
159
|
-
},
|
|
160
|
-
};
|
|
161
|
-
new AnthropicPromptCachingInstrumentor().instrument(instrumentation);
|
|
162
|
-
|
|
163
|
-
const span = fakeSpan();
|
|
164
|
-
const collected = [];
|
|
165
|
-
for await (const chunk of instrumentation._streamingWrapPromise('client', 'mod', { span })) {
|
|
166
|
-
collected.push(chunk);
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
// Same count, order, and object identity: observeCache re-yields each chunk by
|
|
170
|
-
// reference without copying or mutating it.
|
|
171
|
-
assert.equal(collected.length, emitted.length);
|
|
172
|
-
collected.forEach((chunk, index) => assert.equal(chunk, emitted[index]));
|
|
173
|
-
// …while still stamping cache + raw input off the message_start chunk.
|
|
174
|
-
assert.equal(span.attrs['gen_ai.usage.input_tokens'], 10);
|
|
175
|
-
});
|
|
176
|
-
|
|
177
|
-
test('is a no-op when the instrumentor has no _endSpan', () => {
|
|
178
|
-
const instrumentation = {};
|
|
179
|
-
new AnthropicPromptCachingInstrumentor().instrument(instrumentation);
|
|
180
|
-
assert.equal(instrumentation._endSpan, undefined);
|
|
181
|
-
});
|
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
// Tests for the Anthropic request-side cache_control breakpoint capture.
|
|
4
|
-
//
|
|
5
|
-
// The traceloop instrumentation instance is stubbed with a `startSpan` that
|
|
6
|
-
// returns a fake span, so the wrap can be exercised without the real SDK.
|
|
7
|
-
|
|
8
|
-
const test = require('node:test');
|
|
9
|
-
const assert = require('node:assert/strict');
|
|
10
|
-
|
|
11
|
-
const {
|
|
12
|
-
AnthropicCacheConfigInstrumentor,
|
|
13
|
-
extractCacheBreakpoints,
|
|
14
|
-
} = require('../../../src/instrumentation/anthropic/get_cache_config_telemetry');
|
|
15
|
-
|
|
16
|
-
function makeFakeSpan() {
|
|
17
|
-
const attributes = {};
|
|
18
|
-
return {
|
|
19
|
-
attributes,
|
|
20
|
-
setAttribute(key, value) {
|
|
21
|
-
attributes[key] = value;
|
|
22
|
-
},
|
|
23
|
-
};
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
function makeStubInstrumentation() {
|
|
27
|
-
return {
|
|
28
|
-
startSpan() {
|
|
29
|
-
return makeFakeSpan();
|
|
30
|
-
},
|
|
31
|
-
};
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
test('stamps breakpoints from system, message content and tools', () => {
|
|
35
|
-
const instrumentation = makeStubInstrumentation();
|
|
36
|
-
new AnthropicCacheConfigInstrumentor().instrument(instrumentation);
|
|
37
|
-
|
|
38
|
-
const span = instrumentation.startSpan({
|
|
39
|
-
type: 'chat',
|
|
40
|
-
params: {
|
|
41
|
-
system: [{ type: 'text', text: 'big prefix', cache_control: { type: 'ephemeral' } }],
|
|
42
|
-
messages: [
|
|
43
|
-
{ role: 'user', content: 'plain string content' },
|
|
44
|
-
{
|
|
45
|
-
role: 'user',
|
|
46
|
-
content: [{ type: 'text', text: 'doc', cache_control: { type: 'ephemeral', ttl: '1h' } }],
|
|
47
|
-
},
|
|
48
|
-
],
|
|
49
|
-
tools: [
|
|
50
|
-
{ name: 'get_weather', cache_control: { type: 'ephemeral' } },
|
|
51
|
-
{ name: 'uncached_tool' },
|
|
52
|
-
],
|
|
53
|
-
},
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
assert.deepEqual(JSON.parse(span.attributes['weflayr.cache.breakpoints']), [
|
|
57
|
-
{ location: 'system' },
|
|
58
|
-
{ location: 'messages[1]', ttl: '1h' },
|
|
59
|
-
{ location: 'tools[0]' },
|
|
60
|
-
]);
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
test('no attribute without breakpoints', () => {
|
|
64
|
-
const instrumentation = makeStubInstrumentation();
|
|
65
|
-
new AnthropicCacheConfigInstrumentor().instrument(instrumentation);
|
|
66
|
-
|
|
67
|
-
const span = instrumentation.startSpan({
|
|
68
|
-
type: 'chat',
|
|
69
|
-
params: { messages: [{ role: 'user', content: 'hello' }] },
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
assert.ok(!('weflayr.cache.breakpoints' in span.attributes));
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
test('extractCacheBreakpoints omits the ttl when the request sets none', () => {
|
|
76
|
-
assert.deepEqual(
|
|
77
|
-
extractCacheBreakpoints({
|
|
78
|
-
system: [{ type: 'text', text: 'p', cache_control: { type: 'ephemeral' } }],
|
|
79
|
-
}),
|
|
80
|
-
[{ location: 'system' }]
|
|
81
|
-
);
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
test('uninstrument restores the original startSpan', () => {
|
|
85
|
-
const instrumentation = makeStubInstrumentation();
|
|
86
|
-
const original = instrumentation.startSpan;
|
|
87
|
-
const instrumentor = new AnthropicCacheConfigInstrumentor();
|
|
88
|
-
instrumentor.instrument(instrumentation);
|
|
89
|
-
assert.notEqual(instrumentation.startSpan, original);
|
|
90
|
-
instrumentor.uninstrument();
|
|
91
|
-
assert.equal(instrumentation.startSpan, original);
|
|
92
|
-
});
|
|
@@ -1,117 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
// Tests for the Anthropic streamed stop-reason complement.
|
|
4
|
-
//
|
|
5
|
-
// The traceloop instrumentation instance is stubbed the way the real one works:
|
|
6
|
-
// `_streamingWrapPromise` returns `new moduleExports.APIPromise(...)` whose
|
|
7
|
-
// parse step wraps the SDK stream with an accumulating iterator that calls
|
|
8
|
-
// `_endSpan` when exhausted — so the test exercises the complement's APIPromise
|
|
9
|
-
// interposition end to end.
|
|
10
|
-
|
|
11
|
-
const test = require('node:test');
|
|
12
|
-
const assert = require('node:assert/strict');
|
|
13
|
-
|
|
14
|
-
const {
|
|
15
|
-
AnthropicStreamingStopReasonInstrumentor,
|
|
16
|
-
} = require('../../../src/instrumentation/anthropic/get_streaming_stop_reason_telemetry');
|
|
17
|
-
|
|
18
|
-
class StubStream {
|
|
19
|
-
constructor(iteratorFactory, controller) {
|
|
20
|
-
this._iteratorFactory = iteratorFactory;
|
|
21
|
-
this.controller = controller;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
[Symbol.asyncIterator]() {
|
|
25
|
-
return this._iteratorFactory();
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
class StubAPIPromise {
|
|
30
|
-
constructor(client, responsePromise, parseResponse) {
|
|
31
|
-
this.parsed = parseResponse(client, responsePromise);
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
function makeStubInstrumentation() {
|
|
36
|
-
const finalized = [];
|
|
37
|
-
return {
|
|
38
|
-
finalized,
|
|
39
|
-
_streamingWrapPromise(client, moduleExports, { span, promise }) {
|
|
40
|
-
const self = this;
|
|
41
|
-
return new moduleExports.APIPromise(
|
|
42
|
-
client,
|
|
43
|
-
promise,
|
|
44
|
-
async (parseClient, realStreamPromise) => {
|
|
45
|
-
const realStream = await realStreamPromise;
|
|
46
|
-
// Mimics traceloop: re-wrap the stream with an accumulating iterator
|
|
47
|
-
// that finalizes the span once exhausted.
|
|
48
|
-
return new realStream.constructor(
|
|
49
|
-
() =>
|
|
50
|
-
(async function* accumulate() {
|
|
51
|
-
const result = { stop_reason: null };
|
|
52
|
-
for await (const chunk of realStream) yield chunk;
|
|
53
|
-
self._endSpan({ span, result });
|
|
54
|
-
})(),
|
|
55
|
-
realStream.controller
|
|
56
|
-
);
|
|
57
|
-
}
|
|
58
|
-
);
|
|
59
|
-
},
|
|
60
|
-
_endSpan(args) {
|
|
61
|
-
finalized.push(args.result);
|
|
62
|
-
},
|
|
63
|
-
};
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
function chunkStream() {
|
|
67
|
-
return new StubStream(async function* chunks() {
|
|
68
|
-
yield { type: 'message_start', message: { usage: { input_tokens: 5 } } };
|
|
69
|
-
yield { type: 'content_block_delta', delta: { type: 'text_delta', text: 'Hello' } };
|
|
70
|
-
yield {
|
|
71
|
-
type: 'message_delta',
|
|
72
|
-
delta: { stop_reason: 'end_turn' },
|
|
73
|
-
usage: { output_tokens: 3 },
|
|
74
|
-
};
|
|
75
|
-
yield { type: 'message_stop' };
|
|
76
|
-
});
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
test('injects the streamed stop reason into the result before endSpan', async () => {
|
|
80
|
-
const instrumentation = makeStubInstrumentation();
|
|
81
|
-
new AnthropicStreamingStopReasonInstrumentor().instrument(instrumentation);
|
|
82
|
-
|
|
83
|
-
const span = { name: 'anthropic.chat' };
|
|
84
|
-
const apiPromise = instrumentation._streamingWrapPromise(
|
|
85
|
-
{},
|
|
86
|
-
{ APIPromise: StubAPIPromise },
|
|
87
|
-
{ span, type: 'chat', promise: Promise.resolve(chunkStream()) }
|
|
88
|
-
);
|
|
89
|
-
|
|
90
|
-
const stream = await apiPromise.parsed;
|
|
91
|
-
const seen = [];
|
|
92
|
-
for await (const chunk of stream) seen.push(chunk.type);
|
|
93
|
-
|
|
94
|
-
assert.deepEqual(seen, ['message_start', 'content_block_delta', 'message_delta', 'message_stop']);
|
|
95
|
-
assert.equal(instrumentation.finalized.length, 1);
|
|
96
|
-
assert.equal(instrumentation.finalized[0].stop_reason, 'end_turn');
|
|
97
|
-
});
|
|
98
|
-
|
|
99
|
-
test('leaves an already-set stop reason untouched', () => {
|
|
100
|
-
const instrumentation = makeStubInstrumentation();
|
|
101
|
-
new AnthropicStreamingStopReasonInstrumentor().instrument(instrumentation);
|
|
102
|
-
|
|
103
|
-
const span = { name: 'anthropic.chat' };
|
|
104
|
-
instrumentation._endSpan({ span, result: { stop_reason: 'max_tokens' } });
|
|
105
|
-
assert.equal(instrumentation.finalized[0].stop_reason, 'max_tokens');
|
|
106
|
-
});
|
|
107
|
-
|
|
108
|
-
test('uninstrument restores the original methods', () => {
|
|
109
|
-
const instrumentation = makeStubInstrumentation();
|
|
110
|
-
const streamOriginal = instrumentation._streamingWrapPromise;
|
|
111
|
-
const endSpanOriginal = instrumentation._endSpan;
|
|
112
|
-
const instrumentor = new AnthropicStreamingStopReasonInstrumentor();
|
|
113
|
-
instrumentor.instrument(instrumentation);
|
|
114
|
-
instrumentor.uninstrument();
|
|
115
|
-
assert.equal(instrumentation._streamingWrapPromise, streamOriginal);
|
|
116
|
-
assert.equal(instrumentation._endSpan, endSpanOriginal);
|
|
117
|
-
});
|
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
// Tests for the Anthropic tool-definitions complement.
|
|
4
|
-
//
|
|
5
|
-
// The traceloop instrumentation instance is stubbed with a `startSpan` that
|
|
6
|
-
// returns a fake span, so the wrap can be exercised without the real SDK.
|
|
7
|
-
|
|
8
|
-
const test = require('node:test');
|
|
9
|
-
const assert = require('node:assert/strict');
|
|
10
|
-
|
|
11
|
-
const {
|
|
12
|
-
AnthropicToolDefinitionsInstrumentor,
|
|
13
|
-
} = require('../../../src/instrumentation/anthropic/get_tool_definitions_telemetry');
|
|
14
|
-
|
|
15
|
-
function makeFakeSpan() {
|
|
16
|
-
const attributes = {};
|
|
17
|
-
return {
|
|
18
|
-
attributes,
|
|
19
|
-
setAttribute(key, value) {
|
|
20
|
-
attributes[key] = value;
|
|
21
|
-
},
|
|
22
|
-
};
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
function makeStubInstrumentation() {
|
|
26
|
-
return {
|
|
27
|
-
startSpan(request) {
|
|
28
|
-
const span = makeFakeSpan();
|
|
29
|
-
span.attributes['gen_ai.request.model'] = request.params.model;
|
|
30
|
-
return span;
|
|
31
|
-
},
|
|
32
|
-
};
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
const WEATHER_TOOL = {
|
|
36
|
-
name: 'get_weather',
|
|
37
|
-
description: 'Get the current weather for a city.',
|
|
38
|
-
input_schema: { type: 'object', properties: { city: { type: 'string' } } },
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
test('stamps tool definitions from the request params', () => {
|
|
42
|
-
const instrumentation = makeStubInstrumentation();
|
|
43
|
-
const instrumentor = new AnthropicToolDefinitionsInstrumentor();
|
|
44
|
-
instrumentor.instrument(instrumentation);
|
|
45
|
-
|
|
46
|
-
const span = instrumentation.startSpan({
|
|
47
|
-
type: 'chat',
|
|
48
|
-
params: { model: 'claude-haiku-4-5', tools: [WEATHER_TOOL] },
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
assert.equal(span.attributes['gen_ai.request.model'], 'claude-haiku-4-5');
|
|
52
|
-
assert.deepEqual(JSON.parse(span.attributes['gen_ai.tool.definitions']), [WEATHER_TOOL]);
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
test('drops cache_control from the stamped tool definitions', () => {
|
|
56
|
-
const instrumentation = makeStubInstrumentation();
|
|
57
|
-
new AnthropicToolDefinitionsInstrumentor().instrument(instrumentation);
|
|
58
|
-
|
|
59
|
-
const span = instrumentation.startSpan({
|
|
60
|
-
type: 'chat',
|
|
61
|
-
params: {
|
|
62
|
-
model: 'claude-haiku-4-5',
|
|
63
|
-
tools: [{ ...WEATHER_TOOL, cache_control: { type: 'ephemeral', ttl: '1h' } }],
|
|
64
|
-
},
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
assert.deepEqual(JSON.parse(span.attributes['gen_ai.tool.definitions']), [WEATHER_TOOL]);
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
test('no attribute when the request has no tools', () => {
|
|
71
|
-
const instrumentation = makeStubInstrumentation();
|
|
72
|
-
new AnthropicToolDefinitionsInstrumentor().instrument(instrumentation);
|
|
73
|
-
|
|
74
|
-
const span = instrumentation.startSpan({
|
|
75
|
-
type: 'chat',
|
|
76
|
-
params: { model: 'claude-haiku-4-5' },
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
assert.ok(!('gen_ai.tool.definitions' in span.attributes));
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
test('uninstrument restores the original startSpan', () => {
|
|
83
|
-
const instrumentation = makeStubInstrumentation();
|
|
84
|
-
const original = instrumentation.startSpan;
|
|
85
|
-
const instrumentor = new AnthropicToolDefinitionsInstrumentor();
|
|
86
|
-
instrumentor.instrument(instrumentation);
|
|
87
|
-
assert.notEqual(instrumentation.startSpan, original);
|
|
88
|
-
instrumentor.uninstrument();
|
|
89
|
-
assert.equal(instrumentation.startSpan, original);
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
test('is a no-op when the instrumentor has no startSpan', () => {
|
|
93
|
-
const instrumentor = new AnthropicToolDefinitionsInstrumentor();
|
|
94
|
-
instrumentor.instrument({});
|
|
95
|
-
instrumentor.instrument(undefined);
|
|
96
|
-
instrumentor.uninstrument();
|
|
97
|
-
});
|
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
// Tests for the Bedrock request-side cache breakpoint capture.
|
|
4
|
-
//
|
|
5
|
-
// The extractor reads both body schemas an InvokeModel request can carry:
|
|
6
|
-
// Anthropic-on-Bedrock `cache_control` blocks and Amazon Nova `cachePoint`
|
|
7
|
-
// blocks (attached to a content block or standing alone). The traceloop
|
|
8
|
-
// instrumentation instance is stubbed with a `_startSpan` returning a fake
|
|
9
|
-
// span, so the wrap can be exercised without the real SDK.
|
|
10
|
-
|
|
11
|
-
const test = require('node:test');
|
|
12
|
-
const assert = require('node:assert/strict');
|
|
13
|
-
|
|
14
|
-
const {
|
|
15
|
-
BedrockCacheConfigInstrumentor,
|
|
16
|
-
extractBedrockCacheBreakpoints,
|
|
17
|
-
} = require('../../../src/instrumentation/bedrock/get_cache_config_telemetry');
|
|
18
|
-
|
|
19
|
-
function makeFakeSpan() {
|
|
20
|
-
const attributes = {};
|
|
21
|
-
return {
|
|
22
|
-
attributes,
|
|
23
|
-
setAttribute(key, value) {
|
|
24
|
-
attributes[key] = value;
|
|
25
|
-
},
|
|
26
|
-
};
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
function makeStubInstrumentation() {
|
|
30
|
-
return {
|
|
31
|
-
_startSpan() {
|
|
32
|
-
return makeFakeSpan();
|
|
33
|
-
},
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
test('extracts nova cache points', () => {
|
|
38
|
-
const body = {
|
|
39
|
-
system: [{ text: 'sys' }, { cachePoint: { type: 'default' } }],
|
|
40
|
-
messages: [
|
|
41
|
-
{
|
|
42
|
-
role: 'user',
|
|
43
|
-
content: [
|
|
44
|
-
{ text: 'big prefix', cachePoint: { type: 'default' } },
|
|
45
|
-
{ text: 'Reply with OK.' },
|
|
46
|
-
],
|
|
47
|
-
},
|
|
48
|
-
],
|
|
49
|
-
toolConfig: {
|
|
50
|
-
tools: [
|
|
51
|
-
{ toolSpec: { name: 'get_weather' } },
|
|
52
|
-
{ cachePoint: { type: 'default', ttl: '1h' } },
|
|
53
|
-
],
|
|
54
|
-
},
|
|
55
|
-
};
|
|
56
|
-
assert.deepEqual(extractBedrockCacheBreakpoints(body), [
|
|
57
|
-
{ location: 'system' },
|
|
58
|
-
{ location: 'messages[0]' },
|
|
59
|
-
{ location: 'tools[1]', ttl: '1h' },
|
|
60
|
-
]);
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
test('extracts anthropic-on-bedrock cache_control', () => {
|
|
64
|
-
const body = {
|
|
65
|
-
anthropic_version: 'bedrock-2023-05-31',
|
|
66
|
-
system: [{ type: 'text', text: 'big prefix', cache_control: { type: 'ephemeral', ttl: '1h' } }],
|
|
67
|
-
messages: [{ role: 'user', content: 'Reply with OK.' }],
|
|
68
|
-
};
|
|
69
|
-
assert.deepEqual(extractBedrockCacheBreakpoints(body), [{ location: 'system', ttl: '1h' }]);
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
test('no breakpoints without cache blocks', () => {
|
|
73
|
-
assert.deepEqual(
|
|
74
|
-
extractBedrockCacheBreakpoints({ messages: [{ role: 'user', content: 'hello' }] }),
|
|
75
|
-
[]
|
|
76
|
-
);
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
test('stamps breakpoints from the request body', () => {
|
|
80
|
-
const instrumentation = makeStubInstrumentation();
|
|
81
|
-
new BedrockCacheConfigInstrumentor().instrument(instrumentation);
|
|
82
|
-
|
|
83
|
-
const span = instrumentation._startSpan({
|
|
84
|
-
params: {
|
|
85
|
-
input: {
|
|
86
|
-
modelId: 'amazon.nova-micro-v1:0',
|
|
87
|
-
body: JSON.stringify({
|
|
88
|
-
messages: [{ role: 'user', content: [{ text: 'p', cachePoint: { type: 'default' } }] }],
|
|
89
|
-
}),
|
|
90
|
-
},
|
|
91
|
-
},
|
|
92
|
-
});
|
|
93
|
-
|
|
94
|
-
assert.deepEqual(JSON.parse(span.attributes['weflayr.cache.breakpoints']), [
|
|
95
|
-
{ location: 'messages[0]' },
|
|
96
|
-
]);
|
|
97
|
-
});
|
|
98
|
-
|
|
99
|
-
test('uninstrument restores the original _startSpan', () => {
|
|
100
|
-
const instrumentation = makeStubInstrumentation();
|
|
101
|
-
const original = instrumentation._startSpan;
|
|
102
|
-
const instrumentor = new BedrockCacheConfigInstrumentor();
|
|
103
|
-
instrumentor.instrument(instrumentation);
|
|
104
|
-
assert.notEqual(instrumentation._startSpan, original);
|
|
105
|
-
instrumentor.uninstrument();
|
|
106
|
-
assert.equal(instrumentation._startSpan, original);
|
|
107
|
-
});
|