weflayr 0.23.0 → 0.24.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.
Files changed (41) hide show
  1. package/dist/api/generated/facade.gen.d.ts +77 -0
  2. package/dist/api/generated/facade.gen.js +7 -1
  3. package/dist/api/generated/index.d.ts +2 -2
  4. package/dist/api/generated/index.js +7 -1
  5. package/dist/api/generated/sdk.gen.d.ts +25 -1
  6. package/dist/api/generated/sdk.gen.js +55 -1
  7. package/dist/api/generated/types.gen.d.ts +256 -0
  8. package/index.d.ts +5 -2
  9. package/package.json +1 -1
  10. package/src/api/generated/facade.gen.ts +36 -0
  11. package/src/api/generated/index.ts +2 -2
  12. package/src/api/generated/sdk.gen.ts +55 -1
  13. package/src/api/generated/types.gen.ts +293 -0
  14. package/src/auto-instrument.js +1 -0
  15. package/src/instrumentation/anthropic/get_cache_and_reasoning_telemetry.js +11 -0
  16. package/src/instrumentation/anthropic/get_cache_config_telemetry.js +90 -0
  17. package/src/instrumentation/anthropic/get_tool_definitions_telemetry.js +6 -1
  18. package/src/instrumentation/anthropic/set_telemetry_attributes.js +2 -0
  19. package/src/instrumentation/bedrock/get_cache_config_telemetry.js +106 -0
  20. package/src/instrumentation/bedrock/get_cache_telemetry.js +11 -6
  21. package/src/instrumentation/bedrock/set_telemetry_attributes.js +6 -2
  22. package/src/instrumentation/google/get_cache_operations_telemetry.js +171 -0
  23. package/src/instrumentation/google/get_cache_telemetry.js +16 -2
  24. package/src/instrumentation/google/set_telemetry_attributes.js +8 -2
  25. package/src/instrumentation/openai/get_cache_config_telemetry.js +63 -0
  26. package/src/instrumentation/openai/set_telemetry_attributes.js +2 -0
  27. package/src/instrumentation/vercel/full_instrumentation.js +10 -2
  28. package/src/instrumentation/vercel/get_cache_creation_telemetry.js +70 -0
  29. package/src/otel/propagation.js +22 -9
  30. package/src/otel/span-filter.js +12 -12
  31. package/src/otel/span-processor.js +8 -0
  32. package/src/otel/vercel-ai-sdk-span-filter.js +1 -1
  33. package/tests/index.test.js +67 -7
  34. package/tests/instrumentation/anthropic/get_cache_and_reasoning_telemetry.test.js +23 -0
  35. package/tests/instrumentation/anthropic/get_cache_config_telemetry.test.js +92 -0
  36. package/tests/instrumentation/anthropic/get_tool_definitions_telemetry.test.js +15 -0
  37. package/tests/instrumentation/bedrock/get_cache_config_telemetry.test.js +107 -0
  38. package/tests/instrumentation/bedrock/get_cache_telemetry.test.js +16 -0
  39. package/tests/instrumentation/google/get_cache_operations_telemetry.test.js +130 -0
  40. package/tests/instrumentation/openai/get_cache_config_telemetry.test.js +83 -0
  41. package/tests/instrumentation/vercel/get_cache_creation_telemetry.test.js +96 -0
@@ -0,0 +1,96 @@
1
+ 'use strict';
2
+
3
+ // Tests for the ai >= 7 cache-write capture: the telemetry dispatcher's
4
+ // onLanguageModelCallEnd reads the raw `usage.cache_creation` off the event's
5
+ // raw provider usage and stamps it verbatim on the still-open model-call span
6
+ // (reached through the integration's call state) before ending it.
7
+
8
+ const test = require('node:test');
9
+ const assert = require('node:assert/strict');
10
+
11
+ const {
12
+ VercelCacheCreationInstrumentor,
13
+ cacheCreationFromRawUsage,
14
+ } = require('../../../src/instrumentation/vercel/get_cache_creation_telemetry');
15
+
16
+ const RAW_ANTHROPIC_USAGE = {
17
+ input_tokens: 7,
18
+ cache_creation_input_tokens: 6053,
19
+ cache_creation: { ephemeral_5m_input_tokens: 6053, ephemeral_1h_input_tokens: 0 },
20
+ };
21
+
22
+ function makeFakeSpan() {
23
+ const attributes = {};
24
+ return {
25
+ attributes,
26
+ setAttribute(key, value) {
27
+ attributes[key] = value;
28
+ },
29
+ };
30
+ }
31
+
32
+ function makeInstrumentedDispatcher() {
33
+ const span = makeFakeSpan();
34
+ const endedEvents = [];
35
+ const dispatcher = {
36
+ onLanguageModelCallEnd(event) {
37
+ endedEvents.push(event);
38
+ },
39
+ getCallState(callId) {
40
+ return callId === 'call-1' ? { inferenceSpan: span } : undefined;
41
+ },
42
+ };
43
+ const instrumentor = new VercelCacheCreationInstrumentor();
44
+ instrumentor.instrument(dispatcher);
45
+ return { dispatcher, span, endedEvents, instrumentor };
46
+ }
47
+
48
+ test('stamps the raw cache_creation from the provider usage on the model-call span', () => {
49
+ const { dispatcher, span, endedEvents } = makeInstrumentedDispatcher();
50
+
51
+ dispatcher.onLanguageModelCallEnd({
52
+ callId: 'call-1',
53
+ usage: { inputTokens: 6060, outputTokens: 5, raw: RAW_ANTHROPIC_USAGE },
54
+ });
55
+
56
+ assert.deepEqual(
57
+ JSON.parse(span.attributes['weflayr.cache.creation']),
58
+ RAW_ANTHROPIC_USAGE.cache_creation
59
+ );
60
+ // The original handler still runs (it ends the span).
61
+ assert.equal(endedEvents.length, 1);
62
+ });
63
+
64
+ test('stamps nothing without a cache_creation in the raw usage', () => {
65
+ const { dispatcher, span } = makeInstrumentedDispatcher();
66
+
67
+ dispatcher.onLanguageModelCallEnd({
68
+ callId: 'call-1',
69
+ usage: { inputTokens: 13, outputTokens: 5, raw: { input_tokens: 13 } },
70
+ });
71
+
72
+ assert.ok(!('weflayr.cache.creation' in span.attributes));
73
+ });
74
+
75
+ test('cacheCreationFromRawUsage drops an all-zero cache_creation', () => {
76
+ assert.deepEqual(
77
+ cacheCreationFromRawUsage({
78
+ cache_creation: { ephemeral_5m_input_tokens: 4000, ephemeral_1h_input_tokens: 1300 },
79
+ }),
80
+ { ephemeral_5m_input_tokens: 4000, ephemeral_1h_input_tokens: 1300 }
81
+ );
82
+ assert.equal(
83
+ cacheCreationFromRawUsage({
84
+ cache_creation: { ephemeral_5m_input_tokens: 0, ephemeral_1h_input_tokens: 0 },
85
+ }),
86
+ undefined
87
+ );
88
+ assert.equal(cacheCreationFromRawUsage(undefined), undefined);
89
+ });
90
+
91
+ test('uninstrument restores the original handler', () => {
92
+ const { dispatcher, instrumentor } = makeInstrumentedDispatcher();
93
+ assert.equal(dispatcher.onLanguageModelCallEnd.name, 'onLanguageModelCallEndWithCacheCreation');
94
+ instrumentor.uninstrument();
95
+ assert.equal(dispatcher.onLanguageModelCallEnd.name, 'onLanguageModelCallEnd');
96
+ });