shield360 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/README.md +310 -0
- package/dist/__tests__/manual-trace.test.d.ts +1 -0
- package/dist/__tests__/manual-trace.test.js +118 -0
- package/dist/__tests__/manual-trace.test.js.map +1 -0
- package/dist/__tests__/register.test.d.ts +0 -0
- package/dist/__tests__/register.test.js +90 -0
- package/dist/__tests__/register.test.js.map +1 -0
- package/dist/config.d.ts +28 -0
- package/dist/config.js +22 -0
- package/dist/config.js.map +1 -0
- package/dist/constant.d.ts +6 -0
- package/dist/constant.js +14 -0
- package/dist/constant.js.map +1 -0
- package/dist/evals/__tests__/offline.test.d.ts +1 -0
- package/dist/evals/__tests__/offline.test.js +427 -0
- package/dist/evals/__tests__/offline.test.js.map +1 -0
- package/dist/evals/index.d.ts +2 -0
- package/dist/evals/index.js +15 -0
- package/dist/evals/index.js.map +1 -0
- package/dist/evals/offline.d.ts +6 -0
- package/dist/evals/offline.js +350 -0
- package/dist/evals/offline.js.map +1 -0
- package/dist/evals/types.d.ts +74 -0
- package/dist/evals/types.js +23 -0
- package/dist/evals/types.js.map +1 -0
- package/dist/features/__tests__/rule-engine.test.d.ts +1 -0
- package/dist/features/__tests__/rule-engine.test.js +146 -0
- package/dist/features/__tests__/rule-engine.test.js.map +1 -0
- package/dist/features/base.d.ts +8 -0
- package/dist/features/base.js +15 -0
- package/dist/features/base.js.map +1 -0
- package/dist/features/prompt-hub.d.ts +4 -0
- package/dist/features/prompt-hub.js +66 -0
- package/dist/features/prompt-hub.js.map +1 -0
- package/dist/features/rule-engine.d.ts +6 -0
- package/dist/features/rule-engine.js +60 -0
- package/dist/features/rule-engine.js.map +1 -0
- package/dist/features/vault.d.ts +4 -0
- package/dist/features/vault.js +63 -0
- package/dist/features/vault.js.map +1 -0
- package/dist/guard/__tests__/findings.test.d.ts +1 -0
- package/dist/guard/__tests__/findings.test.js +79 -0
- package/dist/guard/__tests__/findings.test.js.map +1 -0
- package/dist/guard/__tests__/integration.test.d.ts +1 -0
- package/dist/guard/__tests__/integration.test.js +215 -0
- package/dist/guard/__tests__/integration.test.js.map +1 -0
- package/dist/guard/__tests__/pii.test.d.ts +1 -0
- package/dist/guard/__tests__/pii.test.js +131 -0
- package/dist/guard/__tests__/pii.test.js.map +1 -0
- package/dist/guard/__tests__/pipeline.test.d.ts +1 -0
- package/dist/guard/__tests__/pipeline.test.js +162 -0
- package/dist/guard/__tests__/pipeline.test.js.map +1 -0
- package/dist/guard/__tests__/prompt-injection.test.d.ts +1 -0
- package/dist/guard/__tests__/prompt-injection.test.js +92 -0
- package/dist/guard/__tests__/prompt-injection.test.js.map +1 -0
- package/dist/guard/__tests__/report.test.d.ts +1 -0
- package/dist/guard/__tests__/report.test.js +50 -0
- package/dist/guard/__tests__/report.test.js.map +1 -0
- package/dist/guard/base.d.ts +79 -0
- package/dist/guard/base.js +136 -0
- package/dist/guard/base.js.map +1 -0
- package/dist/guard/custom.d.ts +19 -0
- package/dist/guard/custom.js +46 -0
- package/dist/guard/custom.js.map +1 -0
- package/dist/guard/findings.d.ts +31 -0
- package/dist/guard/findings.js +156 -0
- package/dist/guard/findings.js.map +1 -0
- package/dist/guard/index.d.ts +24 -0
- package/dist/guard/index.js +42 -0
- package/dist/guard/index.js.map +1 -0
- package/dist/guard/integration.d.ts +44 -0
- package/dist/guard/integration.js +363 -0
- package/dist/guard/integration.js.map +1 -0
- package/dist/guard/moderation.d.ts +18 -0
- package/dist/guard/moderation.js +61 -0
- package/dist/guard/moderation.js.map +1 -0
- package/dist/guard/pii.d.ts +17 -0
- package/dist/guard/pii.js +114 -0
- package/dist/guard/pii.js.map +1 -0
- package/dist/guard/pipeline.d.ts +26 -0
- package/dist/guard/pipeline.js +139 -0
- package/dist/guard/pipeline.js.map +1 -0
- package/dist/guard/prompt-injection.d.ts +21 -0
- package/dist/guard/prompt-injection.js +70 -0
- package/dist/guard/prompt-injection.js.map +1 -0
- package/dist/guard/report.d.ts +34 -0
- package/dist/guard/report.js +182 -0
- package/dist/guard/report.js.map +1 -0
- package/dist/guard/schema.d.ts +20 -0
- package/dist/guard/schema.js +99 -0
- package/dist/guard/schema.js.map +1 -0
- package/dist/guard/sensitive-topic.d.ts +23 -0
- package/dist/guard/sensitive-topic.js +89 -0
- package/dist/guard/sensitive-topic.js.map +1 -0
- package/dist/guard/topic-restriction.d.ts +22 -0
- package/dist/guard/topic-restriction.js +54 -0
- package/dist/guard/topic-restriction.js.map +1 -0
- package/dist/helpers.d.ts +246 -0
- package/dist/helpers.js +903 -0
- package/dist/helpers.js.map +1 -0
- package/dist/index.d.ts +71 -0
- package/dist/index.js +234 -0
- package/dist/index.js.map +1 -0
- package/dist/instrumentation/__tests__/ai21-rag-trace-comparison.test.d.ts +13 -0
- package/dist/instrumentation/__tests__/ai21-rag-trace-comparison.test.js +176 -0
- package/dist/instrumentation/__tests__/ai21-rag-trace-comparison.test.js.map +1 -0
- package/dist/instrumentation/__tests__/ai21-trace-comparison.test.d.ts +10 -0
- package/dist/instrumentation/__tests__/ai21-trace-comparison.test.js +203 -0
- package/dist/instrumentation/__tests__/ai21-trace-comparison.test.js.map +1 -0
- package/dist/instrumentation/__tests__/anthropic-wrapper.test.d.ts +1 -0
- package/dist/instrumentation/__tests__/anthropic-wrapper.test.js +284 -0
- package/dist/instrumentation/__tests__/anthropic-wrapper.test.js.map +1 -0
- package/dist/instrumentation/__tests__/assemblyai-wrapper.test.d.ts +1 -0
- package/dist/instrumentation/__tests__/assemblyai-wrapper.test.js +284 -0
- package/dist/instrumentation/__tests__/assemblyai-wrapper.test.js.map +1 -0
- package/dist/instrumentation/__tests__/astra-trace-comparison.test.d.ts +7 -0
- package/dist/instrumentation/__tests__/astra-trace-comparison.test.js +160 -0
- package/dist/instrumentation/__tests__/astra-trace-comparison.test.js.map +1 -0
- package/dist/instrumentation/__tests__/base-wrapper.test.d.ts +1 -0
- package/dist/instrumentation/__tests__/base-wrapper.test.js +171 -0
- package/dist/instrumentation/__tests__/base-wrapper.test.js.map +1 -0
- package/dist/instrumentation/__tests__/bedrock-trace-comparison.test.d.ts +1 -0
- package/dist/instrumentation/__tests__/bedrock-trace-comparison.test.js +422 -0
- package/dist/instrumentation/__tests__/bedrock-trace-comparison.test.js.map +1 -0
- package/dist/instrumentation/__tests__/browser-use-wrapper.test.d.ts +1 -0
- package/dist/instrumentation/__tests__/browser-use-wrapper.test.js +284 -0
- package/dist/instrumentation/__tests__/browser-use-wrapper.test.js.map +1 -0
- package/dist/instrumentation/__tests__/cache-pricing.test.d.ts +15 -0
- package/dist/instrumentation/__tests__/cache-pricing.test.js +155 -0
- package/dist/instrumentation/__tests__/cache-pricing.test.js.map +1 -0
- package/dist/instrumentation/__tests__/chroma-trace-comparison.test.d.ts +18 -0
- package/dist/instrumentation/__tests__/chroma-trace-comparison.test.js +209 -0
- package/dist/instrumentation/__tests__/chroma-trace-comparison.test.js.map +1 -0
- package/dist/instrumentation/__tests__/cohere-wrapper.test.d.ts +1 -0
- package/dist/instrumentation/__tests__/cohere-wrapper.test.js +256 -0
- package/dist/instrumentation/__tests__/cohere-wrapper.test.js.map +1 -0
- package/dist/instrumentation/__tests__/elevenlabs-wrapper.test.d.ts +1 -0
- package/dist/instrumentation/__tests__/elevenlabs-wrapper.test.js +282 -0
- package/dist/instrumentation/__tests__/elevenlabs-wrapper.test.js.map +1 -0
- package/dist/instrumentation/__tests__/firecrawl-wrapper.test.d.ts +1 -0
- package/dist/instrumentation/__tests__/firecrawl-wrapper.test.js +238 -0
- package/dist/instrumentation/__tests__/firecrawl-wrapper.test.js.map +1 -0
- package/dist/instrumentation/__tests__/google-ai-trace-comparison.test.d.ts +4 -0
- package/dist/instrumentation/__tests__/google-ai-trace-comparison.test.js +229 -0
- package/dist/instrumentation/__tests__/google-ai-trace-comparison.test.js.map +1 -0
- package/dist/instrumentation/__tests__/gpu-collector.test.d.ts +1 -0
- package/dist/instrumentation/__tests__/gpu-collector.test.js +247 -0
- package/dist/instrumentation/__tests__/gpu-collector.test.js.map +1 -0
- package/dist/instrumentation/__tests__/gradient-trace-comparison.test.d.ts +11 -0
- package/dist/instrumentation/__tests__/gradient-trace-comparison.test.js +391 -0
- package/dist/instrumentation/__tests__/gradient-trace-comparison.test.js.map +1 -0
- package/dist/instrumentation/__tests__/groq-trace-comparison.test.d.ts +7 -0
- package/dist/instrumentation/__tests__/groq-trace-comparison.test.js +687 -0
- package/dist/instrumentation/__tests__/groq-trace-comparison.test.js.map +1 -0
- package/dist/instrumentation/__tests__/helpers-genai.test.d.ts +14 -0
- package/dist/instrumentation/__tests__/helpers-genai.test.js +347 -0
- package/dist/instrumentation/__tests__/helpers-genai.test.js.map +1 -0
- package/dist/instrumentation/__tests__/huggingface-trace-comparison.test.d.ts +7 -0
- package/dist/instrumentation/__tests__/huggingface-trace-comparison.test.js +529 -0
- package/dist/instrumentation/__tests__/huggingface-trace-comparison.test.js.map +1 -0
- package/dist/instrumentation/__tests__/langchain-role-map.test.d.ts +1 -0
- package/dist/instrumentation/__tests__/langchain-role-map.test.js +19 -0
- package/dist/instrumentation/__tests__/langchain-role-map.test.js.map +1 -0
- package/dist/instrumentation/__tests__/langchain-wrapper.test.d.ts +1 -0
- package/dist/instrumentation/__tests__/langchain-wrapper.test.js +282 -0
- package/dist/instrumentation/__tests__/langchain-wrapper.test.js.map +1 -0
- package/dist/instrumentation/__tests__/letta-wrapper.test.d.ts +1 -0
- package/dist/instrumentation/__tests__/letta-wrapper.test.js +285 -0
- package/dist/instrumentation/__tests__/letta-wrapper.test.js.map +1 -0
- package/dist/instrumentation/__tests__/mem0-trace-comparison.test.d.ts +13 -0
- package/dist/instrumentation/__tests__/mem0-trace-comparison.test.js +208 -0
- package/dist/instrumentation/__tests__/mem0-trace-comparison.test.js.map +1 -0
- package/dist/instrumentation/__tests__/milvus-trace-comparison.test.d.ts +17 -0
- package/dist/instrumentation/__tests__/milvus-trace-comparison.test.js +206 -0
- package/dist/instrumentation/__tests__/milvus-trace-comparison.test.js.map +1 -0
- package/dist/instrumentation/__tests__/mistral-trace-comparison.test.d.ts +1 -0
- package/dist/instrumentation/__tests__/mistral-trace-comparison.test.js +345 -0
- package/dist/instrumentation/__tests__/mistral-trace-comparison.test.js.map +1 -0
- package/dist/instrumentation/__tests__/openai-wrapper.test.d.ts +1 -0
- package/dist/instrumentation/__tests__/openai-wrapper.test.js +179 -0
- package/dist/instrumentation/__tests__/openai-wrapper.test.js.map +1 -0
- package/dist/instrumentation/__tests__/pg-trace-comparison.test.d.ts +21 -0
- package/dist/instrumentation/__tests__/pg-trace-comparison.test.js +455 -0
- package/dist/instrumentation/__tests__/pg-trace-comparison.test.js.map +1 -0
- package/dist/instrumentation/__tests__/qdrant-trace-comparison.test.d.ts +17 -0
- package/dist/instrumentation/__tests__/qdrant-trace-comparison.test.js +182 -0
- package/dist/instrumentation/__tests__/qdrant-trace-comparison.test.js.map +1 -0
- package/dist/instrumentation/__tests__/replicate-trace-comparison.test.d.ts +8 -0
- package/dist/instrumentation/__tests__/replicate-trace-comparison.test.js +346 -0
- package/dist/instrumentation/__tests__/replicate-trace-comparison.test.js.map +1 -0
- package/dist/instrumentation/__tests__/together-trace-comparison.test.d.ts +4 -0
- package/dist/instrumentation/__tests__/together-trace-comparison.test.js +289 -0
- package/dist/instrumentation/__tests__/together-trace-comparison.test.js.map +1 -0
- package/dist/instrumentation/__tests__/trace-comparison-utils.d.ts +67 -0
- package/dist/instrumentation/__tests__/trace-comparison-utils.js +255 -0
- package/dist/instrumentation/__tests__/trace-comparison-utils.js.map +1 -0
- package/dist/instrumentation/__tests__/transformers-trace-comparison.test.d.ts +11 -0
- package/dist/instrumentation/__tests__/transformers-trace-comparison.test.js +214 -0
- package/dist/instrumentation/__tests__/transformers-trace-comparison.test.js.map +1 -0
- package/dist/instrumentation/__tests__/vercel-ai-trace-comparison.test.d.ts +8 -0
- package/dist/instrumentation/__tests__/vercel-ai-trace-comparison.test.js +446 -0
- package/dist/instrumentation/__tests__/vercel-ai-trace-comparison.test.js.map +1 -0
- package/dist/instrumentation/__tests__/vertexai-trace-comparison.test.d.ts +6 -0
- package/dist/instrumentation/__tests__/vertexai-trace-comparison.test.js +409 -0
- package/dist/instrumentation/__tests__/vertexai-trace-comparison.test.js.map +1 -0
- package/dist/instrumentation/__tests__/vllm-trace-comparison.test.d.ts +1 -0
- package/dist/instrumentation/__tests__/vllm-trace-comparison.test.js +519 -0
- package/dist/instrumentation/__tests__/vllm-trace-comparison.test.js.map +1 -0
- package/dist/instrumentation/ai21/index.d.ts +11 -0
- package/dist/instrumentation/ai21/index.js +67 -0
- package/dist/instrumentation/ai21/index.js.map +1 -0
- package/dist/instrumentation/ai21/wrapper.d.ts +54 -0
- package/dist/instrumentation/ai21/wrapper.js +511 -0
- package/dist/instrumentation/ai21/wrapper.js.map +1 -0
- package/dist/instrumentation/anthropic/index.d.ts +11 -0
- package/dist/instrumentation/anthropic/index.js +45 -0
- package/dist/instrumentation/anthropic/index.js.map +1 -0
- package/dist/instrumentation/anthropic/wrapper.d.ts +34 -0
- package/dist/instrumentation/anthropic/wrapper.js +426 -0
- package/dist/instrumentation/anthropic/wrapper.js.map +1 -0
- package/dist/instrumentation/assemblyai/index.d.ts +12 -0
- package/dist/instrumentation/assemblyai/index.js +91 -0
- package/dist/instrumentation/assemblyai/index.js.map +1 -0
- package/dist/instrumentation/assemblyai/wrapper.d.ts +35 -0
- package/dist/instrumentation/assemblyai/wrapper.js +238 -0
- package/dist/instrumentation/assemblyai/wrapper.js.map +1 -0
- package/dist/instrumentation/astra/index.d.ts +11 -0
- package/dist/instrumentation/astra/index.js +87 -0
- package/dist/instrumentation/astra/index.js.map +1 -0
- package/dist/instrumentation/astra/wrapper.d.ts +39 -0
- package/dist/instrumentation/astra/wrapper.js +349 -0
- package/dist/instrumentation/astra/wrapper.js.map +1 -0
- package/dist/instrumentation/azure-ai-inference/index.d.ts +11 -0
- package/dist/instrumentation/azure-ai-inference/index.js +76 -0
- package/dist/instrumentation/azure-ai-inference/index.js.map +1 -0
- package/dist/instrumentation/azure-ai-inference/wrapper.d.ts +55 -0
- package/dist/instrumentation/azure-ai-inference/wrapper.js +580 -0
- package/dist/instrumentation/azure-ai-inference/wrapper.js.map +1 -0
- package/dist/instrumentation/base-wrapper.d.ts +16 -0
- package/dist/instrumentation/base-wrapper.js +139 -0
- package/dist/instrumentation/base-wrapper.js.map +1 -0
- package/dist/instrumentation/bedrock/index.d.ts +11 -0
- package/dist/instrumentation/bedrock/index.js +52 -0
- package/dist/instrumentation/bedrock/index.js.map +1 -0
- package/dist/instrumentation/bedrock/wrapper.d.ts +41 -0
- package/dist/instrumentation/bedrock/wrapper.js +494 -0
- package/dist/instrumentation/bedrock/wrapper.js.map +1 -0
- package/dist/instrumentation/browser-use/index.d.ts +11 -0
- package/dist/instrumentation/browser-use/index.js +98 -0
- package/dist/instrumentation/browser-use/index.js.map +1 -0
- package/dist/instrumentation/browser-use/wrapper.d.ts +12 -0
- package/dist/instrumentation/browser-use/wrapper.js +706 -0
- package/dist/instrumentation/browser-use/wrapper.js.map +1 -0
- package/dist/instrumentation/chroma/index.d.ts +11 -0
- package/dist/instrumentation/chroma/index.js +70 -0
- package/dist/instrumentation/chroma/index.js.map +1 -0
- package/dist/instrumentation/chroma/wrapper.d.ts +10 -0
- package/dist/instrumentation/chroma/wrapper.js +127 -0
- package/dist/instrumentation/chroma/wrapper.js.map +1 -0
- package/dist/instrumentation/claude-agent-sdk/index.d.ts +23 -0
- package/dist/instrumentation/claude-agent-sdk/index.js +83 -0
- package/dist/instrumentation/claude-agent-sdk/index.js.map +1 -0
- package/dist/instrumentation/claude-agent-sdk/wrapper.d.ts +13 -0
- package/dist/instrumentation/claude-agent-sdk/wrapper.js +1123 -0
- package/dist/instrumentation/claude-agent-sdk/wrapper.js.map +1 -0
- package/dist/instrumentation/cohere/index.d.ts +11 -0
- package/dist/instrumentation/cohere/index.js +53 -0
- package/dist/instrumentation/cohere/index.js.map +1 -0
- package/dist/instrumentation/cohere/wrapper.d.ts +50 -0
- package/dist/instrumentation/cohere/wrapper.js +452 -0
- package/dist/instrumentation/cohere/wrapper.js.map +1 -0
- package/dist/instrumentation/cursor-sdk/index.d.ts +21 -0
- package/dist/instrumentation/cursor-sdk/index.js +58 -0
- package/dist/instrumentation/cursor-sdk/index.js.map +1 -0
- package/dist/instrumentation/cursor-sdk/wrapper.d.ts +17 -0
- package/dist/instrumentation/cursor-sdk/wrapper.js +789 -0
- package/dist/instrumentation/cursor-sdk/wrapper.js.map +1 -0
- package/dist/instrumentation/elevenlabs/index.d.ts +12 -0
- package/dist/instrumentation/elevenlabs/index.js +92 -0
- package/dist/instrumentation/elevenlabs/index.js.map +1 -0
- package/dist/instrumentation/elevenlabs/wrapper.d.ts +34 -0
- package/dist/instrumentation/elevenlabs/wrapper.js +280 -0
- package/dist/instrumentation/elevenlabs/wrapper.js.map +1 -0
- package/dist/instrumentation/firecrawl/index.d.ts +13 -0
- package/dist/instrumentation/firecrawl/index.js +115 -0
- package/dist/instrumentation/firecrawl/index.js.map +1 -0
- package/dist/instrumentation/firecrawl/wrapper.d.ts +22 -0
- package/dist/instrumentation/firecrawl/wrapper.js +378 -0
- package/dist/instrumentation/firecrawl/wrapper.js.map +1 -0
- package/dist/instrumentation/google-adk/index.d.ts +57 -0
- package/dist/instrumentation/google-adk/index.js +371 -0
- package/dist/instrumentation/google-adk/index.js.map +1 -0
- package/dist/instrumentation/google-adk/utils.d.ts +45 -0
- package/dist/instrumentation/google-adk/utils.js +663 -0
- package/dist/instrumentation/google-adk/utils.js.map +1 -0
- package/dist/instrumentation/google-adk/wrapper.d.ts +11 -0
- package/dist/instrumentation/google-adk/wrapper.js +391 -0
- package/dist/instrumentation/google-adk/wrapper.js.map +1 -0
- package/dist/instrumentation/google-ai/index.d.ts +11 -0
- package/dist/instrumentation/google-ai/index.js +48 -0
- package/dist/instrumentation/google-ai/index.js.map +1 -0
- package/dist/instrumentation/google-ai/wrapper.d.ts +52 -0
- package/dist/instrumentation/google-ai/wrapper.js +466 -0
- package/dist/instrumentation/google-ai/wrapper.js.map +1 -0
- package/dist/instrumentation/gpu/index.d.ts +38 -0
- package/dist/instrumentation/gpu/index.js +233 -0
- package/dist/instrumentation/gpu/index.js.map +1 -0
- package/dist/instrumentation/gradient/index.d.ts +12 -0
- package/dist/instrumentation/gradient/index.js +74 -0
- package/dist/instrumentation/gradient/index.js.map +1 -0
- package/dist/instrumentation/gradient/utils.d.ts +14 -0
- package/dist/instrumentation/gradient/utils.js +119 -0
- package/dist/instrumentation/gradient/utils.js.map +1 -0
- package/dist/instrumentation/gradient/wrapper.d.ts +76 -0
- package/dist/instrumentation/gradient/wrapper.js +584 -0
- package/dist/instrumentation/gradient/wrapper.js.map +1 -0
- package/dist/instrumentation/groq/index.d.ts +11 -0
- package/dist/instrumentation/groq/index.js +43 -0
- package/dist/instrumentation/groq/index.js.map +1 -0
- package/dist/instrumentation/groq/wrapper.d.ts +35 -0
- package/dist/instrumentation/groq/wrapper.js +442 -0
- package/dist/instrumentation/groq/wrapper.js.map +1 -0
- package/dist/instrumentation/huggingface/index.d.ts +13 -0
- package/dist/instrumentation/huggingface/index.js +110 -0
- package/dist/instrumentation/huggingface/index.js.map +1 -0
- package/dist/instrumentation/huggingface/wrapper.d.ts +54 -0
- package/dist/instrumentation/huggingface/wrapper.js +514 -0
- package/dist/instrumentation/huggingface/wrapper.js.map +1 -0
- package/dist/instrumentation/index.d.ts +7 -0
- package/dist/instrumentation/index.js +176 -0
- package/dist/instrumentation/index.js.map +1 -0
- package/dist/instrumentation/langchain/index.d.ts +16 -0
- package/dist/instrumentation/langchain/index.js +91 -0
- package/dist/instrumentation/langchain/index.js.map +1 -0
- package/dist/instrumentation/langchain/wrapper.d.ts +41 -0
- package/dist/instrumentation/langchain/wrapper.js +1235 -0
- package/dist/instrumentation/langchain/wrapper.js.map +1 -0
- package/dist/instrumentation/langgraph/index.d.ts +12 -0
- package/dist/instrumentation/langgraph/index.js +99 -0
- package/dist/instrumentation/langgraph/index.js.map +1 -0
- package/dist/instrumentation/langgraph/wrapper.d.ts +20 -0
- package/dist/instrumentation/langgraph/wrapper.js +620 -0
- package/dist/instrumentation/langgraph/wrapper.js.map +1 -0
- package/dist/instrumentation/letta/index.d.ts +10 -0
- package/dist/instrumentation/letta/index.js +122 -0
- package/dist/instrumentation/letta/index.js.map +1 -0
- package/dist/instrumentation/letta/utils.d.ts +24 -0
- package/dist/instrumentation/letta/utils.js +343 -0
- package/dist/instrumentation/letta/utils.js.map +1 -0
- package/dist/instrumentation/letta/wrapper.d.ts +37 -0
- package/dist/instrumentation/letta/wrapper.js +180 -0
- package/dist/instrumentation/letta/wrapper.js.map +1 -0
- package/dist/instrumentation/llamaindex/index.d.ts +36 -0
- package/dist/instrumentation/llamaindex/index.js +221 -0
- package/dist/instrumentation/llamaindex/index.js.map +1 -0
- package/dist/instrumentation/llamaindex/wrapper.d.ts +36 -0
- package/dist/instrumentation/llamaindex/wrapper.js +811 -0
- package/dist/instrumentation/llamaindex/wrapper.js.map +1 -0
- package/dist/instrumentation/mcp/index.d.ts +20 -0
- package/dist/instrumentation/mcp/index.js +282 -0
- package/dist/instrumentation/mcp/index.js.map +1 -0
- package/dist/instrumentation/mcp/wrapper.d.ts +72 -0
- package/dist/instrumentation/mcp/wrapper.js +571 -0
- package/dist/instrumentation/mcp/wrapper.js.map +1 -0
- package/dist/instrumentation/mem0/index.d.ts +17 -0
- package/dist/instrumentation/mem0/index.js +113 -0
- package/dist/instrumentation/mem0/index.js.map +1 -0
- package/dist/instrumentation/mem0/wrapper.d.ts +37 -0
- package/dist/instrumentation/mem0/wrapper.js +298 -0
- package/dist/instrumentation/mem0/wrapper.js.map +1 -0
- package/dist/instrumentation/milvus/index.d.ts +11 -0
- package/dist/instrumentation/milvus/index.js +67 -0
- package/dist/instrumentation/milvus/index.js.map +1 -0
- package/dist/instrumentation/milvus/wrapper.d.ts +15 -0
- package/dist/instrumentation/milvus/wrapper.js +219 -0
- package/dist/instrumentation/milvus/wrapper.js.map +1 -0
- package/dist/instrumentation/mistral/index.d.ts +11 -0
- package/dist/instrumentation/mistral/index.js +66 -0
- package/dist/instrumentation/mistral/index.js.map +1 -0
- package/dist/instrumentation/mistral/wrapper.d.ts +49 -0
- package/dist/instrumentation/mistral/wrapper.js +482 -0
- package/dist/instrumentation/mistral/wrapper.js.map +1 -0
- package/dist/instrumentation/ollama/index.d.ts +11 -0
- package/dist/instrumentation/ollama/index.js +72 -0
- package/dist/instrumentation/ollama/index.js.map +1 -0
- package/dist/instrumentation/ollama/wrapper.d.ts +73 -0
- package/dist/instrumentation/ollama/wrapper.js +629 -0
- package/dist/instrumentation/ollama/wrapper.js.map +1 -0
- package/dist/instrumentation/openai/index.d.ts +11 -0
- package/dist/instrumentation/openai/index.js +79 -0
- package/dist/instrumentation/openai/index.js.map +1 -0
- package/dist/instrumentation/openai/wrapper.d.ts +80 -0
- package/dist/instrumentation/openai/wrapper.js +1121 -0
- package/dist/instrumentation/openai/wrapper.js.map +1 -0
- package/dist/instrumentation/openai-agents/index.d.ts +20 -0
- package/dist/instrumentation/openai-agents/index.js +174 -0
- package/dist/instrumentation/openai-agents/index.js.map +1 -0
- package/dist/instrumentation/openai-agents/processor.d.ts +35 -0
- package/dist/instrumentation/openai-agents/processor.js +249 -0
- package/dist/instrumentation/openai-agents/processor.js.map +1 -0
- package/dist/instrumentation/openai-agents/utils.d.ts +20 -0
- package/dist/instrumentation/openai-agents/utils.js +624 -0
- package/dist/instrumentation/openai-agents/utils.js.map +1 -0
- package/dist/instrumentation/pg/index.d.ts +20 -0
- package/dist/instrumentation/pg/index.js +74 -0
- package/dist/instrumentation/pg/index.js.map +1 -0
- package/dist/instrumentation/pg/wrapper.d.ts +66 -0
- package/dist/instrumentation/pg/wrapper.js +441 -0
- package/dist/instrumentation/pg/wrapper.js.map +1 -0
- package/dist/instrumentation/pinecone/index.d.ts +11 -0
- package/dist/instrumentation/pinecone/index.js +79 -0
- package/dist/instrumentation/pinecone/index.js.map +1 -0
- package/dist/instrumentation/pinecone/wrapper.d.ts +14 -0
- package/dist/instrumentation/pinecone/wrapper.js +198 -0
- package/dist/instrumentation/pinecone/wrapper.js.map +1 -0
- package/dist/instrumentation/qdrant/index.d.ts +11 -0
- package/dist/instrumentation/qdrant/index.js +67 -0
- package/dist/instrumentation/qdrant/index.js.map +1 -0
- package/dist/instrumentation/qdrant/wrapper.d.ts +14 -0
- package/dist/instrumentation/qdrant/wrapper.js +213 -0
- package/dist/instrumentation/qdrant/wrapper.js.map +1 -0
- package/dist/instrumentation/replicate/index.d.ts +11 -0
- package/dist/instrumentation/replicate/index.js +57 -0
- package/dist/instrumentation/replicate/index.js.map +1 -0
- package/dist/instrumentation/replicate/wrapper.d.ts +28 -0
- package/dist/instrumentation/replicate/wrapper.js +242 -0
- package/dist/instrumentation/replicate/wrapper.js.map +1 -0
- package/dist/instrumentation/strands/index.d.ts +21 -0
- package/dist/instrumentation/strands/index.js +83 -0
- package/dist/instrumentation/strands/index.js.map +1 -0
- package/dist/instrumentation/strands/processor.d.ts +51 -0
- package/dist/instrumentation/strands/processor.js +625 -0
- package/dist/instrumentation/strands/processor.js.map +1 -0
- package/dist/instrumentation/strands/utils.d.ts +24 -0
- package/dist/instrumentation/strands/utils.js +373 -0
- package/dist/instrumentation/strands/utils.js.map +1 -0
- package/dist/instrumentation/together/index.d.ts +11 -0
- package/dist/instrumentation/together/index.js +43 -0
- package/dist/instrumentation/together/index.js.map +1 -0
- package/dist/instrumentation/together/wrapper.d.ts +48 -0
- package/dist/instrumentation/together/wrapper.js +409 -0
- package/dist/instrumentation/together/wrapper.js.map +1 -0
- package/dist/instrumentation/transformers/index.d.ts +35 -0
- package/dist/instrumentation/transformers/index.js +119 -0
- package/dist/instrumentation/transformers/index.js.map +1 -0
- package/dist/instrumentation/transformers/wrapper.d.ts +49 -0
- package/dist/instrumentation/transformers/wrapper.js +472 -0
- package/dist/instrumentation/transformers/wrapper.js.map +1 -0
- package/dist/instrumentation/vercel-ai/index.d.ts +10 -0
- package/dist/instrumentation/vercel-ai/index.js +59 -0
- package/dist/instrumentation/vercel-ai/index.js.map +1 -0
- package/dist/instrumentation/vercel-ai/wrapper.d.ts +50 -0
- package/dist/instrumentation/vercel-ai/wrapper.js +539 -0
- package/dist/instrumentation/vercel-ai/wrapper.js.map +1 -0
- package/dist/instrumentation/vertexai/index.d.ts +11 -0
- package/dist/instrumentation/vertexai/index.js +70 -0
- package/dist/instrumentation/vertexai/index.js.map +1 -0
- package/dist/instrumentation/vertexai/wrapper.d.ts +67 -0
- package/dist/instrumentation/vertexai/wrapper.js +530 -0
- package/dist/instrumentation/vertexai/wrapper.js.map +1 -0
- package/dist/instrumentation/vllm/index.d.ts +13 -0
- package/dist/instrumentation/vllm/index.js +67 -0
- package/dist/instrumentation/vllm/index.js.map +1 -0
- package/dist/instrumentation/vllm/wrapper.d.ts +60 -0
- package/dist/instrumentation/vllm/wrapper.js +482 -0
- package/dist/instrumentation/vllm/wrapper.js.map +1 -0
- package/dist/llm/anthropic.d.ts +5 -0
- package/dist/llm/anthropic.js +39 -0
- package/dist/llm/anthropic.js.map +1 -0
- package/dist/llm/index.d.ts +10 -0
- package/dist/llm/index.js +93 -0
- package/dist/llm/index.js.map +1 -0
- package/dist/llm/openai.d.ts +6 -0
- package/dist/llm/openai.js +52 -0
- package/dist/llm/openai.js.map +1 -0
- package/dist/llm/providers.d.ts +7 -0
- package/dist/llm/providers.js +10 -0
- package/dist/llm/providers.js.map +1 -0
- package/dist/manual-trace.d.ts +40 -0
- package/dist/manual-trace.js +103 -0
- package/dist/manual-trace.js.map +1 -0
- package/dist/otel/__tests__/metrics.test.d.ts +1 -0
- package/dist/otel/__tests__/metrics.test.js +40 -0
- package/dist/otel/__tests__/metrics.test.js.map +1 -0
- package/dist/otel/events.d.ts +11 -0
- package/dist/otel/events.js +74 -0
- package/dist/otel/events.js.map +1 -0
- package/dist/otel/metrics.d.ts +35 -0
- package/dist/otel/metrics.js +219 -0
- package/dist/otel/metrics.js.map +1 -0
- package/dist/otel/tracing.d.ts +12 -0
- package/dist/otel/tracing.js +93 -0
- package/dist/otel/tracing.js.map +1 -0
- package/dist/otel/utils.d.ts +11 -0
- package/dist/otel/utils.js +34 -0
- package/dist/otel/utils.js.map +1 -0
- package/dist/pricing.json +951 -0
- package/dist/prompt-hub.d.ts +4 -0
- package/dist/prompt-hub.js +66 -0
- package/dist/prompt-hub.js.map +1 -0
- package/dist/register.d.ts +4 -0
- package/dist/register.js +52 -0
- package/dist/register.js.map +1 -0
- package/dist/score/__tests__/score.test.d.ts +1 -0
- package/dist/score/__tests__/score.test.js +143 -0
- package/dist/score/__tests__/score.test.js.map +1 -0
- package/dist/score/index.d.ts +2 -0
- package/dist/score/index.js +6 -0
- package/dist/score/index.js.map +1 -0
- package/dist/score/score.d.ts +15 -0
- package/dist/score/score.js +135 -0
- package/dist/score/score.js.map +1 -0
- package/dist/semantic-convention.d.ts +555 -0
- package/dist/semantic-convention.js +630 -0
- package/dist/semantic-convention.js.map +1 -0
- package/dist/types.d.ts +131 -0
- package/dist/types.js +3 -0
- package/dist/types.js.map +1 -0
- package/package.json +136 -0
|
@@ -0,0 +1,811 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Shield360 LlamaIndex Wrapper
|
|
4
|
+
*
|
|
5
|
+
* Mirrors Python SDK: sdk/python/src/shield360/instrumentation/llamaindex/
|
|
6
|
+
* Uses the same OPERATION_MAP and span semantics as the Python implementation.
|
|
7
|
+
*
|
|
8
|
+
* LLM operations get full provider-style telemetry (attributes, events, metrics).
|
|
9
|
+
* Framework operations (query engine, retriever, index, etc.) get framework-level spans.
|
|
10
|
+
*/
|
|
11
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
12
|
+
if (k2 === undefined) k2 = k;
|
|
13
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
14
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
15
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
16
|
+
}
|
|
17
|
+
Object.defineProperty(o, k2, desc);
|
|
18
|
+
}) : (function(o, m, k, k2) {
|
|
19
|
+
if (k2 === undefined) k2 = k;
|
|
20
|
+
o[k2] = m[k];
|
|
21
|
+
}));
|
|
22
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
23
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
24
|
+
}) : function(o, v) {
|
|
25
|
+
o["default"] = v;
|
|
26
|
+
});
|
|
27
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
28
|
+
var ownKeys = function(o) {
|
|
29
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
30
|
+
var ar = [];
|
|
31
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
32
|
+
return ar;
|
|
33
|
+
};
|
|
34
|
+
return ownKeys(o);
|
|
35
|
+
};
|
|
36
|
+
return function (mod) {
|
|
37
|
+
if (mod && mod.__esModule) return mod;
|
|
38
|
+
var result = {};
|
|
39
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
40
|
+
__setModuleDefault(result, mod);
|
|
41
|
+
return result;
|
|
42
|
+
};
|
|
43
|
+
})();
|
|
44
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
45
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
46
|
+
};
|
|
47
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
48
|
+
const api_1 = require("@opentelemetry/api");
|
|
49
|
+
const config_1 = __importDefault(require("../../config"));
|
|
50
|
+
const helpers_1 = __importStar(require("../../helpers"));
|
|
51
|
+
const semantic_convention_1 = __importDefault(require("../../semantic-convention"));
|
|
52
|
+
const base_wrapper_1 = __importDefault(require("../base-wrapper"));
|
|
53
|
+
/**
|
|
54
|
+
* Operation mapping matching Python SDK's OPERATION_MAP in
|
|
55
|
+
* sdk/python/src/shield360/instrumentation/llamaindex/utils.py
|
|
56
|
+
*/
|
|
57
|
+
const OPERATION_MAP = {
|
|
58
|
+
// Document Loading & Processing
|
|
59
|
+
document_load: semantic_convention_1.default.GEN_AI_OPERATION_TYPE_RETRIEVE,
|
|
60
|
+
document_transform: semantic_convention_1.default.GEN_AI_OPERATION_TYPE_FRAMEWORK,
|
|
61
|
+
document_split: semantic_convention_1.default.GEN_AI_OPERATION_TYPE_FRAMEWORK,
|
|
62
|
+
// Index Construction & Management
|
|
63
|
+
index_construct: semantic_convention_1.default.GEN_AI_OPERATION_TYPE_FRAMEWORK,
|
|
64
|
+
index_insert: semantic_convention_1.default.GEN_AI_OPERATION_TYPE_FRAMEWORK,
|
|
65
|
+
index_delete: semantic_convention_1.default.GEN_AI_OPERATION_TYPE_FRAMEWORK,
|
|
66
|
+
index_build: semantic_convention_1.default.GEN_AI_OPERATION_TYPE_FRAMEWORK,
|
|
67
|
+
// Query Engine Operations
|
|
68
|
+
query_engine_create: semantic_convention_1.default.GEN_AI_OPERATION_TYPE_FRAMEWORK,
|
|
69
|
+
query_engine_query: semantic_convention_1.default.GEN_AI_OPERATION_TYPE_RETRIEVE,
|
|
70
|
+
// Retriever Operations
|
|
71
|
+
retriever_create: semantic_convention_1.default.GEN_AI_OPERATION_TYPE_FRAMEWORK,
|
|
72
|
+
retriever_retrieve: semantic_convention_1.default.GEN_AI_OPERATION_TYPE_RETRIEVE,
|
|
73
|
+
// LLM Operations
|
|
74
|
+
llm_chat: semantic_convention_1.default.GEN_AI_OPERATION_TYPE_CHAT,
|
|
75
|
+
llm_complete: semantic_convention_1.default.GEN_AI_OPERATION_TYPE_CHAT,
|
|
76
|
+
// Embedding Operations
|
|
77
|
+
embedding_generate: semantic_convention_1.default.GEN_AI_OPERATION_TYPE_EMBEDDING,
|
|
78
|
+
// Response Synthesis
|
|
79
|
+
response_synthesize: semantic_convention_1.default.GEN_AI_OPERATION_TYPE_CHAT,
|
|
80
|
+
// Text Processing Components
|
|
81
|
+
text_splitter_split: semantic_convention_1.default.GEN_AI_OPERATION_TYPE_FRAMEWORK,
|
|
82
|
+
node_parser_parse: semantic_convention_1.default.GEN_AI_OPERATION_TYPE_FRAMEWORK,
|
|
83
|
+
// Vector Store Components
|
|
84
|
+
vector_store_add: semantic_convention_1.default.GEN_AI_OPERATION_TYPE_FRAMEWORK,
|
|
85
|
+
vector_store_delete: semantic_convention_1.default.GEN_AI_OPERATION_TYPE_FRAMEWORK,
|
|
86
|
+
vector_store_query: semantic_convention_1.default.GEN_AI_OPERATION_TYPE_RETRIEVE,
|
|
87
|
+
// Postprocessor
|
|
88
|
+
postprocessor_process: semantic_convention_1.default.GEN_AI_OPERATION_TYPE_FRAMEWORK,
|
|
89
|
+
};
|
|
90
|
+
class LlamaIndexWrapper {
|
|
91
|
+
/**
|
|
92
|
+
* Stamp `shield360.agent.version_hash` (auto) and `gen_ai.agent.version`
|
|
93
|
+
* (user override, if set) on the span and return the same attributes so
|
|
94
|
+
* the caller can merge them into the inference event extras.
|
|
95
|
+
*/
|
|
96
|
+
static _stampAgentVersion(span, args) {
|
|
97
|
+
const out = {};
|
|
98
|
+
try {
|
|
99
|
+
const versionHash = helpers_1.default.computeAgentVersionHash({
|
|
100
|
+
systemInstructions: args.systemInstructionsJson ?? null,
|
|
101
|
+
toolDefinitions: args.toolDefinitionsJson ?? null,
|
|
102
|
+
primaryModel: args.primaryModel ?? null,
|
|
103
|
+
runtimeConfig: {
|
|
104
|
+
temperature: args.temperature ?? null,
|
|
105
|
+
top_p: args.top_p ?? null,
|
|
106
|
+
max_tokens: args.max_tokens ?? null,
|
|
107
|
+
provider: semantic_convention_1.default.GEN_AI_SYSTEM_LLAMAINDEX,
|
|
108
|
+
},
|
|
109
|
+
providers: [semantic_convention_1.default.GEN_AI_SYSTEM_LLAMAINDEX],
|
|
110
|
+
});
|
|
111
|
+
if (versionHash) {
|
|
112
|
+
out[semantic_convention_1.default.SHIELD360_AGENT_VERSION_HASH] = versionHash;
|
|
113
|
+
span.setAttribute(semantic_convention_1.default.SHIELD360_AGENT_VERSION_HASH, versionHash);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
catch {
|
|
117
|
+
// Hash computation must never fail the wrapped call.
|
|
118
|
+
}
|
|
119
|
+
const versionLabel = (0, helpers_1.getCurrentAgentVersion)();
|
|
120
|
+
if (versionLabel) {
|
|
121
|
+
out[semantic_convention_1.default.GEN_AI_AGENT_VERSION] = versionLabel;
|
|
122
|
+
span.setAttribute(semantic_convention_1.default.GEN_AI_AGENT_VERSION, versionLabel);
|
|
123
|
+
}
|
|
124
|
+
return out;
|
|
125
|
+
}
|
|
126
|
+
// ---------------------------------------------------------------------------
|
|
127
|
+
// Helpers (mirrors Python set_server_address_and_port / model extraction)
|
|
128
|
+
// ---------------------------------------------------------------------------
|
|
129
|
+
static _extractModel(instance) {
|
|
130
|
+
return instance?.model
|
|
131
|
+
|| instance?.modelName
|
|
132
|
+
|| instance?.metadata?.model
|
|
133
|
+
|| instance?.llm?.model
|
|
134
|
+
|| instance?._llm?.model
|
|
135
|
+
|| instance?._responseSynthesizer?.llm?.model
|
|
136
|
+
|| instance?._responseSynthesizer?._llm?.model
|
|
137
|
+
|| 'unknown';
|
|
138
|
+
}
|
|
139
|
+
static _extractServerInfo(instance) {
|
|
140
|
+
const candidates = [
|
|
141
|
+
instance?._client?.baseURL,
|
|
142
|
+
instance?.session?.openai?.baseURL,
|
|
143
|
+
instance?.clientOptions?.baseURL,
|
|
144
|
+
instance?.llm?._client?.baseURL,
|
|
145
|
+
instance?._llm?._client?.baseURL,
|
|
146
|
+
instance?.llm?.session?.openai?.baseURL,
|
|
147
|
+
instance?._llm?.session?.openai?.baseURL,
|
|
148
|
+
];
|
|
149
|
+
for (const rawUrl of candidates) {
|
|
150
|
+
if (rawUrl) {
|
|
151
|
+
try {
|
|
152
|
+
const parsed = new URL(rawUrl);
|
|
153
|
+
return {
|
|
154
|
+
address: parsed.hostname,
|
|
155
|
+
port: parsed.port
|
|
156
|
+
? parseInt(parsed.port, 10)
|
|
157
|
+
: (parsed.protocol === 'https:' ? 443 : 80),
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
catch { /* try next */ }
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
return { address: 'localhost', port: 8000 };
|
|
164
|
+
}
|
|
165
|
+
// ---------------------------------------------------------------------------
|
|
166
|
+
// LLM chat patch — full provider-style telemetry + frameworkLlmActive
|
|
167
|
+
// Mirrors Python: LLM.chat -> operation_type "chat"
|
|
168
|
+
// ---------------------------------------------------------------------------
|
|
169
|
+
static _patchLLMChat(tracer) {
|
|
170
|
+
const endpoint = 'llm_chat';
|
|
171
|
+
const operationType = OPERATION_MAP[endpoint];
|
|
172
|
+
return (originalMethod) => {
|
|
173
|
+
return function (...args) {
|
|
174
|
+
const requestModel = LlamaIndexWrapper._extractModel(this);
|
|
175
|
+
const { address, port } = LlamaIndexWrapper._extractServerInfo(this);
|
|
176
|
+
const spanName = `${operationType} ${requestModel}`;
|
|
177
|
+
const span = tracer.startSpan(spanName, {
|
|
178
|
+
kind: api_1.SpanKind.CLIENT,
|
|
179
|
+
attributes: {
|
|
180
|
+
[semantic_convention_1.default.GEN_AI_OPERATION]: operationType,
|
|
181
|
+
[semantic_convention_1.default.GEN_AI_PROVIDER_NAME_OTEL]: LlamaIndexWrapper.aiSystem,
|
|
182
|
+
[semantic_convention_1.default.GEN_AI_REQUEST_MODEL]: requestModel,
|
|
183
|
+
[semantic_convention_1.default.SERVER_ADDRESS]: address,
|
|
184
|
+
[semantic_convention_1.default.SERVER_PORT]: port,
|
|
185
|
+
},
|
|
186
|
+
});
|
|
187
|
+
return api_1.context.with(api_1.trace.setSpan(api_1.context.active(), span), () => {
|
|
188
|
+
const startTime = Date.now();
|
|
189
|
+
const onSuccess = (response) => {
|
|
190
|
+
try {
|
|
191
|
+
LlamaIndexWrapper._processLLMResponse(span, response, requestModel, address, port, startTime, args, 'chat');
|
|
192
|
+
}
|
|
193
|
+
catch { /* swallow telemetry errors */ }
|
|
194
|
+
return response;
|
|
195
|
+
};
|
|
196
|
+
const onError = (e) => {
|
|
197
|
+
helpers_1.default.handleException(span, e);
|
|
198
|
+
base_wrapper_1.default.recordMetrics(span, {
|
|
199
|
+
genAIEndpoint: endpoint,
|
|
200
|
+
model: requestModel,
|
|
201
|
+
aiSystem: LlamaIndexWrapper.aiSystem,
|
|
202
|
+
serverAddress: address,
|
|
203
|
+
serverPort: port,
|
|
204
|
+
errorType: e?.constructor?.name || '_OTHER',
|
|
205
|
+
});
|
|
206
|
+
span.end();
|
|
207
|
+
throw e;
|
|
208
|
+
};
|
|
209
|
+
try {
|
|
210
|
+
const result = (0, helpers_1.runWithFrameworkLlm)(() => originalMethod.apply(this, args));
|
|
211
|
+
if (result && typeof result.then === 'function') {
|
|
212
|
+
return result.then(onSuccess).catch(onError);
|
|
213
|
+
}
|
|
214
|
+
return onSuccess(result);
|
|
215
|
+
}
|
|
216
|
+
catch (e) {
|
|
217
|
+
return onError(e);
|
|
218
|
+
}
|
|
219
|
+
});
|
|
220
|
+
};
|
|
221
|
+
};
|
|
222
|
+
}
|
|
223
|
+
// ---------------------------------------------------------------------------
|
|
224
|
+
// LLM complete patch — full provider-style telemetry + frameworkLlmActive
|
|
225
|
+
// Mirrors Python: LLM.complete -> operation_type "chat"
|
|
226
|
+
// ---------------------------------------------------------------------------
|
|
227
|
+
static _patchLLMComplete(tracer) {
|
|
228
|
+
const endpoint = 'llm_complete';
|
|
229
|
+
const operationType = OPERATION_MAP[endpoint];
|
|
230
|
+
return (originalMethod) => {
|
|
231
|
+
return function (...args) {
|
|
232
|
+
const requestModel = LlamaIndexWrapper._extractModel(this);
|
|
233
|
+
const { address, port } = LlamaIndexWrapper._extractServerInfo(this);
|
|
234
|
+
const spanName = `${operationType} ${requestModel}`;
|
|
235
|
+
const span = tracer.startSpan(spanName, {
|
|
236
|
+
kind: api_1.SpanKind.CLIENT,
|
|
237
|
+
attributes: {
|
|
238
|
+
[semantic_convention_1.default.GEN_AI_OPERATION]: operationType,
|
|
239
|
+
[semantic_convention_1.default.GEN_AI_PROVIDER_NAME_OTEL]: LlamaIndexWrapper.aiSystem,
|
|
240
|
+
[semantic_convention_1.default.GEN_AI_REQUEST_MODEL]: requestModel,
|
|
241
|
+
[semantic_convention_1.default.SERVER_ADDRESS]: address,
|
|
242
|
+
[semantic_convention_1.default.SERVER_PORT]: port,
|
|
243
|
+
},
|
|
244
|
+
});
|
|
245
|
+
return api_1.context.with(api_1.trace.setSpan(api_1.context.active(), span), () => {
|
|
246
|
+
const startTime = Date.now();
|
|
247
|
+
const onSuccess = (response) => {
|
|
248
|
+
try {
|
|
249
|
+
LlamaIndexWrapper._processLLMResponse(span, response, requestModel, address, port, startTime, args, 'complete');
|
|
250
|
+
}
|
|
251
|
+
catch { /* swallow */ }
|
|
252
|
+
return response;
|
|
253
|
+
};
|
|
254
|
+
const onError = (e) => {
|
|
255
|
+
helpers_1.default.handleException(span, e);
|
|
256
|
+
base_wrapper_1.default.recordMetrics(span, {
|
|
257
|
+
genAIEndpoint: endpoint,
|
|
258
|
+
model: requestModel,
|
|
259
|
+
aiSystem: LlamaIndexWrapper.aiSystem,
|
|
260
|
+
serverAddress: address,
|
|
261
|
+
serverPort: port,
|
|
262
|
+
errorType: e?.constructor?.name || '_OTHER',
|
|
263
|
+
});
|
|
264
|
+
span.end();
|
|
265
|
+
throw e;
|
|
266
|
+
};
|
|
267
|
+
try {
|
|
268
|
+
const result = (0, helpers_1.runWithFrameworkLlm)(() => originalMethod.apply(this, args));
|
|
269
|
+
if (result && typeof result.then === 'function') {
|
|
270
|
+
return result.then(onSuccess).catch(onError);
|
|
271
|
+
}
|
|
272
|
+
return onSuccess(result);
|
|
273
|
+
}
|
|
274
|
+
catch (e) {
|
|
275
|
+
return onError(e);
|
|
276
|
+
}
|
|
277
|
+
});
|
|
278
|
+
};
|
|
279
|
+
};
|
|
280
|
+
}
|
|
281
|
+
// ---------------------------------------------------------------------------
|
|
282
|
+
// Shared LLM response processor — attributes, events, metrics
|
|
283
|
+
// ---------------------------------------------------------------------------
|
|
284
|
+
static _processLLMResponse(span, response, requestModel, serverAddress, serverPort, startTime, args, mode) {
|
|
285
|
+
const endpoint = mode === 'chat' ? 'llm_chat' : 'llm_complete';
|
|
286
|
+
const duration = (Date.now() - startTime) / 1000;
|
|
287
|
+
const rawUsage = response?.raw?.usage || response?.usage || {};
|
|
288
|
+
const inputTokens = rawUsage.prompt_tokens || rawUsage.input_tokens || 0;
|
|
289
|
+
const outputTokens = rawUsage.completion_tokens || rawUsage.output_tokens || 0;
|
|
290
|
+
const finishReason = response?.raw?.choices?.[0]?.finish_reason || 'stop';
|
|
291
|
+
const responseModel = response?.raw?.model || requestModel;
|
|
292
|
+
const responseId = response?.raw?.id || '';
|
|
293
|
+
const pricingInfo = config_1.default.pricingInfo || {};
|
|
294
|
+
const cost = helpers_1.default.getChatModelCost(requestModel, pricingInfo, inputTokens, outputTokens);
|
|
295
|
+
base_wrapper_1.default.setBaseSpanAttributes(span, {
|
|
296
|
+
genAIEndpoint: endpoint,
|
|
297
|
+
model: requestModel,
|
|
298
|
+
cost,
|
|
299
|
+
aiSystem: LlamaIndexWrapper.aiSystem,
|
|
300
|
+
serverAddress,
|
|
301
|
+
serverPort,
|
|
302
|
+
});
|
|
303
|
+
span.setAttribute(semantic_convention_1.default.GEN_AI_REQUEST_IS_STREAM, false);
|
|
304
|
+
if (responseModel) {
|
|
305
|
+
span.setAttribute(semantic_convention_1.default.GEN_AI_RESPONSE_MODEL, responseModel);
|
|
306
|
+
}
|
|
307
|
+
if (responseId) {
|
|
308
|
+
span.setAttribute(semantic_convention_1.default.GEN_AI_RESPONSE_ID, responseId);
|
|
309
|
+
}
|
|
310
|
+
span.setAttribute(semantic_convention_1.default.GEN_AI_RESPONSE_FINISH_REASON, [finishReason]);
|
|
311
|
+
if (inputTokens) {
|
|
312
|
+
span.setAttribute(semantic_convention_1.default.GEN_AI_USAGE_INPUT_TOKENS, inputTokens);
|
|
313
|
+
}
|
|
314
|
+
if (outputTokens) {
|
|
315
|
+
span.setAttribute(semantic_convention_1.default.GEN_AI_USAGE_OUTPUT_TOKENS, outputTokens);
|
|
316
|
+
}
|
|
317
|
+
span.setAttribute(semantic_convention_1.default.GEN_AI_CLIENT_OPERATION_DURATION, duration);
|
|
318
|
+
let inputMessagesJson = '';
|
|
319
|
+
let outputMessagesJson = '';
|
|
320
|
+
const requestTools = (mode === 'chat' && args[0] && !Array.isArray(args[0]) ? args[0]?.tools : undefined) ||
|
|
321
|
+
(args[0] && typeof args[0] === 'object' ? args[0].tools : undefined);
|
|
322
|
+
const toolDefinitionsJson = helpers_1.default.buildToolDefinitions(requestTools);
|
|
323
|
+
// Compute system_instructions JSON regardless of captureContent so the
|
|
324
|
+
// version hash still groups correctly when content capture is disabled.
|
|
325
|
+
let systemInstructionsJson;
|
|
326
|
+
if (mode === 'chat') {
|
|
327
|
+
const messages = args[0]?.messages || (Array.isArray(args[0]) ? args[0] : []);
|
|
328
|
+
const formatted = (Array.isArray(messages) ? messages : [messages]).map((m) => ({
|
|
329
|
+
role: m.role || 'user',
|
|
330
|
+
content: typeof m.content === 'string' ? m.content : JSON.stringify(m.content || ''),
|
|
331
|
+
}));
|
|
332
|
+
systemInstructionsJson = helpers_1.default.buildSystemInstructionsFromMessages(formatted);
|
|
333
|
+
}
|
|
334
|
+
const versionExtras = LlamaIndexWrapper._stampAgentVersion(span, {
|
|
335
|
+
systemInstructionsJson,
|
|
336
|
+
toolDefinitionsJson,
|
|
337
|
+
primaryModel: responseModel || requestModel,
|
|
338
|
+
temperature: null,
|
|
339
|
+
top_p: null,
|
|
340
|
+
max_tokens: null,
|
|
341
|
+
});
|
|
342
|
+
if (config_1.default.captureMessageContent) {
|
|
343
|
+
if (mode === 'chat') {
|
|
344
|
+
const messages = args[0]?.messages || (Array.isArray(args[0]) ? args[0] : []);
|
|
345
|
+
const formatted = (Array.isArray(messages) ? messages : [messages]).map((m) => ({
|
|
346
|
+
role: m.role || 'user',
|
|
347
|
+
content: typeof m.content === 'string' ? m.content : JSON.stringify(m.content || ''),
|
|
348
|
+
}));
|
|
349
|
+
inputMessagesJson = helpers_1.default.buildInputMessages(formatted);
|
|
350
|
+
const text = response?.message?.content || response?.text || '';
|
|
351
|
+
outputMessagesJson = helpers_1.default.buildOutputMessages(text, finishReason);
|
|
352
|
+
}
|
|
353
|
+
else {
|
|
354
|
+
const prompt = typeof args[0] === 'string' ? args[0] : args[0]?.prompt || '';
|
|
355
|
+
inputMessagesJson = helpers_1.default.buildInputMessages([{ role: 'user', content: prompt }]);
|
|
356
|
+
const text = response?.text || '';
|
|
357
|
+
outputMessagesJson = helpers_1.default.buildOutputMessages(text, finishReason);
|
|
358
|
+
}
|
|
359
|
+
span.setAttribute(semantic_convention_1.default.GEN_AI_INPUT_MESSAGES, inputMessagesJson);
|
|
360
|
+
span.setAttribute(semantic_convention_1.default.GEN_AI_OUTPUT_MESSAGES, outputMessagesJson);
|
|
361
|
+
if (systemInstructionsJson) {
|
|
362
|
+
span.setAttribute(semantic_convention_1.default.GEN_AI_SYSTEM_INSTRUCTIONS, systemInstructionsJson);
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
if (toolDefinitionsJson) {
|
|
366
|
+
span.setAttribute(semantic_convention_1.default.GEN_AI_TOOL_DEFINITIONS, toolDefinitionsJson);
|
|
367
|
+
}
|
|
368
|
+
const eventAttrs = {
|
|
369
|
+
[semantic_convention_1.default.GEN_AI_OPERATION]: semantic_convention_1.default.GEN_AI_OPERATION_TYPE_CHAT,
|
|
370
|
+
[semantic_convention_1.default.GEN_AI_REQUEST_MODEL]: requestModel,
|
|
371
|
+
[semantic_convention_1.default.GEN_AI_RESPONSE_MODEL]: responseModel,
|
|
372
|
+
[semantic_convention_1.default.SERVER_ADDRESS]: serverAddress,
|
|
373
|
+
[semantic_convention_1.default.SERVER_PORT]: serverPort,
|
|
374
|
+
[semantic_convention_1.default.GEN_AI_RESPONSE_ID]: responseId,
|
|
375
|
+
[semantic_convention_1.default.GEN_AI_RESPONSE_FINISH_REASON]: [finishReason],
|
|
376
|
+
[semantic_convention_1.default.GEN_AI_OUTPUT_TYPE]: semantic_convention_1.default.GEN_AI_OUTPUT_TYPE_TEXT,
|
|
377
|
+
[semantic_convention_1.default.GEN_AI_USAGE_INPUT_TOKENS]: inputTokens,
|
|
378
|
+
[semantic_convention_1.default.GEN_AI_USAGE_OUTPUT_TOKENS]: outputTokens,
|
|
379
|
+
...versionExtras,
|
|
380
|
+
};
|
|
381
|
+
if (config_1.default.captureMessageContent) {
|
|
382
|
+
eventAttrs[semantic_convention_1.default.GEN_AI_INPUT_MESSAGES] = inputMessagesJson;
|
|
383
|
+
eventAttrs[semantic_convention_1.default.GEN_AI_OUTPUT_MESSAGES] = outputMessagesJson;
|
|
384
|
+
if (systemInstructionsJson)
|
|
385
|
+
eventAttrs[semantic_convention_1.default.GEN_AI_SYSTEM_INSTRUCTIONS] = systemInstructionsJson;
|
|
386
|
+
}
|
|
387
|
+
if (toolDefinitionsJson)
|
|
388
|
+
eventAttrs[semantic_convention_1.default.GEN_AI_TOOL_DEFINITIONS] = toolDefinitionsJson;
|
|
389
|
+
helpers_1.default.emitInferenceEvent(span, eventAttrs);
|
|
390
|
+
base_wrapper_1.default.recordMetrics(span, {
|
|
391
|
+
genAIEndpoint: endpoint,
|
|
392
|
+
model: requestModel,
|
|
393
|
+
cost,
|
|
394
|
+
aiSystem: LlamaIndexWrapper.aiSystem,
|
|
395
|
+
serverAddress,
|
|
396
|
+
serverPort,
|
|
397
|
+
});
|
|
398
|
+
span.end();
|
|
399
|
+
}
|
|
400
|
+
// ---------------------------------------------------------------------------
|
|
401
|
+
// Query engine query patch — retrieval span with source nodes
|
|
402
|
+
// Mirrors Python: RetrieverQueryEngine.query -> operation_type "retrieval"
|
|
403
|
+
// ---------------------------------------------------------------------------
|
|
404
|
+
static _patchQueryEngineQuery(tracer) {
|
|
405
|
+
const endpoint = 'query_engine_query';
|
|
406
|
+
const operationType = OPERATION_MAP[endpoint];
|
|
407
|
+
return (originalMethod) => {
|
|
408
|
+
return function (...args) {
|
|
409
|
+
const requestModel = LlamaIndexWrapper._extractModel(this);
|
|
410
|
+
const { address, port } = LlamaIndexWrapper._extractServerInfo(this?.llm || this?._llm || this);
|
|
411
|
+
const spanName = `${operationType} ${endpoint}`;
|
|
412
|
+
const span = tracer.startSpan(spanName, {
|
|
413
|
+
kind: api_1.SpanKind.CLIENT,
|
|
414
|
+
attributes: {
|
|
415
|
+
[semantic_convention_1.default.GEN_AI_OPERATION]: operationType,
|
|
416
|
+
[semantic_convention_1.default.GEN_AI_PROVIDER_NAME_OTEL]: LlamaIndexWrapper.aiSystem,
|
|
417
|
+
},
|
|
418
|
+
});
|
|
419
|
+
return api_1.context.with(api_1.trace.setSpan(api_1.context.active(), span), () => {
|
|
420
|
+
const startTime = Date.now();
|
|
421
|
+
const onSuccess = (response) => {
|
|
422
|
+
try {
|
|
423
|
+
const duration = (Date.now() - startTime) / 1000;
|
|
424
|
+
base_wrapper_1.default.setBaseSpanAttributes(span, {
|
|
425
|
+
genAIEndpoint: endpoint,
|
|
426
|
+
model: requestModel,
|
|
427
|
+
aiSystem: LlamaIndexWrapper.aiSystem,
|
|
428
|
+
serverAddress: address,
|
|
429
|
+
serverPort: port,
|
|
430
|
+
});
|
|
431
|
+
span.setAttribute(semantic_convention_1.default.GEN_AI_CLIENT_OPERATION_DURATION, duration);
|
|
432
|
+
const sourceNodes = response?.sourceNodes || response?.source_nodes || [];
|
|
433
|
+
if (sourceNodes.length > 0) {
|
|
434
|
+
span.setAttribute(semantic_convention_1.default.GEN_AI_RETRIEVAL_SOURCE, JSON.stringify(sourceNodes.slice(0, 5).map((n) => ({
|
|
435
|
+
id: n.node?.id_ || n.id_ || '',
|
|
436
|
+
score: n.score,
|
|
437
|
+
text: n.node?.text?.slice(0, 200) || '',
|
|
438
|
+
}))));
|
|
439
|
+
}
|
|
440
|
+
if (config_1.default.captureMessageContent) {
|
|
441
|
+
const queryStr = typeof args[0] === 'string'
|
|
442
|
+
? args[0]
|
|
443
|
+
: args[0]?.query || args[0]?.queryStr || '';
|
|
444
|
+
span.setAttribute(semantic_convention_1.default.GEN_AI_INPUT_MESSAGES, helpers_1.default.buildInputMessages([{ role: 'user', content: queryStr }]));
|
|
445
|
+
const responseText = typeof response?.response === 'string'
|
|
446
|
+
? response.response
|
|
447
|
+
: response?.message?.content || response?.toString?.() || '';
|
|
448
|
+
span.setAttribute(semantic_convention_1.default.GEN_AI_OUTPUT_MESSAGES, helpers_1.default.buildOutputMessages(responseText, 'stop'));
|
|
449
|
+
}
|
|
450
|
+
base_wrapper_1.default.recordMetrics(span, {
|
|
451
|
+
genAIEndpoint: endpoint,
|
|
452
|
+
model: requestModel,
|
|
453
|
+
aiSystem: LlamaIndexWrapper.aiSystem,
|
|
454
|
+
serverAddress: address,
|
|
455
|
+
serverPort: port,
|
|
456
|
+
});
|
|
457
|
+
}
|
|
458
|
+
catch { /* swallow */ }
|
|
459
|
+
span.end();
|
|
460
|
+
return response;
|
|
461
|
+
};
|
|
462
|
+
const onError = (e) => {
|
|
463
|
+
helpers_1.default.handleException(span, e);
|
|
464
|
+
base_wrapper_1.default.recordMetrics(span, {
|
|
465
|
+
genAIEndpoint: endpoint,
|
|
466
|
+
model: requestModel,
|
|
467
|
+
aiSystem: LlamaIndexWrapper.aiSystem,
|
|
468
|
+
serverAddress: address,
|
|
469
|
+
serverPort: port,
|
|
470
|
+
errorType: e?.constructor?.name || '_OTHER',
|
|
471
|
+
});
|
|
472
|
+
span.end();
|
|
473
|
+
throw e;
|
|
474
|
+
};
|
|
475
|
+
try {
|
|
476
|
+
const result = originalMethod.apply(this, args);
|
|
477
|
+
if (result && typeof result.then === 'function') {
|
|
478
|
+
return result.then(onSuccess).catch(onError);
|
|
479
|
+
}
|
|
480
|
+
return onSuccess(result);
|
|
481
|
+
}
|
|
482
|
+
catch (e) {
|
|
483
|
+
return onError(e);
|
|
484
|
+
}
|
|
485
|
+
});
|
|
486
|
+
};
|
|
487
|
+
};
|
|
488
|
+
}
|
|
489
|
+
// ---------------------------------------------------------------------------
|
|
490
|
+
// Chat engine chat patch — framework span with chat content
|
|
491
|
+
// Mirrors Python: chat engine operations -> operation_type "invoke_workflow"
|
|
492
|
+
// ---------------------------------------------------------------------------
|
|
493
|
+
static _patchChatEngineChat(tracer) {
|
|
494
|
+
const endpoint = 'chat_engine_chat';
|
|
495
|
+
const operationType = semantic_convention_1.default.GEN_AI_OPERATION_TYPE_FRAMEWORK;
|
|
496
|
+
return (originalMethod) => {
|
|
497
|
+
return function (...args) {
|
|
498
|
+
const requestModel = LlamaIndexWrapper._extractModel(this);
|
|
499
|
+
const { address, port } = LlamaIndexWrapper._extractServerInfo(this?.llm || this?._llm || this);
|
|
500
|
+
const workflowName = this?.constructor?.name || 'chat_engine';
|
|
501
|
+
const spanName = `${operationType} ${workflowName}`;
|
|
502
|
+
const span = tracer.startSpan(spanName, {
|
|
503
|
+
kind: api_1.SpanKind.INTERNAL,
|
|
504
|
+
attributes: {
|
|
505
|
+
[semantic_convention_1.default.GEN_AI_OPERATION]: operationType,
|
|
506
|
+
[semantic_convention_1.default.GEN_AI_PROVIDER_NAME_OTEL]: LlamaIndexWrapper.aiSystem,
|
|
507
|
+
[semantic_convention_1.default.GEN_AI_WORKFLOW_NAME]: workflowName,
|
|
508
|
+
},
|
|
509
|
+
});
|
|
510
|
+
return api_1.context.with(api_1.trace.setSpan(api_1.context.active(), span), () => {
|
|
511
|
+
const startTime = Date.now();
|
|
512
|
+
const onSuccess = (response) => {
|
|
513
|
+
try {
|
|
514
|
+
const duration = (Date.now() - startTime) / 1000;
|
|
515
|
+
base_wrapper_1.default.setBaseSpanAttributes(span, {
|
|
516
|
+
genAIEndpoint: endpoint,
|
|
517
|
+
model: requestModel,
|
|
518
|
+
aiSystem: LlamaIndexWrapper.aiSystem,
|
|
519
|
+
serverAddress: address,
|
|
520
|
+
serverPort: port,
|
|
521
|
+
});
|
|
522
|
+
span.setAttribute(semantic_convention_1.default.GEN_AI_CLIENT_OPERATION_DURATION, duration);
|
|
523
|
+
if (config_1.default.captureMessageContent) {
|
|
524
|
+
const messageInput = args[0];
|
|
525
|
+
const message = typeof messageInput === 'string'
|
|
526
|
+
? messageInput
|
|
527
|
+
: messageInput?.message || messageInput?.content || '';
|
|
528
|
+
span.setAttribute(semantic_convention_1.default.GEN_AI_INPUT_MESSAGES, helpers_1.default.buildInputMessages([{ role: 'user', content: message }]));
|
|
529
|
+
const responseContent = response?.message?.content
|
|
530
|
+
|| (typeof response?.response === 'string' ? response.response : '')
|
|
531
|
+
|| response?.toString?.() || '';
|
|
532
|
+
span.setAttribute(semantic_convention_1.default.GEN_AI_OUTPUT_MESSAGES, helpers_1.default.buildOutputMessages(responseContent, 'stop'));
|
|
533
|
+
}
|
|
534
|
+
base_wrapper_1.default.recordMetrics(span, {
|
|
535
|
+
genAIEndpoint: endpoint,
|
|
536
|
+
model: requestModel,
|
|
537
|
+
aiSystem: LlamaIndexWrapper.aiSystem,
|
|
538
|
+
serverAddress: address,
|
|
539
|
+
serverPort: port,
|
|
540
|
+
});
|
|
541
|
+
}
|
|
542
|
+
catch { /* swallow */ }
|
|
543
|
+
span.end();
|
|
544
|
+
return response;
|
|
545
|
+
};
|
|
546
|
+
const onError = (e) => {
|
|
547
|
+
helpers_1.default.handleException(span, e);
|
|
548
|
+
base_wrapper_1.default.recordMetrics(span, {
|
|
549
|
+
genAIEndpoint: endpoint,
|
|
550
|
+
model: requestModel,
|
|
551
|
+
aiSystem: LlamaIndexWrapper.aiSystem,
|
|
552
|
+
serverAddress: address,
|
|
553
|
+
serverPort: port,
|
|
554
|
+
errorType: e?.constructor?.name || '_OTHER',
|
|
555
|
+
});
|
|
556
|
+
span.end();
|
|
557
|
+
throw e;
|
|
558
|
+
};
|
|
559
|
+
try {
|
|
560
|
+
const result = originalMethod.apply(this, args);
|
|
561
|
+
if (result && typeof result.then === 'function') {
|
|
562
|
+
return result.then(onSuccess).catch(onError);
|
|
563
|
+
}
|
|
564
|
+
return onSuccess(result);
|
|
565
|
+
}
|
|
566
|
+
catch (e) {
|
|
567
|
+
return onError(e);
|
|
568
|
+
}
|
|
569
|
+
});
|
|
570
|
+
};
|
|
571
|
+
};
|
|
572
|
+
}
|
|
573
|
+
// ---------------------------------------------------------------------------
|
|
574
|
+
// Retriever retrieve patch — retrieval span
|
|
575
|
+
// Mirrors Python: BaseRetriever.retrieve -> operation_type "retrieval"
|
|
576
|
+
// ---------------------------------------------------------------------------
|
|
577
|
+
static _patchRetrieverRetrieve(tracer) {
|
|
578
|
+
const endpoint = 'retriever_retrieve';
|
|
579
|
+
const operationType = OPERATION_MAP[endpoint];
|
|
580
|
+
return (originalMethod) => {
|
|
581
|
+
return function (...args) {
|
|
582
|
+
const { address, port } = LlamaIndexWrapper._extractServerInfo(this);
|
|
583
|
+
const spanName = `${operationType} ${endpoint}`;
|
|
584
|
+
const span = tracer.startSpan(spanName, {
|
|
585
|
+
kind: api_1.SpanKind.CLIENT,
|
|
586
|
+
attributes: {
|
|
587
|
+
[semantic_convention_1.default.GEN_AI_OPERATION]: operationType,
|
|
588
|
+
[semantic_convention_1.default.GEN_AI_PROVIDER_NAME_OTEL]: LlamaIndexWrapper.aiSystem,
|
|
589
|
+
},
|
|
590
|
+
});
|
|
591
|
+
return api_1.context.with(api_1.trace.setSpan(api_1.context.active(), span), () => {
|
|
592
|
+
const startTime = Date.now();
|
|
593
|
+
const model = LlamaIndexWrapper._extractModel(this);
|
|
594
|
+
const onSuccess = (response) => {
|
|
595
|
+
try {
|
|
596
|
+
const duration = (Date.now() - startTime) / 1000;
|
|
597
|
+
base_wrapper_1.default.setBaseSpanAttributes(span, {
|
|
598
|
+
genAIEndpoint: endpoint,
|
|
599
|
+
model,
|
|
600
|
+
aiSystem: LlamaIndexWrapper.aiSystem,
|
|
601
|
+
serverAddress: address,
|
|
602
|
+
serverPort: port,
|
|
603
|
+
});
|
|
604
|
+
span.setAttribute(semantic_convention_1.default.GEN_AI_CLIENT_OPERATION_DURATION, duration);
|
|
605
|
+
if (Array.isArray(response) && response.length > 0) {
|
|
606
|
+
span.setAttribute(semantic_convention_1.default.GEN_AI_RETRIEVAL_SOURCE, JSON.stringify(response.slice(0, 5).map((n) => ({
|
|
607
|
+
id: n.node?.id_ || n.id_ || '',
|
|
608
|
+
score: n.score,
|
|
609
|
+
text: n.node?.text?.slice(0, 200) || n.text?.slice(0, 200) || '',
|
|
610
|
+
}))));
|
|
611
|
+
}
|
|
612
|
+
if (config_1.default.captureMessageContent) {
|
|
613
|
+
const queryStr = typeof args[0] === 'string'
|
|
614
|
+
? args[0]
|
|
615
|
+
: args[0]?.query || args[0]?.queryStr || '';
|
|
616
|
+
span.setAttribute(semantic_convention_1.default.GEN_AI_INPUT_MESSAGES, helpers_1.default.buildInputMessages([{ role: 'user', content: queryStr }]));
|
|
617
|
+
}
|
|
618
|
+
base_wrapper_1.default.recordMetrics(span, {
|
|
619
|
+
genAIEndpoint: endpoint,
|
|
620
|
+
model,
|
|
621
|
+
aiSystem: LlamaIndexWrapper.aiSystem,
|
|
622
|
+
serverAddress: address,
|
|
623
|
+
serverPort: port,
|
|
624
|
+
});
|
|
625
|
+
}
|
|
626
|
+
catch { /* swallow */ }
|
|
627
|
+
span.end();
|
|
628
|
+
return response;
|
|
629
|
+
};
|
|
630
|
+
const onError = (e) => {
|
|
631
|
+
helpers_1.default.handleException(span, e);
|
|
632
|
+
base_wrapper_1.default.recordMetrics(span, {
|
|
633
|
+
genAIEndpoint: endpoint,
|
|
634
|
+
model,
|
|
635
|
+
aiSystem: LlamaIndexWrapper.aiSystem,
|
|
636
|
+
serverAddress: address,
|
|
637
|
+
serverPort: port,
|
|
638
|
+
errorType: e?.constructor?.name || '_OTHER',
|
|
639
|
+
});
|
|
640
|
+
span.end();
|
|
641
|
+
throw e;
|
|
642
|
+
};
|
|
643
|
+
try {
|
|
644
|
+
const result = originalMethod.apply(this, args);
|
|
645
|
+
if (result && typeof result.then === 'function') {
|
|
646
|
+
return result.then(onSuccess).catch(onError);
|
|
647
|
+
}
|
|
648
|
+
return onSuccess(result);
|
|
649
|
+
}
|
|
650
|
+
catch (e) {
|
|
651
|
+
return onError(e);
|
|
652
|
+
}
|
|
653
|
+
});
|
|
654
|
+
};
|
|
655
|
+
};
|
|
656
|
+
}
|
|
657
|
+
// ---------------------------------------------------------------------------
|
|
658
|
+
// Embedding patch — embeddings span
|
|
659
|
+
// Mirrors Python: BaseEmbedding.get_text_embedding_batch -> "embeddings"
|
|
660
|
+
// ---------------------------------------------------------------------------
|
|
661
|
+
static _patchEmbedding(tracer, endpoint = 'embedding_generate') {
|
|
662
|
+
const operationType = OPERATION_MAP[endpoint] || semantic_convention_1.default.GEN_AI_OPERATION_TYPE_EMBEDDING;
|
|
663
|
+
return (originalMethod) => {
|
|
664
|
+
return function (...args) {
|
|
665
|
+
const model = LlamaIndexWrapper._extractModel(this);
|
|
666
|
+
const { address, port } = LlamaIndexWrapper._extractServerInfo(this);
|
|
667
|
+
const spanName = `${operationType} ${endpoint}`;
|
|
668
|
+
const span = tracer.startSpan(spanName, {
|
|
669
|
+
kind: api_1.SpanKind.CLIENT,
|
|
670
|
+
attributes: {
|
|
671
|
+
[semantic_convention_1.default.GEN_AI_OPERATION]: operationType,
|
|
672
|
+
[semantic_convention_1.default.GEN_AI_PROVIDER_NAME_OTEL]: LlamaIndexWrapper.aiSystem,
|
|
673
|
+
[semantic_convention_1.default.GEN_AI_REQUEST_MODEL]: model,
|
|
674
|
+
[semantic_convention_1.default.SERVER_ADDRESS]: address,
|
|
675
|
+
[semantic_convention_1.default.SERVER_PORT]: port,
|
|
676
|
+
},
|
|
677
|
+
});
|
|
678
|
+
return api_1.context.with(api_1.trace.setSpan(api_1.context.active(), span), () => {
|
|
679
|
+
const startTime = Date.now();
|
|
680
|
+
const onSuccess = (response) => {
|
|
681
|
+
try {
|
|
682
|
+
const duration = (Date.now() - startTime) / 1000;
|
|
683
|
+
base_wrapper_1.default.setBaseSpanAttributes(span, {
|
|
684
|
+
genAIEndpoint: endpoint,
|
|
685
|
+
model,
|
|
686
|
+
aiSystem: LlamaIndexWrapper.aiSystem,
|
|
687
|
+
serverAddress: address,
|
|
688
|
+
serverPort: port,
|
|
689
|
+
});
|
|
690
|
+
span.setAttribute(semantic_convention_1.default.GEN_AI_CLIENT_OPERATION_DURATION, duration);
|
|
691
|
+
if (Array.isArray(response) && response.length > 0) {
|
|
692
|
+
if (Array.isArray(response[0])) {
|
|
693
|
+
span.setAttribute(semantic_convention_1.default.GEN_AI_EMBEDDINGS_DIMENSION_COUNT, response[0].length);
|
|
694
|
+
}
|
|
695
|
+
else if (typeof response[0] === 'number') {
|
|
696
|
+
span.setAttribute(semantic_convention_1.default.GEN_AI_EMBEDDINGS_DIMENSION_COUNT, response.length);
|
|
697
|
+
}
|
|
698
|
+
}
|
|
699
|
+
base_wrapper_1.default.recordMetrics(span, {
|
|
700
|
+
genAIEndpoint: endpoint,
|
|
701
|
+
model,
|
|
702
|
+
aiSystem: LlamaIndexWrapper.aiSystem,
|
|
703
|
+
serverAddress: address,
|
|
704
|
+
serverPort: port,
|
|
705
|
+
});
|
|
706
|
+
}
|
|
707
|
+
catch { /* swallow */ }
|
|
708
|
+
span.end();
|
|
709
|
+
return response;
|
|
710
|
+
};
|
|
711
|
+
const onError = (e) => {
|
|
712
|
+
helpers_1.default.handleException(span, e);
|
|
713
|
+
base_wrapper_1.default.recordMetrics(span, {
|
|
714
|
+
genAIEndpoint: endpoint,
|
|
715
|
+
model,
|
|
716
|
+
aiSystem: LlamaIndexWrapper.aiSystem,
|
|
717
|
+
serverAddress: address,
|
|
718
|
+
serverPort: port,
|
|
719
|
+
errorType: e?.constructor?.name || '_OTHER',
|
|
720
|
+
});
|
|
721
|
+
span.end();
|
|
722
|
+
throw e;
|
|
723
|
+
};
|
|
724
|
+
try {
|
|
725
|
+
const result = (0, helpers_1.runWithFrameworkLlm)(() => originalMethod.apply(this, args));
|
|
726
|
+
if (result && typeof result.then === 'function') {
|
|
727
|
+
return result.then(onSuccess).catch(onError);
|
|
728
|
+
}
|
|
729
|
+
return onSuccess(result);
|
|
730
|
+
}
|
|
731
|
+
catch (e) {
|
|
732
|
+
return onError(e);
|
|
733
|
+
}
|
|
734
|
+
});
|
|
735
|
+
};
|
|
736
|
+
};
|
|
737
|
+
}
|
|
738
|
+
// ---------------------------------------------------------------------------
|
|
739
|
+
// Generic framework method patch — for index, document, synthesizer, etc.
|
|
740
|
+
// Mirrors Python: common_llamaindex_logic with framework-level attributes
|
|
741
|
+
// ---------------------------------------------------------------------------
|
|
742
|
+
static _patchFrameworkMethod(tracer, endpoint) {
|
|
743
|
+
const operationType = OPERATION_MAP[endpoint] || semantic_convention_1.default.GEN_AI_OPERATION_TYPE_FRAMEWORK;
|
|
744
|
+
return (originalMethod) => {
|
|
745
|
+
return function (...args) {
|
|
746
|
+
const { address, port } = LlamaIndexWrapper._extractServerInfo(this);
|
|
747
|
+
const spanName = `${operationType} ${endpoint}`;
|
|
748
|
+
const span = tracer.startSpan(spanName, {
|
|
749
|
+
kind: api_1.SpanKind.CLIENT,
|
|
750
|
+
attributes: {
|
|
751
|
+
[semantic_convention_1.default.GEN_AI_OPERATION]: operationType,
|
|
752
|
+
[semantic_convention_1.default.GEN_AI_PROVIDER_NAME_OTEL]: LlamaIndexWrapper.aiSystem,
|
|
753
|
+
},
|
|
754
|
+
});
|
|
755
|
+
return api_1.context.with(api_1.trace.setSpan(api_1.context.active(), span), () => {
|
|
756
|
+
const startTime = Date.now();
|
|
757
|
+
const model = LlamaIndexWrapper._extractModel(this);
|
|
758
|
+
const onSuccess = (response) => {
|
|
759
|
+
try {
|
|
760
|
+
const duration = (Date.now() - startTime) / 1000;
|
|
761
|
+
base_wrapper_1.default.setBaseSpanAttributes(span, {
|
|
762
|
+
genAIEndpoint: endpoint,
|
|
763
|
+
model,
|
|
764
|
+
aiSystem: LlamaIndexWrapper.aiSystem,
|
|
765
|
+
serverAddress: address,
|
|
766
|
+
serverPort: port,
|
|
767
|
+
});
|
|
768
|
+
span.setAttribute(semantic_convention_1.default.GEN_AI_CLIENT_OPERATION_DURATION, duration);
|
|
769
|
+
base_wrapper_1.default.recordMetrics(span, {
|
|
770
|
+
genAIEndpoint: endpoint,
|
|
771
|
+
model,
|
|
772
|
+
aiSystem: LlamaIndexWrapper.aiSystem,
|
|
773
|
+
serverAddress: address,
|
|
774
|
+
serverPort: port,
|
|
775
|
+
});
|
|
776
|
+
}
|
|
777
|
+
catch { /* swallow */ }
|
|
778
|
+
span.end();
|
|
779
|
+
return response;
|
|
780
|
+
};
|
|
781
|
+
const onError = (e) => {
|
|
782
|
+
helpers_1.default.handleException(span, e);
|
|
783
|
+
base_wrapper_1.default.recordMetrics(span, {
|
|
784
|
+
genAIEndpoint: endpoint,
|
|
785
|
+
model,
|
|
786
|
+
aiSystem: LlamaIndexWrapper.aiSystem,
|
|
787
|
+
serverAddress: address,
|
|
788
|
+
serverPort: port,
|
|
789
|
+
errorType: e?.constructor?.name || '_OTHER',
|
|
790
|
+
});
|
|
791
|
+
span.end();
|
|
792
|
+
throw e;
|
|
793
|
+
};
|
|
794
|
+
try {
|
|
795
|
+
const result = originalMethod.apply(this, args);
|
|
796
|
+
if (result && typeof result.then === 'function') {
|
|
797
|
+
return result.then(onSuccess).catch(onError);
|
|
798
|
+
}
|
|
799
|
+
return onSuccess(result);
|
|
800
|
+
}
|
|
801
|
+
catch (e) {
|
|
802
|
+
return onError(e);
|
|
803
|
+
}
|
|
804
|
+
});
|
|
805
|
+
};
|
|
806
|
+
};
|
|
807
|
+
}
|
|
808
|
+
}
|
|
809
|
+
LlamaIndexWrapper.aiSystem = semantic_convention_1.default.GEN_AI_SYSTEM_LLAMAINDEX;
|
|
810
|
+
exports.default = LlamaIndexWrapper;
|
|
811
|
+
//# sourceMappingURL=wrapper.js.map
|