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
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The full Bedrock model id on invoke_model spans.
|
|
3
|
+
*
|
|
4
|
+
* `@traceloop/instrumentation-bedrock` splits the vendor segment off the
|
|
5
|
+
* requested `modelId` before stamping `gen_ai.request.model`:
|
|
6
|
+
* "amazon.nova-micro-v1:0" becomes "nova-micro-v1:0" and
|
|
7
|
+
* "us.anthropic.claude-haiku-4-5-20251001-v1:0" becomes
|
|
8
|
+
* "claude-haiku-4-5-20251001-v1:0". Neither stripped form matches anything in the
|
|
9
|
+
* pricing catalogue, whose Bedrock keys are the full ids, so those calls price at
|
|
10
|
+
* nothing.
|
|
11
|
+
*
|
|
12
|
+
* Wrap `_startSpan({ params })` to re-stamp the id exactly as requested (so it
|
|
13
|
+
* lands on error spans too). The Python SDK does the same from botocore's
|
|
14
|
+
* `_make_api_call`, and the normalizer prefers the request model over the
|
|
15
|
+
* response one for Bedrock-SDK spans.
|
|
16
|
+
*/
|
|
17
|
+
export declare class BedrockModelIdInstrumentor {
|
|
18
|
+
private _patched;
|
|
19
|
+
instrument(instrumentation: any): void;
|
|
20
|
+
uninstrument(): void;
|
|
21
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* The full Bedrock model id on invoke_model spans.
|
|
4
|
+
*
|
|
5
|
+
* `@traceloop/instrumentation-bedrock` splits the vendor segment off the
|
|
6
|
+
* requested `modelId` before stamping `gen_ai.request.model`:
|
|
7
|
+
* "amazon.nova-micro-v1:0" becomes "nova-micro-v1:0" and
|
|
8
|
+
* "us.anthropic.claude-haiku-4-5-20251001-v1:0" becomes
|
|
9
|
+
* "claude-haiku-4-5-20251001-v1:0". Neither stripped form matches anything in the
|
|
10
|
+
* pricing catalogue, whose Bedrock keys are the full ids, so those calls price at
|
|
11
|
+
* nothing.
|
|
12
|
+
*
|
|
13
|
+
* Wrap `_startSpan({ params })` to re-stamp the id exactly as requested (so it
|
|
14
|
+
* lands on error spans too). The Python SDK does the same from botocore's
|
|
15
|
+
* `_make_api_call`, and the normalizer prefers the request model over the
|
|
16
|
+
* response one for Bedrock-SDK spans.
|
|
17
|
+
*/
|
|
18
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
|
+
exports.BedrockModelIdInstrumentor = void 0;
|
|
20
|
+
const REQUEST_MODEL_ATTR = 'gen_ai.request.model';
|
|
21
|
+
class BedrockModelIdInstrumentor {
|
|
22
|
+
// [instrumentation, methodName, originalFunction] for uninstrument().
|
|
23
|
+
_patched = [];
|
|
24
|
+
// No-op (and never throws) if the instrumentor's internals have changed shape —
|
|
25
|
+
// the worst case is the stripped model id, never a crash.
|
|
26
|
+
instrument(instrumentation) {
|
|
27
|
+
if (!instrumentation)
|
|
28
|
+
return;
|
|
29
|
+
const original = instrumentation._startSpan;
|
|
30
|
+
if (typeof original !== 'function')
|
|
31
|
+
return;
|
|
32
|
+
instrumentation._startSpan = function startSpanWithFullModelId(request) {
|
|
33
|
+
const span = original.call(this, request);
|
|
34
|
+
try {
|
|
35
|
+
const modelId = request?.params?.input?.modelId;
|
|
36
|
+
if (span && typeof modelId === 'string' && modelId) {
|
|
37
|
+
span.setAttribute(REQUEST_MODEL_ATTR, modelId);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
catch {
|
|
41
|
+
// Never break span creation over an enrichment failure.
|
|
42
|
+
}
|
|
43
|
+
return span;
|
|
44
|
+
};
|
|
45
|
+
this._patched.push([instrumentation, '_startSpan', original]);
|
|
46
|
+
}
|
|
47
|
+
uninstrument() {
|
|
48
|
+
for (const [owner, methodName, original] of this._patched) {
|
|
49
|
+
owner[methodName] = original;
|
|
50
|
+
}
|
|
51
|
+
this._patched = [];
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
exports.BedrockModelIdInstrumentor = BedrockModelIdInstrumentor;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reasoning output parts for Claude-on-Bedrock invoke_model spans.
|
|
3
|
+
*
|
|
4
|
+
* `@traceloop/instrumentation-bedrock` maps each response content block through a
|
|
5
|
+
* mapper that does not know Anthropic's extended-thinking block, so a
|
|
6
|
+
* `{type: "thinking", thinking, signature}` block falls through unchanged and
|
|
7
|
+
* `gen_ai.output.messages` ends up holding Bedrock's raw block. Wrap
|
|
8
|
+
* `_setResponseAttributes` to rewrite those parts into the OTel
|
|
9
|
+
* `{type: "reasoning", content}` shape the Python SDK already emits, so both SDKs
|
|
10
|
+
* normalize a chain of thought identically.
|
|
11
|
+
*
|
|
12
|
+
* The block's `signature` (Anthropic's attestation of the thinking text) is
|
|
13
|
+
* dropped: it is not content, and the Python instrumentor does not emit it.
|
|
14
|
+
*/
|
|
15
|
+
export declare class BedrockReasoningOutputInstrumentor {
|
|
16
|
+
private _patched;
|
|
17
|
+
instrument(instrumentation: any): void;
|
|
18
|
+
uninstrument(): void;
|
|
19
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Reasoning output parts for Claude-on-Bedrock invoke_model spans.
|
|
4
|
+
*
|
|
5
|
+
* `@traceloop/instrumentation-bedrock` maps each response content block through a
|
|
6
|
+
* mapper that does not know Anthropic's extended-thinking block, so a
|
|
7
|
+
* `{type: "thinking", thinking, signature}` block falls through unchanged and
|
|
8
|
+
* `gen_ai.output.messages` ends up holding Bedrock's raw block. Wrap
|
|
9
|
+
* `_setResponseAttributes` to rewrite those parts into the OTel
|
|
10
|
+
* `{type: "reasoning", content}` shape the Python SDK already emits, so both SDKs
|
|
11
|
+
* normalize a chain of thought identically.
|
|
12
|
+
*
|
|
13
|
+
* The block's `signature` (Anthropic's attestation of the thinking text) is
|
|
14
|
+
* dropped: it is not content, and the Python instrumentor does not emit it.
|
|
15
|
+
*/
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.BedrockReasoningOutputInstrumentor = void 0;
|
|
18
|
+
function _mapThinkingPart(part) {
|
|
19
|
+
if (!part || part.type !== 'thinking' || typeof part.thinking !== 'string')
|
|
20
|
+
return part;
|
|
21
|
+
return { type: 'reasoning', content: part.thinking };
|
|
22
|
+
}
|
|
23
|
+
function _rewriteReasoningParts(rawOutputMessages) {
|
|
24
|
+
if (typeof rawOutputMessages !== 'string')
|
|
25
|
+
return null;
|
|
26
|
+
let messages;
|
|
27
|
+
try {
|
|
28
|
+
messages = JSON.parse(rawOutputMessages);
|
|
29
|
+
}
|
|
30
|
+
catch {
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
if (!Array.isArray(messages))
|
|
34
|
+
return null;
|
|
35
|
+
let rewroteAny = false;
|
|
36
|
+
const rewritten = messages.map((message) => {
|
|
37
|
+
if (!message || !Array.isArray(message.parts))
|
|
38
|
+
return message;
|
|
39
|
+
const parts = message.parts.map((part) => {
|
|
40
|
+
const mapped = _mapThinkingPart(part);
|
|
41
|
+
if (mapped !== part)
|
|
42
|
+
rewroteAny = true;
|
|
43
|
+
return mapped;
|
|
44
|
+
});
|
|
45
|
+
return { ...message, parts };
|
|
46
|
+
});
|
|
47
|
+
return rewroteAny ? JSON.stringify(rewritten) : null;
|
|
48
|
+
}
|
|
49
|
+
class BedrockReasoningOutputInstrumentor {
|
|
50
|
+
// [instrumentation, methodName, originalFunction] for uninstrument().
|
|
51
|
+
_patched = [];
|
|
52
|
+
// No-op (and never throws) if the instrumentor's internals have changed shape —
|
|
53
|
+
// the worst case is the raw upstream part shape, never a crash.
|
|
54
|
+
instrument(instrumentation) {
|
|
55
|
+
if (!instrumentation)
|
|
56
|
+
return;
|
|
57
|
+
const original = instrumentation._setResponseAttributes;
|
|
58
|
+
if (typeof original !== 'function')
|
|
59
|
+
return;
|
|
60
|
+
instrumentation._setResponseAttributes = function setResponseAttributesWithReasoning(...args) {
|
|
61
|
+
const attributes = original.apply(this, args);
|
|
62
|
+
try {
|
|
63
|
+
const rewritten = _rewriteReasoningParts(attributes['gen_ai.output.messages']);
|
|
64
|
+
if (rewritten !== null)
|
|
65
|
+
attributes['gen_ai.output.messages'] = rewritten;
|
|
66
|
+
}
|
|
67
|
+
catch {
|
|
68
|
+
// Never break the response handling over an enrichment failure.
|
|
69
|
+
}
|
|
70
|
+
return attributes;
|
|
71
|
+
};
|
|
72
|
+
this._patched.push([instrumentation, '_setResponseAttributes', original]);
|
|
73
|
+
}
|
|
74
|
+
uninstrument() {
|
|
75
|
+
for (const [owner, methodName, original] of this._patched) {
|
|
76
|
+
owner[methodName] = original;
|
|
77
|
+
}
|
|
78
|
+
this._patched = [];
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
exports.BedrockReasoningOutputInstrumentor = BedrockReasoningOutputInstrumentor;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Streamed-output message content for the Bedrock invoke_model stream span.
|
|
3
|
+
*
|
|
4
|
+
* `@traceloop/instrumentation-bedrock` accumulates the streamed text but formats
|
|
5
|
+
* the final `gen_ai.output.messages` by passing that string through its chat
|
|
6
|
+
* block mapper, which only accepts block arrays — so streamed Nova spans end up
|
|
7
|
+
* with an assistant message whose `parts` is empty. This complement wraps the
|
|
8
|
+
* instrumentor's per-chunk `_handleNovaStreamingMetadata(span, parsedResponse)`
|
|
9
|
+
* hook: it accumulates the `contentBlockDelta` text and the `messageStop` stop
|
|
10
|
+
* reason itself, and re-stamps a correct output message when the trailing
|
|
11
|
+
* `metadata` chunk (always last in a Nova stream) arrives — after the
|
|
12
|
+
* instrumentor has written its empty-parts message. The span processor strips
|
|
13
|
+
* the attribute when message-content capture is disabled.
|
|
14
|
+
*
|
|
15
|
+
* A streamed tool call is accumulated the same way and for the same reason:
|
|
16
|
+
* `contentBlockStart` opens it with an id and name, `contentBlockDelta` appends
|
|
17
|
+
* its JSON arguments in fragments, and upstream reads neither — so without this
|
|
18
|
+
* a forced tool call streams into an empty message carrying only
|
|
19
|
+
* `finish_reason: "tool_call"`. Upstream accumulates tool blocks on the Converse
|
|
20
|
+
* API path only, never on InvokeModelWithResponseStream.
|
|
21
|
+
*/
|
|
22
|
+
export declare class BedrockStreamingOutputMessageInstrumentor {
|
|
23
|
+
private _patched;
|
|
24
|
+
private _streamStateBySpan;
|
|
25
|
+
instrument(instrumentation: any): void;
|
|
26
|
+
uninstrument(): void;
|
|
27
|
+
}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Streamed-output message content for the Bedrock invoke_model stream span.
|
|
4
|
+
*
|
|
5
|
+
* `@traceloop/instrumentation-bedrock` accumulates the streamed text but formats
|
|
6
|
+
* the final `gen_ai.output.messages` by passing that string through its chat
|
|
7
|
+
* block mapper, which only accepts block arrays — so streamed Nova spans end up
|
|
8
|
+
* with an assistant message whose `parts` is empty. This complement wraps the
|
|
9
|
+
* instrumentor's per-chunk `_handleNovaStreamingMetadata(span, parsedResponse)`
|
|
10
|
+
* hook: it accumulates the `contentBlockDelta` text and the `messageStop` stop
|
|
11
|
+
* reason itself, and re-stamps a correct output message when the trailing
|
|
12
|
+
* `metadata` chunk (always last in a Nova stream) arrives — after the
|
|
13
|
+
* instrumentor has written its empty-parts message. The span processor strips
|
|
14
|
+
* the attribute when message-content capture is disabled.
|
|
15
|
+
*
|
|
16
|
+
* A streamed tool call is accumulated the same way and for the same reason:
|
|
17
|
+
* `contentBlockStart` opens it with an id and name, `contentBlockDelta` appends
|
|
18
|
+
* its JSON arguments in fragments, and upstream reads neither — so without this
|
|
19
|
+
* a forced tool call streams into an empty message carrying only
|
|
20
|
+
* `finish_reason: "tool_call"`. Upstream accumulates tool blocks on the Converse
|
|
21
|
+
* API path only, never on InvokeModelWithResponseStream.
|
|
22
|
+
*/
|
|
23
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
24
|
+
exports.BedrockStreamingOutputMessageInstrumentor = void 0;
|
|
25
|
+
// Nova stop reasons mapped to the OTel finish_reason values the instrumentor
|
|
26
|
+
// uses on non-streamed spans, so streamed and non-streamed rows normalize alike.
|
|
27
|
+
const FINISH_REASON_BY_STOP_REASON = {
|
|
28
|
+
end_turn: 'stop',
|
|
29
|
+
stop_sequence: 'stop',
|
|
30
|
+
max_tokens: 'length',
|
|
31
|
+
tool_use: 'tool_call',
|
|
32
|
+
};
|
|
33
|
+
function _parseArguments(argumentsJson) {
|
|
34
|
+
try {
|
|
35
|
+
return JSON.parse(argumentsJson);
|
|
36
|
+
}
|
|
37
|
+
catch {
|
|
38
|
+
return argumentsJson;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
/** Gather a streamed tool call across the chunks that carry it. */
|
|
42
|
+
function _accumulateToolCall(state, parsedResponse) {
|
|
43
|
+
const startToolUse = parsedResponse?.contentBlockStart?.start?.toolUse;
|
|
44
|
+
if (startToolUse) {
|
|
45
|
+
state.toolCalls.push({
|
|
46
|
+
id: startToolUse.toolUseId,
|
|
47
|
+
name: startToolUse.name,
|
|
48
|
+
arguments: '',
|
|
49
|
+
});
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
const deltaToolUse = parsedResponse?.contentBlockDelta?.delta?.toolUse;
|
|
53
|
+
if (deltaToolUse && state.toolCalls.length) {
|
|
54
|
+
state.toolCalls[state.toolCalls.length - 1].arguments += deltaToolUse.input ?? '';
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
class BedrockStreamingOutputMessageInstrumentor {
|
|
58
|
+
// [instrumentation, methodName, originalFunction] for uninstrument().
|
|
59
|
+
_patched = [];
|
|
60
|
+
// span -> {text, stopReason} accumulated across the stream's chunks.
|
|
61
|
+
_streamStateBySpan = new WeakMap();
|
|
62
|
+
// No-op (and never throws) if the instrumentor's internals have changed shape —
|
|
63
|
+
// the worst case is an empty streamed output message, never a crash.
|
|
64
|
+
instrument(instrumentation) {
|
|
65
|
+
if (!instrumentation)
|
|
66
|
+
return;
|
|
67
|
+
const original = instrumentation._handleNovaStreamingMetadata;
|
|
68
|
+
if (typeof original !== 'function')
|
|
69
|
+
return;
|
|
70
|
+
const streamStateBySpan = this._streamStateBySpan;
|
|
71
|
+
instrumentation._handleNovaStreamingMetadata = function handleWithOutputMessage(span, parsedResponse) {
|
|
72
|
+
try {
|
|
73
|
+
const state = streamStateBySpan.get(span) || {
|
|
74
|
+
text: '',
|
|
75
|
+
stopReason: null,
|
|
76
|
+
toolCalls: [],
|
|
77
|
+
};
|
|
78
|
+
const delta = parsedResponse &&
|
|
79
|
+
parsedResponse.contentBlockDelta &&
|
|
80
|
+
parsedResponse.contentBlockDelta.delta &&
|
|
81
|
+
parsedResponse.contentBlockDelta.delta.text;
|
|
82
|
+
if (typeof delta === 'string')
|
|
83
|
+
state.text += delta;
|
|
84
|
+
const stopReason = parsedResponse && parsedResponse.messageStop && parsedResponse.messageStop.stopReason;
|
|
85
|
+
if (stopReason != null)
|
|
86
|
+
state.stopReason = stopReason;
|
|
87
|
+
_accumulateToolCall(state, parsedResponse);
|
|
88
|
+
streamStateBySpan.set(span, state);
|
|
89
|
+
if (parsedResponse && parsedResponse.metadata && (state.text || state.toolCalls.length)) {
|
|
90
|
+
const parts = [];
|
|
91
|
+
if (state.text)
|
|
92
|
+
parts.push({ type: 'text', content: state.text });
|
|
93
|
+
for (const toolCall of state.toolCalls) {
|
|
94
|
+
parts.push({
|
|
95
|
+
type: 'tool_call',
|
|
96
|
+
id: toolCall.id,
|
|
97
|
+
name: toolCall.name,
|
|
98
|
+
arguments: _parseArguments(toolCall.arguments),
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
const message = {
|
|
102
|
+
role: 'assistant',
|
|
103
|
+
parts,
|
|
104
|
+
};
|
|
105
|
+
if (state.stopReason != null) {
|
|
106
|
+
message.finish_reason =
|
|
107
|
+
FINISH_REASON_BY_STOP_REASON[state.stopReason] || state.stopReason;
|
|
108
|
+
}
|
|
109
|
+
span.setAttribute('gen_ai.output.messages', JSON.stringify([message]));
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
catch {
|
|
113
|
+
// Never break the caller's stream over an enrichment failure.
|
|
114
|
+
}
|
|
115
|
+
return original.call(this, span, parsedResponse);
|
|
116
|
+
};
|
|
117
|
+
this._patched.push([instrumentation, '_handleNovaStreamingMetadata', original]);
|
|
118
|
+
}
|
|
119
|
+
uninstrument() {
|
|
120
|
+
for (const [owner, methodName, original] of this._patched) {
|
|
121
|
+
owner[methodName] = original;
|
|
122
|
+
}
|
|
123
|
+
this._patched = [];
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
exports.BedrockStreamingOutputMessageInstrumentor = BedrockStreamingOutputMessageInstrumentor;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tool-call output parts for Bedrock invoke_model spans.
|
|
3
|
+
*
|
|
4
|
+
* `@traceloop/instrumentation-bedrock` maps each response content block through
|
|
5
|
+
* a mapper keyed on Anthropic's block vocabulary (`{type: "tool_use"}`). Nova's
|
|
6
|
+
* InvokeModel response instead returns `{toolUse: {name, toolUseId, input}}`
|
|
7
|
+
* blocks, which carry no `type`, so they fall through the mapper unchanged and
|
|
8
|
+
* `gen_ai.output.messages` ends up holding Bedrock's raw block. Wrap
|
|
9
|
+
* `_setResponseAttributes` to rewrite those parts into the OTel
|
|
10
|
+
* `{type: "tool_call", id, name, arguments}` shape the Python SDK already
|
|
11
|
+
* emits, so both SDKs normalize a tool call identically.
|
|
12
|
+
*/
|
|
13
|
+
export declare class BedrockToolCallOutputInstrumentor {
|
|
14
|
+
private _patched;
|
|
15
|
+
instrument(instrumentation: any): void;
|
|
16
|
+
uninstrument(): void;
|
|
17
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Tool-call output parts for Bedrock invoke_model spans.
|
|
4
|
+
*
|
|
5
|
+
* `@traceloop/instrumentation-bedrock` maps each response content block through
|
|
6
|
+
* a mapper keyed on Anthropic's block vocabulary (`{type: "tool_use"}`). Nova's
|
|
7
|
+
* InvokeModel response instead returns `{toolUse: {name, toolUseId, input}}`
|
|
8
|
+
* blocks, which carry no `type`, so they fall through the mapper unchanged and
|
|
9
|
+
* `gen_ai.output.messages` ends up holding Bedrock's raw block. Wrap
|
|
10
|
+
* `_setResponseAttributes` to rewrite those parts into the OTel
|
|
11
|
+
* `{type: "tool_call", id, name, arguments}` shape the Python SDK already
|
|
12
|
+
* emits, so both SDKs normalize a tool call identically.
|
|
13
|
+
*/
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.BedrockToolCallOutputInstrumentor = void 0;
|
|
16
|
+
function _mapToolUsePart(part) {
|
|
17
|
+
const toolUse = part && part.toolUse;
|
|
18
|
+
if (!toolUse || typeof toolUse !== 'object')
|
|
19
|
+
return part;
|
|
20
|
+
return {
|
|
21
|
+
type: 'tool_call',
|
|
22
|
+
id: toolUse.toolUseId,
|
|
23
|
+
name: toolUse.name,
|
|
24
|
+
arguments: toolUse.input,
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
function _rewriteToolCallParts(rawOutputMessages) {
|
|
28
|
+
if (typeof rawOutputMessages !== 'string')
|
|
29
|
+
return null;
|
|
30
|
+
let messages;
|
|
31
|
+
try {
|
|
32
|
+
messages = JSON.parse(rawOutputMessages);
|
|
33
|
+
}
|
|
34
|
+
catch {
|
|
35
|
+
return null;
|
|
36
|
+
}
|
|
37
|
+
if (!Array.isArray(messages))
|
|
38
|
+
return null;
|
|
39
|
+
let rewroteAny = false;
|
|
40
|
+
const rewritten = messages.map((message) => {
|
|
41
|
+
if (!message || !Array.isArray(message.parts))
|
|
42
|
+
return message;
|
|
43
|
+
const parts = message.parts.map((part) => {
|
|
44
|
+
const mapped = _mapToolUsePart(part);
|
|
45
|
+
if (mapped !== part)
|
|
46
|
+
rewroteAny = true;
|
|
47
|
+
return mapped;
|
|
48
|
+
});
|
|
49
|
+
return { ...message, parts };
|
|
50
|
+
});
|
|
51
|
+
return rewroteAny ? JSON.stringify(rewritten) : null;
|
|
52
|
+
}
|
|
53
|
+
class BedrockToolCallOutputInstrumentor {
|
|
54
|
+
// [instrumentation, methodName, originalFunction] for uninstrument().
|
|
55
|
+
_patched = [];
|
|
56
|
+
// No-op (and never throws) if the instrumentor's internals have changed shape —
|
|
57
|
+
// the worst case is the raw upstream part shape, never a crash.
|
|
58
|
+
instrument(instrumentation) {
|
|
59
|
+
if (!instrumentation)
|
|
60
|
+
return;
|
|
61
|
+
const original = instrumentation._setResponseAttributes;
|
|
62
|
+
if (typeof original !== 'function')
|
|
63
|
+
return;
|
|
64
|
+
instrumentation._setResponseAttributes = function setResponseAttributesWithToolCalls(...args) {
|
|
65
|
+
const attributes = original.apply(this, args);
|
|
66
|
+
try {
|
|
67
|
+
const rewritten = _rewriteToolCallParts(attributes['gen_ai.output.messages']);
|
|
68
|
+
if (rewritten !== null)
|
|
69
|
+
attributes['gen_ai.output.messages'] = rewritten;
|
|
70
|
+
}
|
|
71
|
+
catch {
|
|
72
|
+
// Never break the response handling over an enrichment failure.
|
|
73
|
+
}
|
|
74
|
+
return attributes;
|
|
75
|
+
};
|
|
76
|
+
this._patched.push([instrumentation, '_setResponseAttributes', original]);
|
|
77
|
+
}
|
|
78
|
+
uninstrument() {
|
|
79
|
+
for (const [owner, methodName, original] of this._patched) {
|
|
80
|
+
owner[methodName] = original;
|
|
81
|
+
}
|
|
82
|
+
this._patched = [];
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
exports.BedrockToolCallOutputInstrumentor = BedrockToolCallOutputInstrumentor;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tool definitions for Bedrock invoke_model spans.
|
|
3
|
+
*
|
|
4
|
+
* `@traceloop/instrumentation-bedrock` reads the request body for the prompt and
|
|
5
|
+
* the inference config but never for its `toolConfig`, so a tool-using call
|
|
6
|
+
* carries no `gen_ai.tool.definitions`. Wrap the instrumentor's
|
|
7
|
+
* `_startSpan({ params })` to stamp the definitions from the request body,
|
|
8
|
+
* unwrapping each entry's `toolSpec` so the attribute holds the bare
|
|
9
|
+
* `{name, description, inputSchema}` definitions rather than Bedrock's wrapper.
|
|
10
|
+
*/
|
|
11
|
+
export declare class BedrockToolDefinitionsInstrumentor {
|
|
12
|
+
private _patched;
|
|
13
|
+
instrument(instrumentation: any): void;
|
|
14
|
+
uninstrument(): void;
|
|
15
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Tool definitions for Bedrock invoke_model spans.
|
|
4
|
+
*
|
|
5
|
+
* `@traceloop/instrumentation-bedrock` reads the request body for the prompt and
|
|
6
|
+
* the inference config but never for its `toolConfig`, so a tool-using call
|
|
7
|
+
* carries no `gen_ai.tool.definitions`. Wrap the instrumentor's
|
|
8
|
+
* `_startSpan({ params })` to stamp the definitions from the request body,
|
|
9
|
+
* unwrapping each entry's `toolSpec` so the attribute holds the bare
|
|
10
|
+
* `{name, description, inputSchema}` definitions rather than Bedrock's wrapper.
|
|
11
|
+
*/
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
exports.BedrockToolDefinitionsInstrumentor = void 0;
|
|
14
|
+
// The bare tool definitions from an InvokeModel JSON body, e.g.
|
|
15
|
+
// `{"toolConfig": {"tools": [{"toolSpec": {"name": "get_weather", ...}}]}}`
|
|
16
|
+
// -> `[{"name": "get_weather", ...}]`.
|
|
17
|
+
function _toolDefinitionsFromRequestBody(rawBody) {
|
|
18
|
+
if (typeof rawBody !== 'string')
|
|
19
|
+
return [];
|
|
20
|
+
let body;
|
|
21
|
+
try {
|
|
22
|
+
body = JSON.parse(rawBody);
|
|
23
|
+
}
|
|
24
|
+
catch {
|
|
25
|
+
return [];
|
|
26
|
+
}
|
|
27
|
+
const tools = body && body.toolConfig && body.toolConfig.tools;
|
|
28
|
+
if (!Array.isArray(tools))
|
|
29
|
+
return [];
|
|
30
|
+
return tools
|
|
31
|
+
.filter((tool) => tool && typeof tool.toolSpec === 'object' && tool.toolSpec !== null)
|
|
32
|
+
.map((tool) => tool.toolSpec);
|
|
33
|
+
}
|
|
34
|
+
class BedrockToolDefinitionsInstrumentor {
|
|
35
|
+
// [instrumentation, methodName, originalFunction] for uninstrument().
|
|
36
|
+
_patched = [];
|
|
37
|
+
// No-op (and never throws) if the instrumentor's internals have changed shape —
|
|
38
|
+
// the worst case is missing tool definitions, never a crash.
|
|
39
|
+
instrument(instrumentation) {
|
|
40
|
+
if (!instrumentation)
|
|
41
|
+
return;
|
|
42
|
+
const original = instrumentation._startSpan;
|
|
43
|
+
if (typeof original !== 'function')
|
|
44
|
+
return;
|
|
45
|
+
instrumentation._startSpan = function startSpanWithToolDefinitions(request) {
|
|
46
|
+
const span = original.call(this, request);
|
|
47
|
+
try {
|
|
48
|
+
const body = request && request.params && request.params.input && request.params.input.body;
|
|
49
|
+
const definitions = _toolDefinitionsFromRequestBody(body);
|
|
50
|
+
if (definitions.length) {
|
|
51
|
+
span.setAttribute('gen_ai.tool.definitions', JSON.stringify(definitions));
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
catch {
|
|
55
|
+
// Never break span creation over an enrichment failure.
|
|
56
|
+
}
|
|
57
|
+
return span;
|
|
58
|
+
};
|
|
59
|
+
this._patched.push([instrumentation, '_startSpan', original]);
|
|
60
|
+
}
|
|
61
|
+
uninstrument() {
|
|
62
|
+
for (const [owner, methodName, original] of this._patched) {
|
|
63
|
+
owner[methodName] = original;
|
|
64
|
+
}
|
|
65
|
+
this._patched = [];
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
exports.BedrockToolDefinitionsInstrumentor = BedrockToolDefinitionsInstrumentor;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Bedrock telemetry complement — the registered orchestrator.
|
|
3
|
+
*
|
|
4
|
+
* Wires the weflayr-supplied patches the traceloop Bedrock instrumentor misses:
|
|
5
|
+
* cached-prompt token counts on the invoke_model span (Nova returns them in the
|
|
6
|
+
* response body but traceloop never reads them), the request's cache
|
|
7
|
+
* breakpoints (`cache_control` / `cachePoint` blocks it never records), the
|
|
8
|
+
* streamed output message content (its stream path formats an empty-parts
|
|
9
|
+
* message), the request's tool definitions (it never reads the body's
|
|
10
|
+
* `toolConfig`) and the tool-call output parts (its block mapper only knows
|
|
11
|
+
* Anthropic's block shape, so Nova's `toolUse` blocks come through raw).
|
|
12
|
+
*/
|
|
13
|
+
export declare class BedrockTelemetryInstrumentor {
|
|
14
|
+
private _subInstrumentors;
|
|
15
|
+
constructor();
|
|
16
|
+
instrument(instrumentation: any): void;
|
|
17
|
+
uninstrument(): void;
|
|
18
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Bedrock telemetry complement — the registered orchestrator.
|
|
4
|
+
*
|
|
5
|
+
* Wires the weflayr-supplied patches the traceloop Bedrock instrumentor misses:
|
|
6
|
+
* cached-prompt token counts on the invoke_model span (Nova returns them in the
|
|
7
|
+
* response body but traceloop never reads them), the request's cache
|
|
8
|
+
* breakpoints (`cache_control` / `cachePoint` blocks it never records), the
|
|
9
|
+
* streamed output message content (its stream path formats an empty-parts
|
|
10
|
+
* message), the request's tool definitions (it never reads the body's
|
|
11
|
+
* `toolConfig`) and the tool-call output parts (its block mapper only knows
|
|
12
|
+
* Anthropic's block shape, so Nova's `toolUse` blocks come through raw).
|
|
13
|
+
*/
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.BedrockTelemetryInstrumentor = void 0;
|
|
16
|
+
const get_cache_config_telemetry_1 = require("./get_cache_config_telemetry");
|
|
17
|
+
const get_cache_telemetry_1 = require("./get_cache_telemetry");
|
|
18
|
+
const get_input_message_content_telemetry_1 = require("./get_input_message_content_telemetry");
|
|
19
|
+
const get_streaming_output_message_telemetry_1 = require("./get_streaming_output_message_telemetry");
|
|
20
|
+
const get_model_id_telemetry_1 = require("./get_model_id_telemetry");
|
|
21
|
+
const get_reasoning_output_telemetry_1 = require("./get_reasoning_output_telemetry");
|
|
22
|
+
const get_tool_call_output_telemetry_1 = require("./get_tool_call_output_telemetry");
|
|
23
|
+
const get_tool_definitions_telemetry_1 = require("./get_tool_definitions_telemetry");
|
|
24
|
+
class BedrockTelemetryInstrumentor {
|
|
25
|
+
_subInstrumentors;
|
|
26
|
+
constructor() {
|
|
27
|
+
this._subInstrumentors = [
|
|
28
|
+
new get_cache_telemetry_1.BedrockPromptCachingInstrumentor(),
|
|
29
|
+
new get_cache_config_telemetry_1.BedrockCacheConfigInstrumentor(),
|
|
30
|
+
new get_input_message_content_telemetry_1.BedrockInputMessageContentInstrumentor(),
|
|
31
|
+
new get_streaming_output_message_telemetry_1.BedrockStreamingOutputMessageInstrumentor(),
|
|
32
|
+
new get_tool_definitions_telemetry_1.BedrockToolDefinitionsInstrumentor(),
|
|
33
|
+
new get_tool_call_output_telemetry_1.BedrockToolCallOutputInstrumentor(),
|
|
34
|
+
new get_model_id_telemetry_1.BedrockModelIdInstrumentor(),
|
|
35
|
+
new get_reasoning_output_telemetry_1.BedrockReasoningOutputInstrumentor(),
|
|
36
|
+
];
|
|
37
|
+
}
|
|
38
|
+
instrument(instrumentation) {
|
|
39
|
+
for (const sub of this._subInstrumentors)
|
|
40
|
+
sub.instrument(instrumentation);
|
|
41
|
+
}
|
|
42
|
+
uninstrument() {
|
|
43
|
+
for (const sub of this._subInstrumentors)
|
|
44
|
+
sub.uninstrument();
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
exports.BedrockTelemetryInstrumentor = BedrockTelemetryInstrumentor;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Chat token-usage enrichment complement for the Cohere v1 chat path.
|
|
3
|
+
*
|
|
4
|
+
* `@traceloop/instrumentation-cohere` creates the `cohere.chat` span but reads
|
|
5
|
+
* token usage from the obsolete `result.token_count.{prompt,response}_tokens`
|
|
6
|
+
* shape; modern cohere-ai returns usage under `meta.billedUnits` instead, so the
|
|
7
|
+
* traceloop span ends up with zero chat tokens. This thin complement backfills
|
|
8
|
+
* `gen_ai.usage.{input,output}_tokens` from `meta.billedUnits`, the same source
|
|
9
|
+
* traceloop already uses for the `generate` endpoint — bringing Node chat tokens
|
|
10
|
+
* to parity with the Python SDK (OpenLLMetry captures them natively, so there is
|
|
11
|
+
* no Python counterpart).
|
|
12
|
+
*
|
|
13
|
+
* It hooks the internal `CohereClient.prototype.__chat` (which the public `chat`
|
|
14
|
+
* delegates to synchronously) rather than the public `chat`: traceloop wraps
|
|
15
|
+
* `chat` and opens the span around it, so `__chat` runs while that span is the
|
|
16
|
+
* active span — letting this complement enrich it regardless of patch order.
|
|
17
|
+
*/
|
|
18
|
+
export declare class CohereChatTokenUsageInstrumentor {
|
|
19
|
+
private _patched;
|
|
20
|
+
instrument(): void;
|
|
21
|
+
uninstrument(): void;
|
|
22
|
+
private _wrap;
|
|
23
|
+
}
|