weflayr 0.26.1 → 0.28.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 (100) hide show
  1. package/dist/package.json +8 -5
  2. package/dist/src/auto-instrument.d.ts +4 -3
  3. package/dist/src/auto-instrument.js +18 -17
  4. package/dist/src/get-data-uri-mime-type.d.ts +17 -0
  5. package/dist/src/get-data-uri-mime-type.js +25 -0
  6. package/dist/src/index.d.ts +3 -2
  7. package/dist/src/index.js +5 -1
  8. package/dist/src/instrumentation/anthropic/get_streaming_accumulation_telemetry.d.ts +3 -1
  9. package/dist/src/instrumentation/anthropic/get_streaming_accumulation_telemetry.js +6 -3
  10. package/dist/src/instrumentation/anthropic/get_vertex_billing_telemetry.d.ts +32 -0
  11. package/dist/src/instrumentation/anthropic/get_vertex_billing_telemetry.js +100 -0
  12. package/dist/src/instrumentation/anthropic/get_web_search_telemetry.d.ts +43 -0
  13. package/dist/src/instrumentation/anthropic/get_web_search_telemetry.js +147 -0
  14. package/dist/src/instrumentation/anthropic/set_telemetry_attributes.d.ts +5 -2
  15. package/dist/src/instrumentation/anthropic/set_telemetry_attributes.js +17 -4
  16. package/dist/src/instrumentation/bedrock/get_cache_config_telemetry.d.ts +13 -1
  17. package/dist/src/instrumentation/bedrock/get_cache_config_telemetry.js +56 -1
  18. package/dist/src/instrumentation/bedrock/get_cache_telemetry.js +8 -5
  19. package/dist/src/instrumentation/bedrock/get_input_message_content_telemetry.js +33 -5
  20. package/dist/src/instrumentation/bedrock/get_model_id_telemetry.d.ts +1 -1
  21. package/dist/src/instrumentation/bedrock/get_model_id_telemetry.js +1 -1
  22. package/dist/src/instrumentation/bedrock/get_openai_chat_format_telemetry.d.ts +45 -0
  23. package/dist/src/instrumentation/bedrock/get_openai_chat_format_telemetry.js +251 -0
  24. package/dist/src/instrumentation/bedrock/get_streaming_output_message_telemetry.d.ts +6 -5
  25. package/dist/src/instrumentation/bedrock/get_streaming_output_message_telemetry.js +15 -12
  26. package/dist/src/instrumentation/bedrock/get_tool_definitions_telemetry.d.ts +2 -2
  27. package/dist/src/instrumentation/bedrock/get_tool_definitions_telemetry.js +12 -4
  28. package/dist/src/instrumentation/bedrock/set_telemetry_attributes.d.ts +4 -2
  29. package/dist/src/instrumentation/bedrock/set_telemetry_attributes.js +10 -3
  30. package/dist/src/instrumentation/cohere/get_embeddings_telemetry.js +4 -6
  31. package/dist/src/instrumentation/cohere/get_input_message_content_telemetry.d.ts +23 -0
  32. package/dist/src/instrumentation/cohere/get_input_message_content_telemetry.js +105 -0
  33. package/dist/src/instrumentation/cohere/get_v2_chat_telemetry.d.ts +18 -0
  34. package/dist/src/instrumentation/cohere/get_v2_chat_telemetry.js +186 -0
  35. package/dist/src/instrumentation/cohere/set_telemetry_attributes.d.ts +3 -1
  36. package/dist/src/instrumentation/cohere/set_telemetry_attributes.js +5 -1
  37. package/dist/src/instrumentation/google/get_embeddings_telemetry.d.ts +8 -4
  38. package/dist/src/instrumentation/google/get_embeddings_telemetry.js +68 -35
  39. package/dist/src/instrumentation/google/get_provider_name.d.ts +2 -1
  40. package/dist/src/instrumentation/google/get_provider_name.js +2 -1
  41. package/dist/src/instrumentation/google/get_web_search_telemetry.d.ts +38 -0
  42. package/dist/src/instrumentation/google/get_web_search_telemetry.js +125 -0
  43. package/dist/src/instrumentation/google/set_telemetry_attributes.d.ts +2 -2
  44. package/dist/src/instrumentation/google/set_telemetry_attributes.js +6 -2
  45. package/dist/src/instrumentation/mistral/full_instrumentation.d.ts +60 -0
  46. package/dist/src/instrumentation/mistral/full_instrumentation.js +364 -0
  47. package/dist/src/instrumentation/mistral/get_input_message_content_telemetry.d.ts +35 -0
  48. package/dist/src/instrumentation/mistral/get_input_message_content_telemetry.js +113 -0
  49. package/dist/src/instrumentation/mistral/get_structured_output_schema_telemetry.d.ts +13 -0
  50. package/dist/src/instrumentation/mistral/get_structured_output_schema_telemetry.js +24 -0
  51. package/dist/src/instrumentation/mistral/get_vertex_telemetry.d.ts +54 -0
  52. package/dist/src/instrumentation/mistral/get_vertex_telemetry.js +153 -0
  53. package/dist/src/instrumentation/openai/get_bedrock_mantle_telemetry.d.ts +10 -0
  54. package/dist/src/instrumentation/openai/get_bedrock_mantle_telemetry.js +33 -0
  55. package/dist/src/instrumentation/openai/get_cache_and_reasoning_telemetry.d.ts +13 -6
  56. package/dist/src/instrumentation/openai/get_cache_and_reasoning_telemetry.js +17 -7
  57. package/dist/src/instrumentation/openai/get_cache_config_telemetry.d.ts +21 -4
  58. package/dist/src/instrumentation/openai/get_cache_config_telemetry.js +50 -11
  59. package/dist/src/instrumentation/openai/get_embeddings_telemetry.js +14 -6
  60. package/dist/src/instrumentation/openai/get_file_part_mime_type_telemetry.d.ts +26 -0
  61. package/dist/src/instrumentation/openai/get_file_part_mime_type_telemetry.js +100 -0
  62. package/dist/src/instrumentation/openai/get_openai_compatible_provider_telemetry.d.ts +48 -0
  63. package/dist/src/instrumentation/openai/get_openai_compatible_provider_telemetry.js +123 -0
  64. package/dist/src/instrumentation/openai/get_reasoning_content_telemetry.d.ts +28 -0
  65. package/dist/src/instrumentation/openai/get_reasoning_content_telemetry.js +130 -0
  66. package/dist/src/instrumentation/openai/get_responses_telemetry.d.ts +89 -0
  67. package/dist/src/instrumentation/openai/get_responses_telemetry.js +587 -0
  68. package/dist/src/instrumentation/openai/get_service_tier_telemetry.d.ts +20 -0
  69. package/dist/src/instrumentation/openai/get_service_tier_telemetry.js +84 -0
  70. package/dist/src/instrumentation/openai/get_structured_output_schema_telemetry.d.ts +7 -5
  71. package/dist/src/instrumentation/openai/get_structured_output_schema_telemetry.js +15 -8
  72. package/dist/src/instrumentation/openai/get_vertex_openai_compatible_telemetry.d.ts +23 -0
  73. package/dist/src/instrumentation/openai/get_vertex_openai_compatible_telemetry.js +69 -0
  74. package/dist/src/instrumentation/openai/get_web_search_telemetry.d.ts +74 -0
  75. package/dist/src/instrumentation/openai/get_web_search_telemetry.js +259 -0
  76. package/dist/src/instrumentation/openai/set_telemetry_attributes.d.ts +13 -1
  77. package/dist/src/instrumentation/openai/set_telemetry_attributes.js +33 -2
  78. package/dist/src/instrumentation/shared/get_structured_output_schema_telemetry.d.ts +1 -1
  79. package/dist/src/instrumentation/shared/get_structured_output_schema_telemetry.js +1 -1
  80. package/dist/src/instrumentation/shared/is_vertex_base_url.d.ts +17 -0
  81. package/dist/src/instrumentation/shared/is_vertex_base_url.js +40 -0
  82. package/dist/src/otel/propagation.d.ts +37 -10
  83. package/dist/src/otel/propagation.js +62 -22
  84. package/dist/src/otel/span-filter.d.ts +2 -0
  85. package/dist/src/otel/span-filter.js +10 -1
  86. package/dist/src/otel/span-processor.d.ts +1 -2
  87. package/dist/src/otel/span-processor.js +17 -20
  88. package/dist/src/otel/strip-media-payloads.d.ts +26 -0
  89. package/dist/src/otel/strip-media-payloads.js +135 -0
  90. package/dist/src/propagate-metadata-to-gateway.d.ts +37 -0
  91. package/dist/src/propagate-metadata-to-gateway.js +213 -0
  92. package/package.json +8 -5
  93. package/dist/src/instrumentation/vercel/full_instrumentation.d.ts +0 -3
  94. package/dist/src/instrumentation/vercel/full_instrumentation.js +0 -54
  95. package/dist/src/instrumentation/vercel/get_cache_creation_telemetry.d.ts +0 -22
  96. package/dist/src/instrumentation/vercel/get_cache_creation_telemetry.js +0 -66
  97. package/dist/src/instrumentation/vercel/get_structured_output_schema_telemetry.d.ts +0 -24
  98. package/dist/src/instrumentation/vercel/get_structured_output_schema_telemetry.js +0 -84
  99. package/dist/src/otel/vercel-ai-sdk-span-filter.d.ts +0 -12
  100. package/dist/src/otel/vercel-ai-sdk-span-filter.js +0 -88
@@ -1,84 +0,0 @@
1
- "use strict";
2
- /**
3
- * Structured-output schema capture for Vercel AI SDK (ai >= 7) model-call spans.
4
- *
5
- * A `generateObject` call's schema is only ever emitted on the operation's ROOT
6
- * span (`onObjectOperationStart` stamps `ai.schema` there under the
7
- * supplemental-attributes opt-in) — and weflayr's span filter drops that
8
- * aggregate span, keeping one span per model call. So the schema never reaches
9
- * the exported span, even though the gateway bills it as input.
10
- *
11
- * The operation and its nested model call share one `callId` in the
12
- * dispatcher's call state. Wrap `onObjectOperationStart` to remember the
13
- * event's schema by callId, and `onObjectStepEnd` — the object operation's own
14
- * model-call hook, where the call state's `inferenceSpan` exists (object
15
- * operations never fire `onLanguageModelCallEnd`; verified live) — to stamp it
16
- * as `ai.schema` on that span, the attribute the worker already reads.
17
- * `cleanupCallState` is wrapped so an operation that errors before its model
18
- * call does not leak its entry.
19
- */
20
- Object.defineProperty(exports, "__esModule", { value: true });
21
- exports.VercelStructuredOutputSchemaInstrumentor = void 0;
22
- const SCHEMA_ATTR = 'ai.schema';
23
- class VercelStructuredOutputSchemaInstrumentor {
24
- // [owner, methodName, originalFunction] for uninstrument().
25
- _patched = [];
26
- _schemasByCallId = new Map();
27
- // No-op (and never throws) if the interface is missing — the worst case is
28
- // the schema capture staying empty, exactly the pre-complement behaviour.
29
- instrument(dispatcher) {
30
- if (!dispatcher ||
31
- typeof dispatcher.onObjectOperationStart !== 'function' ||
32
- typeof dispatcher.onObjectStepEnd !== 'function') {
33
- return;
34
- }
35
- const schemasByCallId = this._schemasByCallId;
36
- const originalOperationStart = dispatcher.onObjectOperationStart;
37
- dispatcher.onObjectOperationStart = function onObjectOperationStartWithSchema(event) {
38
- try {
39
- if (event && event.callId && event.schema && typeof event.schema === 'object') {
40
- schemasByCallId.set(event.callId, event.schema);
41
- }
42
- }
43
- catch {
44
- // Never break span creation over an enrichment failure.
45
- }
46
- return originalOperationStart.call(this, event);
47
- };
48
- this._patched.push([dispatcher, 'onObjectOperationStart', originalOperationStart]);
49
- const originalStepEnd = dispatcher.onObjectStepEnd;
50
- dispatcher.onObjectStepEnd = function onObjectStepEndWithSchema(event) {
51
- try {
52
- const schema = event && schemasByCallId.get(event.callId);
53
- if (schema) {
54
- const callState = this.getCallState && this.getCallState(event.callId);
55
- const span = callState && callState.inferenceSpan;
56
- if (span && typeof span.setAttribute === 'function') {
57
- span.setAttribute(SCHEMA_ATTR, JSON.stringify(schema));
58
- }
59
- }
60
- }
61
- catch {
62
- // Never break span finalization over an enrichment failure.
63
- }
64
- return originalStepEnd.call(this, event);
65
- };
66
- this._patched.push([dispatcher, 'onObjectStepEnd', originalStepEnd]);
67
- const originalCleanup = dispatcher.cleanupCallState;
68
- if (typeof originalCleanup === 'function') {
69
- dispatcher.cleanupCallState = function cleanupCallStateWithSchema(callId) {
70
- schemasByCallId.delete(callId);
71
- return originalCleanup.call(this, callId);
72
- };
73
- this._patched.push([dispatcher, 'cleanupCallState', originalCleanup]);
74
- }
75
- }
76
- uninstrument() {
77
- for (const [owner, methodName, original] of this._patched) {
78
- owner[methodName] = original;
79
- }
80
- this._patched = [];
81
- this._schemasByCallId.clear();
82
- }
83
- }
84
- exports.VercelStructuredOutputSchemaInstrumentor = VercelStructuredOutputSchemaInstrumentor;
@@ -1,12 +0,0 @@
1
- import type { ReadableSpan } from '@opentelemetry/sdk-trace-base';
2
- export declare class VercelAiSdkSpanFilter {
3
- private _openSpanOperations;
4
- private _openLegacySchemas;
5
- onStart(span: ReadableSpan): void;
6
- /**
7
- * Export verdict for a Vercel AI SDK span, or null when the span is not
8
- * one (the caller falls back to the default filter).
9
- */
10
- shouldExport(span: ReadableSpan): boolean | null;
11
- }
12
- export declare function stampVercelGatewayProviderName(span: ReadableSpan): void;
@@ -1,88 +0,0 @@
1
- "use strict";
2
- // The Vercel AI SDK's OTel integrations emit aggregate spans around each model
3
- // call, all repeating the same usage counts:
4
- // - `@ai-sdk/otel` (ai >= 7, scope "gen_ai"): per-call "chat" spans are
5
- // wrapped in "agent_step" + "invoke_agent" spans, and embed/embedMany
6
- // emits an outer "embeddings" operation span around the model-call
7
- // "embeddings" span(s).
8
- // - the legacy integration (ai <= 6, scope "ai"): `ai.<fn>.do<Call>` spans
9
- // are wrapped in an outer `ai.<fn>` span.
10
- // Exactly one span per model call may reach the exporter — exporting an
11
- // aggregate alongside its children would bill every call twice.
12
- Object.defineProperty(exports, "__esModule", { value: true });
13
- exports.VercelAiSdkSpanFilter = void 0;
14
- exports.stampVercelGatewayProviderName = stampVercelGatewayProviderName;
15
- const VERCEL_SEMCONV_SCOPE = 'gen_ai';
16
- const VERCEL_LEGACY_SCOPE = 'ai';
17
- const LEGACY_MODEL_CALL_SPAN_NAME = /\.do(Generate|Stream|Embed)$/;
18
- function _parentSpanId(span) {
19
- return span.parentSpanContext?.spanId ?? span.parentSpanId;
20
- }
21
- class VercelAiSdkSpanFilter {
22
- // spanId -> gen_ai.operation.name for open "gen_ai"-scope spans, so a
23
- // span can check what its parent is (children end before their parent).
24
- _openSpanOperations = new Map();
25
- // spanId -> ai.schema of open legacy generateObject/streamObject ROOT spans:
26
- // ai <= 6 records the schema only there, and this filter drops the root, so
27
- // the schema is copied onto the model-call child when it starts (the root's
28
- // creation attributes are already set by then).
29
- _openLegacySchemas = new Map();
30
- onStart(span) {
31
- const scope = span.instrumentationScope?.name;
32
- if (scope === VERCEL_LEGACY_SCOPE) {
33
- const schema = span.attributes['ai.schema'];
34
- if (schema !== undefined && !LEGACY_MODEL_CALL_SPAN_NAME.test(span.name)) {
35
- this._openLegacySchemas.set(span.spanContext().spanId, schema);
36
- }
37
- const parentSpanId = _parentSpanId(span);
38
- if (parentSpanId &&
39
- span.attributes['ai.schema'] === undefined &&
40
- this._openLegacySchemas.has(parentSpanId)) {
41
- span.attributes['ai.schema'] = this._openLegacySchemas.get(parentSpanId);
42
- }
43
- return;
44
- }
45
- if (scope !== VERCEL_SEMCONV_SCOPE)
46
- return;
47
- this._openSpanOperations.set(span.spanContext().spanId, span.attributes['gen_ai.operation.name']);
48
- }
49
- /**
50
- * Export verdict for a Vercel AI SDK span, or null when the span is not
51
- * one (the caller falls back to the default filter).
52
- */
53
- shouldExport(span) {
54
- const scope = span.instrumentationScope?.name;
55
- if (scope === VERCEL_LEGACY_SCOPE) {
56
- this._openLegacySchemas.delete(span.spanContext().spanId);
57
- return LEGACY_MODEL_CALL_SPAN_NAME.test(span.name);
58
- }
59
- if (scope !== VERCEL_SEMCONV_SCOPE) {
60
- return null;
61
- }
62
- const operation = span.attributes['gen_ai.operation.name'];
63
- this._openSpanOperations.delete(span.spanContext().spanId);
64
- if (operation === 'chat') {
65
- return true;
66
- }
67
- if (operation === 'embeddings') {
68
- // Keep the outer aggregate (one event per embed/embedMany call, with the
69
- // total usage) and drop the nested model-call span(s) repeating it.
70
- const parentSpanId = _parentSpanId(span);
71
- return (parentSpanId && this._openSpanOperations.get(parentSpanId)) !== 'embeddings';
72
- }
73
- // invoke_agent / agent_step (usage aggregates) and execute_tool (no usage).
74
- return false;
75
- }
76
- }
77
- exports.VercelAiSdkSpanFilter = VercelAiSdkSpanFilter;
78
- // `@ai-sdk/otel` reports the Vercel AI Gateway as the bare provider id
79
- // "gateway" — too generic a name to special-case downstream. Stamp the weflayr
80
- // provider override (which the normalizer prefers) with the canonical name.
81
- // A providerNameOverride set through propagateMetadata was stamped at span start and
82
- // wins.
83
- function stampVercelGatewayProviderName(span) {
84
- if (span.attributes['gen_ai.provider.name'] === 'gateway' &&
85
- span.attributes['weflayr.provider_name'] === undefined) {
86
- span.attributes['weflayr.provider_name'] = 'vercel_ai_gateway';
87
- }
88
- }