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,687 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Cross-Language Trace Comparison Tests for Groq Integration
|
|
4
|
+
*
|
|
5
|
+
* These tests verify that TypeScript and Python generate equivalent traces
|
|
6
|
+
* for the same operations.
|
|
7
|
+
*/
|
|
8
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
9
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
const wrapper_1 = __importDefault(require("../groq/wrapper"));
|
|
13
|
+
const config_1 = __importDefault(require("../../config"));
|
|
14
|
+
const helpers_1 = __importDefault(require("../../helpers"));
|
|
15
|
+
const base_wrapper_1 = __importDefault(require("../base-wrapper"));
|
|
16
|
+
const semantic_convention_1 = __importDefault(require("../../semantic-convention"));
|
|
17
|
+
jest.mock('../../config');
|
|
18
|
+
jest.mock('../../helpers');
|
|
19
|
+
jest.mock('../base-wrapper');
|
|
20
|
+
describe('Groq Cross-Language Trace Comparison', () => {
|
|
21
|
+
let mockSpan;
|
|
22
|
+
let _mockTracer;
|
|
23
|
+
beforeEach(() => {
|
|
24
|
+
mockSpan = {
|
|
25
|
+
setAttribute: jest.fn(),
|
|
26
|
+
addEvent: jest.fn(),
|
|
27
|
+
end: jest.fn(),
|
|
28
|
+
setStatus: jest.fn(),
|
|
29
|
+
};
|
|
30
|
+
_mockTracer = {
|
|
31
|
+
startSpan: jest.fn().mockReturnValue(mockSpan),
|
|
32
|
+
};
|
|
33
|
+
config_1.default.environment = 'shield360-testing';
|
|
34
|
+
config_1.default.applicationName = 'shield360-test';
|
|
35
|
+
config_1.default.captureMessageContent = true;
|
|
36
|
+
config_1.default.pricingInfo = {};
|
|
37
|
+
config_1.default.disableEvents = false;
|
|
38
|
+
helpers_1.default.getChatModelCost = jest.fn().mockReturnValue(0.001);
|
|
39
|
+
helpers_1.default.openaiTokens = jest.fn().mockReturnValue(5);
|
|
40
|
+
helpers_1.default.handleException = jest.fn();
|
|
41
|
+
helpers_1.default.createStreamProxy = jest.fn().mockImplementation((stream, _generator) => stream);
|
|
42
|
+
helpers_1.default.buildInputMessages = jest.fn().mockReturnValue('[{"role":"user","parts":[{"type":"text","content":"Test"}]}]');
|
|
43
|
+
helpers_1.default.buildOutputMessages = jest.fn().mockReturnValue('[{"role":"assistant","parts":[{"type":"text","content":"Response"}],"finish_reason":"stop"}]');
|
|
44
|
+
helpers_1.default.buildSystemInstructionsFromMessages = jest.fn().mockImplementation((messages) => {
|
|
45
|
+
const sys = (messages || []).find((m) => m?.role === 'system');
|
|
46
|
+
return sys ? JSON.stringify([{ type: 'text', content: String(sys.content) }]) : undefined;
|
|
47
|
+
});
|
|
48
|
+
helpers_1.default.buildToolDefinitions = jest.fn().mockImplementation((tools) => {
|
|
49
|
+
if (!Array.isArray(tools) || tools.length === 0)
|
|
50
|
+
return undefined;
|
|
51
|
+
return JSON.stringify(tools
|
|
52
|
+
.filter((t) => t?.function?.name || t?.name)
|
|
53
|
+
.map((t) => ({
|
|
54
|
+
type: 'function',
|
|
55
|
+
name: t.function?.name ?? t.name,
|
|
56
|
+
description: t.function?.description ?? t.description ?? '',
|
|
57
|
+
parameters: t.function?.parameters ?? t.parameters ?? {},
|
|
58
|
+
})));
|
|
59
|
+
});
|
|
60
|
+
helpers_1.default.emitInferenceEvent = jest.fn();
|
|
61
|
+
// Stamp a deterministic agent version hash so the assertions below can
|
|
62
|
+
// pin the exact attribute value. The real helper would canonicalise the
|
|
63
|
+
// prompt + tools + model + runtime config — none of which matters for
|
|
64
|
+
// verifying the wrapper *plumbs* the result onto the span.
|
|
65
|
+
helpers_1.default.computeAgentVersionHash = jest
|
|
66
|
+
.fn()
|
|
67
|
+
.mockReturnValue('ts-test-version-hash');
|
|
68
|
+
base_wrapper_1.default.recordMetrics = jest.fn();
|
|
69
|
+
base_wrapper_1.default.setBaseSpanAttributes = jest.fn().mockImplementation((span, attrs) => {
|
|
70
|
+
span.setAttribute(semantic_convention_1.default.GEN_AI_PROVIDER_NAME_OTEL, attrs.aiSystem);
|
|
71
|
+
span.setAttribute(semantic_convention_1.default.GEN_AI_REQUEST_MODEL, attrs.model);
|
|
72
|
+
if (attrs.cost !== undefined) {
|
|
73
|
+
span.setAttribute(semantic_convention_1.default.GEN_AI_USAGE_COST, attrs.cost);
|
|
74
|
+
}
|
|
75
|
+
if (attrs.serverAddress) {
|
|
76
|
+
span.setAttribute(semantic_convention_1.default.SERVER_ADDRESS, attrs.serverAddress);
|
|
77
|
+
}
|
|
78
|
+
if (attrs.serverPort !== undefined) {
|
|
79
|
+
span.setAttribute(semantic_convention_1.default.SERVER_PORT, attrs.serverPort);
|
|
80
|
+
}
|
|
81
|
+
span.setAttribute(semantic_convention_1.default.GEN_AI_SDK_VERSION, '1.9.0');
|
|
82
|
+
});
|
|
83
|
+
});
|
|
84
|
+
afterEach(() => {
|
|
85
|
+
jest.clearAllMocks();
|
|
86
|
+
});
|
|
87
|
+
describe('Chat Completion Trace Consistency', () => {
|
|
88
|
+
it('should set same attributes as Python SDK', async () => {
|
|
89
|
+
const mockArgs = [
|
|
90
|
+
{
|
|
91
|
+
messages: [{ role: 'user', content: 'What is LLM Observability?' }],
|
|
92
|
+
model: 'llama-3.1-8b-instant',
|
|
93
|
+
max_tokens: 100,
|
|
94
|
+
temperature: 0.7,
|
|
95
|
+
stream: false,
|
|
96
|
+
},
|
|
97
|
+
];
|
|
98
|
+
const mockResponse = {
|
|
99
|
+
id: 'test-id-123',
|
|
100
|
+
created: Date.now(),
|
|
101
|
+
model: 'llama-3.1-8b-instant',
|
|
102
|
+
choices: [
|
|
103
|
+
{
|
|
104
|
+
index: 0,
|
|
105
|
+
finish_reason: 'stop',
|
|
106
|
+
message: { role: 'assistant', content: 'LLM Observability is...' },
|
|
107
|
+
},
|
|
108
|
+
],
|
|
109
|
+
usage: {
|
|
110
|
+
prompt_tokens: 10,
|
|
111
|
+
completion_tokens: 20,
|
|
112
|
+
total_tokens: 30,
|
|
113
|
+
},
|
|
114
|
+
};
|
|
115
|
+
await wrapper_1.default._chatCompletion({
|
|
116
|
+
args: mockArgs,
|
|
117
|
+
genAIEndpoint: 'groq.chat.completions',
|
|
118
|
+
response: mockResponse,
|
|
119
|
+
span: mockSpan,
|
|
120
|
+
});
|
|
121
|
+
expect(mockSpan.setAttribute).toHaveBeenCalledWith(semantic_convention_1.default.GEN_AI_PROVIDER_NAME_OTEL, 'groq');
|
|
122
|
+
expect(mockSpan.setAttribute).toHaveBeenCalledWith(semantic_convention_1.default.GEN_AI_REQUEST_MODEL, 'llama-3.1-8b-instant');
|
|
123
|
+
expect(mockSpan.setAttribute).toHaveBeenCalledWith(semantic_convention_1.default.GEN_AI_RESPONSE_MODEL, 'llama-3.1-8b-instant');
|
|
124
|
+
expect(mockSpan.setAttribute).toHaveBeenCalledWith(semantic_convention_1.default.GEN_AI_RESPONSE_ID, 'test-id-123');
|
|
125
|
+
expect(mockSpan.setAttribute).toHaveBeenCalledWith(semantic_convention_1.default.GEN_AI_USAGE_INPUT_TOKENS, 10);
|
|
126
|
+
expect(mockSpan.setAttribute).toHaveBeenCalledWith(semantic_convention_1.default.GEN_AI_USAGE_OUTPUT_TOKENS, 20);
|
|
127
|
+
expect(mockSpan.setAttribute).toHaveBeenCalledWith(semantic_convention_1.default.GEN_AI_REQUEST_TEMPERATURE, 0.7);
|
|
128
|
+
expect(mockSpan.setAttribute).toHaveBeenCalledWith(semantic_convention_1.default.GEN_AI_REQUEST_MAX_TOKENS, 100);
|
|
129
|
+
expect(mockSpan.setAttribute).toHaveBeenCalledWith(semantic_convention_1.default.GEN_AI_REQUEST_IS_STREAM, false);
|
|
130
|
+
expect(mockSpan.setAttribute).toHaveBeenCalledWith(semantic_convention_1.default.GEN_AI_RESPONSE_FINISH_REASON, ['stop']);
|
|
131
|
+
expect(mockSpan.setAttribute).toHaveBeenCalledWith(semantic_convention_1.default.GEN_AI_OUTPUT_TYPE, 'text');
|
|
132
|
+
expect(mockSpan.setAttribute).toHaveBeenCalledWith(semantic_convention_1.default.SERVER_ADDRESS, 'api.groq.com');
|
|
133
|
+
expect(mockSpan.setAttribute).toHaveBeenCalledWith(semantic_convention_1.default.SERVER_PORT, 443);
|
|
134
|
+
expect(mockSpan.setAttribute).toHaveBeenCalledWith(semantic_convention_1.default.GEN_AI_SDK_VERSION, '1.9.0');
|
|
135
|
+
});
|
|
136
|
+
it('stamps shield360.agent.version_hash on the chat span', async () => {
|
|
137
|
+
const mockArgs = [
|
|
138
|
+
{
|
|
139
|
+
messages: [{ role: 'user', content: 'Hash me' }],
|
|
140
|
+
model: 'llama-3.1-8b-instant',
|
|
141
|
+
stream: false,
|
|
142
|
+
},
|
|
143
|
+
];
|
|
144
|
+
const mockResponse = {
|
|
145
|
+
id: 'hash-id',
|
|
146
|
+
created: Date.now(),
|
|
147
|
+
model: 'llama-3.1-8b-instant',
|
|
148
|
+
choices: [
|
|
149
|
+
{ index: 0, finish_reason: 'stop', message: { role: 'assistant', content: 'ok' } },
|
|
150
|
+
],
|
|
151
|
+
usage: { prompt_tokens: 1, completion_tokens: 1, total_tokens: 2 },
|
|
152
|
+
};
|
|
153
|
+
await wrapper_1.default._chatCompletion({
|
|
154
|
+
args: mockArgs,
|
|
155
|
+
genAIEndpoint: 'groq.chat.completions',
|
|
156
|
+
response: mockResponse,
|
|
157
|
+
span: mockSpan,
|
|
158
|
+
});
|
|
159
|
+
expect(helpers_1.default.computeAgentVersionHash).toHaveBeenCalled();
|
|
160
|
+
expect(mockSpan.setAttribute).toHaveBeenCalledWith(semantic_convention_1.default.SHIELD360_AGENT_VERSION_HASH, 'ts-test-version-hash');
|
|
161
|
+
});
|
|
162
|
+
it('should NOT set total_tokens or client.token.usage on span', async () => {
|
|
163
|
+
const mockArgs = [
|
|
164
|
+
{
|
|
165
|
+
messages: [{ role: 'user', content: 'Test' }],
|
|
166
|
+
model: 'llama-3.1-8b-instant',
|
|
167
|
+
stream: false,
|
|
168
|
+
},
|
|
169
|
+
];
|
|
170
|
+
const mockResponse = {
|
|
171
|
+
id: 'test',
|
|
172
|
+
model: 'llama-3.1-8b-instant',
|
|
173
|
+
choices: [{ message: { content: 'Response' }, finish_reason: 'stop' }],
|
|
174
|
+
usage: { prompt_tokens: 5, completion_tokens: 10, total_tokens: 15 },
|
|
175
|
+
};
|
|
176
|
+
await wrapper_1.default._chatCompletion({
|
|
177
|
+
args: mockArgs,
|
|
178
|
+
genAIEndpoint: 'groq.chat.completions',
|
|
179
|
+
response: mockResponse,
|
|
180
|
+
span: mockSpan,
|
|
181
|
+
});
|
|
182
|
+
const setAttributeCalls = mockSpan.setAttribute.mock.calls;
|
|
183
|
+
const attributeKeys = setAttributeCalls.map(([key]) => key);
|
|
184
|
+
expect(attributeKeys).not.toContain(semantic_convention_1.default.GEN_AI_USAGE_TOTAL_TOKENS);
|
|
185
|
+
expect(attributeKeys).not.toContain(semantic_convention_1.default.GEN_AI_CLIENT_TOKEN_USAGE);
|
|
186
|
+
});
|
|
187
|
+
it('should not set sentinel values for optional params', async () => {
|
|
188
|
+
const mockArgs = [
|
|
189
|
+
{
|
|
190
|
+
messages: [{ role: 'user', content: 'Test' }],
|
|
191
|
+
model: 'llama-3.1-8b-instant',
|
|
192
|
+
stream: false,
|
|
193
|
+
},
|
|
194
|
+
];
|
|
195
|
+
const mockResponse = {
|
|
196
|
+
id: 'test',
|
|
197
|
+
model: 'llama-3.1-8b-instant',
|
|
198
|
+
choices: [{ message: { content: 'Response' }, finish_reason: 'stop' }],
|
|
199
|
+
usage: { prompt_tokens: 5, completion_tokens: 10, total_tokens: 15 },
|
|
200
|
+
};
|
|
201
|
+
await wrapper_1.default._chatCompletion({
|
|
202
|
+
args: mockArgs,
|
|
203
|
+
genAIEndpoint: 'groq.chat.completions',
|
|
204
|
+
response: mockResponse,
|
|
205
|
+
span: mockSpan,
|
|
206
|
+
});
|
|
207
|
+
const setAttributeCalls = mockSpan.setAttribute.mock.calls;
|
|
208
|
+
const attributeKeys = setAttributeCalls.map(([key]) => key);
|
|
209
|
+
expect(attributeKeys).not.toContain(semantic_convention_1.default.GEN_AI_REQUEST_SEED);
|
|
210
|
+
expect(attributeKeys).not.toContain(semantic_convention_1.default.GEN_AI_REQUEST_FREQUENCY_PENALTY);
|
|
211
|
+
expect(attributeKeys).not.toContain(semantic_convention_1.default.GEN_AI_REQUEST_PRESENCE_PENALTY);
|
|
212
|
+
expect(attributeKeys).not.toContain(semantic_convention_1.default.GEN_AI_REQUEST_MAX_TOKENS);
|
|
213
|
+
expect(attributeKeys).not.toContain(semantic_convention_1.default.GEN_AI_REQUEST_STOP_SEQUENCES);
|
|
214
|
+
expect(attributeKeys).not.toContain(semantic_convention_1.default.GEN_AI_REQUEST_CHOICE_COUNT);
|
|
215
|
+
});
|
|
216
|
+
it('should set conditional params only when explicitly provided', async () => {
|
|
217
|
+
const mockArgs = [
|
|
218
|
+
{
|
|
219
|
+
messages: [{ role: 'user', content: 'Test' }],
|
|
220
|
+
model: 'llama-3.1-8b-instant',
|
|
221
|
+
max_tokens: 200,
|
|
222
|
+
seed: 42,
|
|
223
|
+
frequency_penalty: 0.5,
|
|
224
|
+
presence_penalty: 0.3,
|
|
225
|
+
stop: ['END'],
|
|
226
|
+
n: 2,
|
|
227
|
+
stream: false,
|
|
228
|
+
},
|
|
229
|
+
];
|
|
230
|
+
const mockResponse = {
|
|
231
|
+
id: 'test',
|
|
232
|
+
model: 'llama-3.1-8b-instant',
|
|
233
|
+
choices: [{ message: { content: 'Response' }, finish_reason: 'stop' }],
|
|
234
|
+
usage: { prompt_tokens: 5, completion_tokens: 10, total_tokens: 15 },
|
|
235
|
+
};
|
|
236
|
+
await wrapper_1.default._chatCompletion({
|
|
237
|
+
args: mockArgs,
|
|
238
|
+
genAIEndpoint: 'groq.chat.completions',
|
|
239
|
+
response: mockResponse,
|
|
240
|
+
span: mockSpan,
|
|
241
|
+
});
|
|
242
|
+
expect(mockSpan.setAttribute).toHaveBeenCalledWith(semantic_convention_1.default.GEN_AI_REQUEST_MAX_TOKENS, 200);
|
|
243
|
+
expect(mockSpan.setAttribute).toHaveBeenCalledWith(semantic_convention_1.default.GEN_AI_REQUEST_SEED, 42);
|
|
244
|
+
expect(mockSpan.setAttribute).toHaveBeenCalledWith(semantic_convention_1.default.GEN_AI_REQUEST_FREQUENCY_PENALTY, 0.5);
|
|
245
|
+
expect(mockSpan.setAttribute).toHaveBeenCalledWith(semantic_convention_1.default.GEN_AI_REQUEST_PRESENCE_PENALTY, 0.3);
|
|
246
|
+
expect(mockSpan.setAttribute).toHaveBeenCalledWith(semantic_convention_1.default.GEN_AI_REQUEST_STOP_SEQUENCES, ['END']);
|
|
247
|
+
expect(mockSpan.setAttribute).toHaveBeenCalledWith(semantic_convention_1.default.GEN_AI_REQUEST_CHOICE_COUNT, 2);
|
|
248
|
+
});
|
|
249
|
+
it('should emit inference event via LoggerProvider', async () => {
|
|
250
|
+
const mockArgs = [
|
|
251
|
+
{
|
|
252
|
+
messages: [{ role: 'user', content: 'Test' }],
|
|
253
|
+
model: 'llama-3.1-8b-instant',
|
|
254
|
+
stream: false,
|
|
255
|
+
},
|
|
256
|
+
];
|
|
257
|
+
const mockResponse = {
|
|
258
|
+
id: 'test-id',
|
|
259
|
+
model: 'llama-3.1-8b-instant',
|
|
260
|
+
choices: [{ message: { content: 'Response' }, finish_reason: 'stop' }],
|
|
261
|
+
usage: { prompt_tokens: 5, completion_tokens: 10, total_tokens: 15 },
|
|
262
|
+
};
|
|
263
|
+
await wrapper_1.default._chatCompletion({
|
|
264
|
+
args: mockArgs,
|
|
265
|
+
genAIEndpoint: 'groq.chat.completions',
|
|
266
|
+
response: mockResponse,
|
|
267
|
+
span: mockSpan,
|
|
268
|
+
});
|
|
269
|
+
expect(helpers_1.default.emitInferenceEvent).toHaveBeenCalledWith(mockSpan, expect.objectContaining({
|
|
270
|
+
[semantic_convention_1.default.GEN_AI_OPERATION]: semantic_convention_1.default.GEN_AI_OPERATION_TYPE_CHAT,
|
|
271
|
+
[semantic_convention_1.default.GEN_AI_REQUEST_MODEL]: 'llama-3.1-8b-instant',
|
|
272
|
+
[semantic_convention_1.default.GEN_AI_RESPONSE_MODEL]: 'llama-3.1-8b-instant',
|
|
273
|
+
[semantic_convention_1.default.SERVER_ADDRESS]: 'api.groq.com',
|
|
274
|
+
[semantic_convention_1.default.SERVER_PORT]: 443,
|
|
275
|
+
[semantic_convention_1.default.GEN_AI_RESPONSE_ID]: 'test-id',
|
|
276
|
+
[semantic_convention_1.default.GEN_AI_RESPONSE_FINISH_REASON]: ['stop'],
|
|
277
|
+
[semantic_convention_1.default.GEN_AI_USAGE_INPUT_TOKENS]: 5,
|
|
278
|
+
[semantic_convention_1.default.GEN_AI_USAGE_OUTPUT_TOKENS]: 10,
|
|
279
|
+
}));
|
|
280
|
+
});
|
|
281
|
+
it('should include message content in event when captureMessageContent is true', async () => {
|
|
282
|
+
config_1.default.captureMessageContent = true;
|
|
283
|
+
const mockArgs = [
|
|
284
|
+
{
|
|
285
|
+
messages: [{ role: 'user', content: 'Test' }],
|
|
286
|
+
model: 'llama-3.1-8b-instant',
|
|
287
|
+
stream: false,
|
|
288
|
+
},
|
|
289
|
+
];
|
|
290
|
+
const mockResponse = {
|
|
291
|
+
id: 'test-id',
|
|
292
|
+
model: 'llama-3.1-8b-instant',
|
|
293
|
+
choices: [{ message: { content: 'Response' }, finish_reason: 'stop' }],
|
|
294
|
+
usage: { prompt_tokens: 5, completion_tokens: 10, total_tokens: 15 },
|
|
295
|
+
};
|
|
296
|
+
await wrapper_1.default._chatCompletion({
|
|
297
|
+
args: mockArgs,
|
|
298
|
+
genAIEndpoint: 'groq.chat.completions',
|
|
299
|
+
response: mockResponse,
|
|
300
|
+
span: mockSpan,
|
|
301
|
+
});
|
|
302
|
+
expect(helpers_1.default.emitInferenceEvent).toHaveBeenCalledWith(mockSpan, expect.objectContaining({
|
|
303
|
+
[semantic_convention_1.default.GEN_AI_INPUT_MESSAGES]: expect.any(String),
|
|
304
|
+
[semantic_convention_1.default.GEN_AI_OUTPUT_MESSAGES]: expect.any(String),
|
|
305
|
+
}));
|
|
306
|
+
});
|
|
307
|
+
it('should NOT include message content in event when captureMessageContent is false', async () => {
|
|
308
|
+
config_1.default.captureMessageContent = false;
|
|
309
|
+
const mockArgs = [
|
|
310
|
+
{
|
|
311
|
+
messages: [{ role: 'user', content: 'Test' }],
|
|
312
|
+
model: 'llama-3.1-8b-instant',
|
|
313
|
+
stream: false,
|
|
314
|
+
},
|
|
315
|
+
];
|
|
316
|
+
const mockResponse = {
|
|
317
|
+
id: 'test-id',
|
|
318
|
+
model: 'llama-3.1-8b-instant',
|
|
319
|
+
choices: [{ message: { content: 'Response' }, finish_reason: 'stop' }],
|
|
320
|
+
usage: { prompt_tokens: 5, completion_tokens: 10, total_tokens: 15 },
|
|
321
|
+
};
|
|
322
|
+
await wrapper_1.default._chatCompletion({
|
|
323
|
+
args: mockArgs,
|
|
324
|
+
genAIEndpoint: 'groq.chat.completions',
|
|
325
|
+
response: mockResponse,
|
|
326
|
+
span: mockSpan,
|
|
327
|
+
});
|
|
328
|
+
const eventCall = helpers_1.default.emitInferenceEvent.mock.calls[0];
|
|
329
|
+
const eventAttrs = eventCall[1];
|
|
330
|
+
expect(eventAttrs).not.toHaveProperty(semantic_convention_1.default.GEN_AI_INPUT_MESSAGES);
|
|
331
|
+
expect(eventAttrs).not.toHaveProperty(semantic_convention_1.default.GEN_AI_OUTPUT_MESSAGES);
|
|
332
|
+
});
|
|
333
|
+
it('should handle tool calls properly', async () => {
|
|
334
|
+
const mockArgs = [
|
|
335
|
+
{
|
|
336
|
+
messages: [{ role: 'user', content: 'What is the weather?' }],
|
|
337
|
+
model: 'llama-3.1-8b-instant',
|
|
338
|
+
tools: [{ type: 'function', function: { name: 'get_weather' } }],
|
|
339
|
+
stream: false,
|
|
340
|
+
},
|
|
341
|
+
];
|
|
342
|
+
const mockResponse = {
|
|
343
|
+
id: 'test-id',
|
|
344
|
+
model: 'llama-3.1-8b-instant',
|
|
345
|
+
choices: [
|
|
346
|
+
{
|
|
347
|
+
message: {
|
|
348
|
+
content: null,
|
|
349
|
+
role: 'assistant',
|
|
350
|
+
tool_calls: [
|
|
351
|
+
{
|
|
352
|
+
id: 'call_123',
|
|
353
|
+
type: 'function',
|
|
354
|
+
function: { name: 'get_weather', arguments: '{"location":"SF"}' },
|
|
355
|
+
},
|
|
356
|
+
],
|
|
357
|
+
},
|
|
358
|
+
finish_reason: 'tool_calls',
|
|
359
|
+
},
|
|
360
|
+
],
|
|
361
|
+
usage: { prompt_tokens: 10, completion_tokens: 20, total_tokens: 30 },
|
|
362
|
+
};
|
|
363
|
+
await wrapper_1.default._chatCompletion({
|
|
364
|
+
args: mockArgs,
|
|
365
|
+
genAIEndpoint: 'groq.chat.completions',
|
|
366
|
+
response: mockResponse,
|
|
367
|
+
span: mockSpan,
|
|
368
|
+
});
|
|
369
|
+
expect(mockSpan.setAttribute).toHaveBeenCalledWith(semantic_convention_1.default.GEN_AI_TOOL_NAME, 'get_weather');
|
|
370
|
+
expect(mockSpan.setAttribute).toHaveBeenCalledWith(semantic_convention_1.default.GEN_AI_TOOL_CALL_ID, 'call_123');
|
|
371
|
+
expect(mockSpan.setAttribute).toHaveBeenCalledWith(semantic_convention_1.default.GEN_AI_TOOL_ARGS, '{"location":"SF"}');
|
|
372
|
+
});
|
|
373
|
+
it('should set system_fingerprint when present', async () => {
|
|
374
|
+
const mockArgs = [
|
|
375
|
+
{
|
|
376
|
+
messages: [{ role: 'user', content: 'Test' }],
|
|
377
|
+
model: 'llama-3.1-8b-instant',
|
|
378
|
+
stream: false,
|
|
379
|
+
},
|
|
380
|
+
];
|
|
381
|
+
const mockResponse = {
|
|
382
|
+
id: 'test-id',
|
|
383
|
+
model: 'llama-3.1-8b-instant',
|
|
384
|
+
system_fingerprint: 'fp_groq_test',
|
|
385
|
+
choices: [{ message: { content: 'Response' }, finish_reason: 'stop' }],
|
|
386
|
+
usage: { prompt_tokens: 5, completion_tokens: 10, total_tokens: 15 },
|
|
387
|
+
};
|
|
388
|
+
await wrapper_1.default._chatCompletion({
|
|
389
|
+
args: mockArgs,
|
|
390
|
+
genAIEndpoint: 'groq.chat.completions',
|
|
391
|
+
response: mockResponse,
|
|
392
|
+
span: mockSpan,
|
|
393
|
+
});
|
|
394
|
+
expect(mockSpan.setAttribute).toHaveBeenCalledWith(semantic_convention_1.default.GEN_AI_RESPONSE_SYSTEM_FINGERPRINT, 'fp_groq_test');
|
|
395
|
+
});
|
|
396
|
+
it('should record metrics via BaseWrapper.recordMetrics', async () => {
|
|
397
|
+
const mockArgs = [
|
|
398
|
+
{
|
|
399
|
+
messages: [{ role: 'user', content: 'Test' }],
|
|
400
|
+
model: 'llama-3.1-8b-instant',
|
|
401
|
+
stream: false,
|
|
402
|
+
},
|
|
403
|
+
];
|
|
404
|
+
const mockResponse = {
|
|
405
|
+
id: 'test',
|
|
406
|
+
model: 'llama-3.1-8b-instant',
|
|
407
|
+
choices: [{ message: { content: 'Response' }, finish_reason: 'stop' }],
|
|
408
|
+
usage: { prompt_tokens: 5, completion_tokens: 10, total_tokens: 15 },
|
|
409
|
+
};
|
|
410
|
+
await wrapper_1.default._chatCompletion({
|
|
411
|
+
args: mockArgs,
|
|
412
|
+
genAIEndpoint: 'groq.chat.completions',
|
|
413
|
+
response: mockResponse,
|
|
414
|
+
span: mockSpan,
|
|
415
|
+
});
|
|
416
|
+
expect(base_wrapper_1.default.recordMetrics).toHaveBeenCalledWith(mockSpan, expect.objectContaining({
|
|
417
|
+
genAIEndpoint: 'groq.chat.completions',
|
|
418
|
+
model: 'llama-3.1-8b-instant',
|
|
419
|
+
aiSystem: 'groq',
|
|
420
|
+
}));
|
|
421
|
+
});
|
|
422
|
+
it('should use Shield360Config.pricingInfo for cost calculation', async () => {
|
|
423
|
+
config_1.default.pricingInfo = { chat: { 'llama-3.1-8b-instant': { promptPrice: 0.05, completionPrice: 0.08 } } };
|
|
424
|
+
const mockArgs = [
|
|
425
|
+
{
|
|
426
|
+
messages: [{ role: 'user', content: 'Test' }],
|
|
427
|
+
model: 'llama-3.1-8b-instant',
|
|
428
|
+
stream: false,
|
|
429
|
+
},
|
|
430
|
+
];
|
|
431
|
+
const mockResponse = {
|
|
432
|
+
id: 'test',
|
|
433
|
+
model: 'llama-3.1-8b-instant',
|
|
434
|
+
choices: [{ message: { content: 'Response' }, finish_reason: 'stop' }],
|
|
435
|
+
usage: { prompt_tokens: 100, completion_tokens: 50, total_tokens: 150 },
|
|
436
|
+
};
|
|
437
|
+
await wrapper_1.default._chatCompletion({
|
|
438
|
+
args: mockArgs,
|
|
439
|
+
genAIEndpoint: 'groq.chat.completions',
|
|
440
|
+
response: mockResponse,
|
|
441
|
+
span: mockSpan,
|
|
442
|
+
});
|
|
443
|
+
expect(helpers_1.default.getChatModelCost).toHaveBeenCalledWith('llama-3.1-8b-instant', expect.any(Object), 100, 50, 0, 0, true);
|
|
444
|
+
});
|
|
445
|
+
});
|
|
446
|
+
describe('Streaming Chat Completion', () => {
|
|
447
|
+
it('should set streaming attributes matching Python SDK', async () => {
|
|
448
|
+
const mockArgs = [
|
|
449
|
+
{
|
|
450
|
+
messages: [{ role: 'user', content: 'Test streaming' }],
|
|
451
|
+
model: 'llama-3.1-8b-instant',
|
|
452
|
+
stream: true,
|
|
453
|
+
},
|
|
454
|
+
];
|
|
455
|
+
async function* mockStream() {
|
|
456
|
+
yield {
|
|
457
|
+
id: 'test-id',
|
|
458
|
+
created: Date.now(),
|
|
459
|
+
model: 'llama-3.1-8b-instant',
|
|
460
|
+
choices: [{ delta: { content: 'Hello' } }],
|
|
461
|
+
};
|
|
462
|
+
yield {
|
|
463
|
+
id: 'test-id',
|
|
464
|
+
created: Date.now(),
|
|
465
|
+
model: 'llama-3.1-8b-instant',
|
|
466
|
+
choices: [{ delta: { content: ' world' } }],
|
|
467
|
+
};
|
|
468
|
+
}
|
|
469
|
+
const generator = wrapper_1.default._chatCompletionGenerator({
|
|
470
|
+
args: mockArgs,
|
|
471
|
+
genAIEndpoint: 'groq.chat.completions',
|
|
472
|
+
response: mockStream(),
|
|
473
|
+
span: mockSpan,
|
|
474
|
+
});
|
|
475
|
+
for await (const _ of generator) {
|
|
476
|
+
// consume
|
|
477
|
+
}
|
|
478
|
+
expect(mockSpan.setAttribute).toHaveBeenCalledWith(semantic_convention_1.default.GEN_AI_REQUEST_IS_STREAM, true);
|
|
479
|
+
expect(mockSpan.setAttribute).toHaveBeenCalledWith(semantic_convention_1.default.GEN_AI_PROVIDER_NAME_OTEL, 'groq');
|
|
480
|
+
});
|
|
481
|
+
it('should handle x_groq usage data in streaming', async () => {
|
|
482
|
+
const mockArgs = [
|
|
483
|
+
{
|
|
484
|
+
messages: [{ role: 'user', content: 'Test' }],
|
|
485
|
+
model: 'llama-3.1-8b-instant',
|
|
486
|
+
stream: true,
|
|
487
|
+
},
|
|
488
|
+
];
|
|
489
|
+
async function* mockStream() {
|
|
490
|
+
yield {
|
|
491
|
+
id: 'test-id',
|
|
492
|
+
created: Date.now(),
|
|
493
|
+
model: 'llama-3.1-8b-instant',
|
|
494
|
+
choices: [{ delta: { content: 'Hello' } }],
|
|
495
|
+
};
|
|
496
|
+
yield {
|
|
497
|
+
id: 'test-id',
|
|
498
|
+
created: Date.now(),
|
|
499
|
+
model: 'llama-3.1-8b-instant',
|
|
500
|
+
choices: [{ delta: { content: '' }, finish_reason: 'stop' }],
|
|
501
|
+
x_groq: {
|
|
502
|
+
usage: { prompt_tokens: 15, completion_tokens: 25, total_tokens: 40 },
|
|
503
|
+
},
|
|
504
|
+
};
|
|
505
|
+
}
|
|
506
|
+
const generator = wrapper_1.default._chatCompletionGenerator({
|
|
507
|
+
args: mockArgs,
|
|
508
|
+
genAIEndpoint: 'groq.chat.completions',
|
|
509
|
+
response: mockStream(),
|
|
510
|
+
span: mockSpan,
|
|
511
|
+
});
|
|
512
|
+
for await (const _ of generator) {
|
|
513
|
+
// consume
|
|
514
|
+
}
|
|
515
|
+
expect(mockSpan.setAttribute).toHaveBeenCalledWith(semantic_convention_1.default.GEN_AI_USAGE_INPUT_TOKENS, 15);
|
|
516
|
+
expect(mockSpan.setAttribute).toHaveBeenCalledWith(semantic_convention_1.default.GEN_AI_USAGE_OUTPUT_TOKENS, 25);
|
|
517
|
+
});
|
|
518
|
+
it('should handle tool calls in streaming', async () => {
|
|
519
|
+
const mockArgs = [
|
|
520
|
+
{
|
|
521
|
+
messages: [{ role: 'user', content: 'Get the weather' }],
|
|
522
|
+
model: 'llama-3.1-8b-instant',
|
|
523
|
+
stream: true,
|
|
524
|
+
},
|
|
525
|
+
];
|
|
526
|
+
async function* mockStream() {
|
|
527
|
+
yield {
|
|
528
|
+
id: 'test-id',
|
|
529
|
+
created: Date.now(),
|
|
530
|
+
model: 'llama-3.1-8b-instant',
|
|
531
|
+
choices: [{
|
|
532
|
+
delta: {
|
|
533
|
+
tool_calls: [{
|
|
534
|
+
index: 0,
|
|
535
|
+
id: 'call_abc',
|
|
536
|
+
type: 'function',
|
|
537
|
+
function: { name: 'get_weather', arguments: '{"loc' },
|
|
538
|
+
}],
|
|
539
|
+
},
|
|
540
|
+
}],
|
|
541
|
+
};
|
|
542
|
+
yield {
|
|
543
|
+
id: 'test-id',
|
|
544
|
+
created: Date.now(),
|
|
545
|
+
model: 'llama-3.1-8b-instant',
|
|
546
|
+
choices: [{
|
|
547
|
+
delta: {
|
|
548
|
+
tool_calls: [{
|
|
549
|
+
index: 0,
|
|
550
|
+
function: { arguments: 'ation":"SF"}' },
|
|
551
|
+
}],
|
|
552
|
+
},
|
|
553
|
+
}],
|
|
554
|
+
};
|
|
555
|
+
yield {
|
|
556
|
+
id: 'test-id',
|
|
557
|
+
created: Date.now(),
|
|
558
|
+
model: 'llama-3.1-8b-instant',
|
|
559
|
+
choices: [{ delta: {}, finish_reason: 'tool_calls' }],
|
|
560
|
+
};
|
|
561
|
+
}
|
|
562
|
+
const generator = wrapper_1.default._chatCompletionGenerator({
|
|
563
|
+
args: mockArgs,
|
|
564
|
+
genAIEndpoint: 'groq.chat.completions',
|
|
565
|
+
response: mockStream(),
|
|
566
|
+
span: mockSpan,
|
|
567
|
+
});
|
|
568
|
+
for await (const _ of generator) {
|
|
569
|
+
// consume
|
|
570
|
+
}
|
|
571
|
+
expect(mockSpan.setAttribute).toHaveBeenCalledWith(semantic_convention_1.default.GEN_AI_TOOL_NAME, 'get_weather');
|
|
572
|
+
expect(mockSpan.setAttribute).toHaveBeenCalledWith(semantic_convention_1.default.GEN_AI_TOOL_CALL_ID, 'call_abc');
|
|
573
|
+
});
|
|
574
|
+
});
|
|
575
|
+
describe('Span Creation Attributes', () => {
|
|
576
|
+
it('should use aiSystem from SemanticConvention.GEN_AI_SYSTEM_GROQ', () => {
|
|
577
|
+
expect(wrapper_1.default.aiSystem).toBe(semantic_convention_1.default.GEN_AI_SYSTEM_GROQ);
|
|
578
|
+
expect(wrapper_1.default.aiSystem).toBe('groq');
|
|
579
|
+
});
|
|
580
|
+
it('should set correct server address and port', () => {
|
|
581
|
+
expect(wrapper_1.default.serverAddress).toBe('api.groq.com');
|
|
582
|
+
expect(wrapper_1.default.serverPort).toBe(443);
|
|
583
|
+
});
|
|
584
|
+
});
|
|
585
|
+
describe('GenAI semantic conventions: system_instructions + tool_definitions', () => {
|
|
586
|
+
const buildResponse = () => ({
|
|
587
|
+
id: 'sys-tools-test',
|
|
588
|
+
created: Date.now(),
|
|
589
|
+
model: 'llama-3.1-8b-instant',
|
|
590
|
+
choices: [
|
|
591
|
+
{
|
|
592
|
+
index: 0,
|
|
593
|
+
finish_reason: 'stop',
|
|
594
|
+
message: { role: 'assistant', content: 'ok' },
|
|
595
|
+
},
|
|
596
|
+
],
|
|
597
|
+
usage: { prompt_tokens: 5, completion_tokens: 5, total_tokens: 10 },
|
|
598
|
+
});
|
|
599
|
+
it('writes gen_ai.system_instructions on the span and emitted event when a system message is present', async () => {
|
|
600
|
+
const mockArgs = [
|
|
601
|
+
{
|
|
602
|
+
messages: [
|
|
603
|
+
{ role: 'system', content: 'You are a helpful assistant.' },
|
|
604
|
+
{ role: 'user', content: 'hi' },
|
|
605
|
+
],
|
|
606
|
+
model: 'llama-3.1-8b-instant',
|
|
607
|
+
stream: false,
|
|
608
|
+
},
|
|
609
|
+
];
|
|
610
|
+
await wrapper_1.default._chatCompletion({
|
|
611
|
+
args: mockArgs,
|
|
612
|
+
genAIEndpoint: 'groq.chat.completions',
|
|
613
|
+
response: buildResponse(),
|
|
614
|
+
span: mockSpan,
|
|
615
|
+
});
|
|
616
|
+
const expectedSysJson = JSON.stringify([
|
|
617
|
+
{ type: 'text', content: 'You are a helpful assistant.' },
|
|
618
|
+
]);
|
|
619
|
+
expect(mockSpan.setAttribute).toHaveBeenCalledWith(semantic_convention_1.default.GEN_AI_SYSTEM_INSTRUCTIONS, expectedSysJson);
|
|
620
|
+
const emit = helpers_1.default.emitInferenceEvent;
|
|
621
|
+
expect(emit).toHaveBeenCalled();
|
|
622
|
+
const eventAttrs = emit.mock.calls[0][1];
|
|
623
|
+
expect(eventAttrs[semantic_convention_1.default.GEN_AI_SYSTEM_INSTRUCTIONS]).toBe(expectedSysJson);
|
|
624
|
+
});
|
|
625
|
+
it('writes gen_ai.tool.definitions on the span and emitted event when tools are present', async () => {
|
|
626
|
+
const mockArgs = [
|
|
627
|
+
{
|
|
628
|
+
messages: [{ role: 'user', content: 'use a tool' }],
|
|
629
|
+
model: 'llama-3.1-8b-instant',
|
|
630
|
+
stream: false,
|
|
631
|
+
tools: [
|
|
632
|
+
{
|
|
633
|
+
type: 'function',
|
|
634
|
+
function: {
|
|
635
|
+
name: 'get_weather',
|
|
636
|
+
description: 'Get current weather',
|
|
637
|
+
parameters: { type: 'object', properties: {} },
|
|
638
|
+
},
|
|
639
|
+
},
|
|
640
|
+
],
|
|
641
|
+
},
|
|
642
|
+
];
|
|
643
|
+
await wrapper_1.default._chatCompletion({
|
|
644
|
+
args: mockArgs,
|
|
645
|
+
genAIEndpoint: 'groq.chat.completions',
|
|
646
|
+
response: buildResponse(),
|
|
647
|
+
span: mockSpan,
|
|
648
|
+
});
|
|
649
|
+
const expectedToolJson = JSON.stringify([
|
|
650
|
+
{
|
|
651
|
+
type: 'function',
|
|
652
|
+
name: 'get_weather',
|
|
653
|
+
description: 'Get current weather',
|
|
654
|
+
parameters: { type: 'object', properties: {} },
|
|
655
|
+
},
|
|
656
|
+
]);
|
|
657
|
+
expect(mockSpan.setAttribute).toHaveBeenCalledWith(semantic_convention_1.default.GEN_AI_TOOL_DEFINITIONS, expectedToolJson);
|
|
658
|
+
const emit = helpers_1.default.emitInferenceEvent;
|
|
659
|
+
expect(emit).toHaveBeenCalled();
|
|
660
|
+
const eventAttrs = emit.mock.calls[0][1];
|
|
661
|
+
expect(eventAttrs[semantic_convention_1.default.GEN_AI_TOOL_DEFINITIONS]).toBe(expectedToolJson);
|
|
662
|
+
});
|
|
663
|
+
it('omits both attributes when neither system messages nor tools are provided', async () => {
|
|
664
|
+
const mockArgs = [
|
|
665
|
+
{
|
|
666
|
+
messages: [{ role: 'user', content: 'hi' }],
|
|
667
|
+
model: 'llama-3.1-8b-instant',
|
|
668
|
+
stream: false,
|
|
669
|
+
},
|
|
670
|
+
];
|
|
671
|
+
await wrapper_1.default._chatCompletion({
|
|
672
|
+
args: mockArgs,
|
|
673
|
+
genAIEndpoint: 'groq.chat.completions',
|
|
674
|
+
response: buildResponse(),
|
|
675
|
+
span: mockSpan,
|
|
676
|
+
});
|
|
677
|
+
const setAttrKeys = mockSpan.setAttribute.mock.calls.map(([k]) => k);
|
|
678
|
+
expect(setAttrKeys).not.toContain(semantic_convention_1.default.GEN_AI_SYSTEM_INSTRUCTIONS);
|
|
679
|
+
expect(setAttrKeys).not.toContain(semantic_convention_1.default.GEN_AI_TOOL_DEFINITIONS);
|
|
680
|
+
const emit = helpers_1.default.emitInferenceEvent;
|
|
681
|
+
const eventAttrs = emit.mock.calls[0][1];
|
|
682
|
+
expect(eventAttrs[semantic_convention_1.default.GEN_AI_SYSTEM_INSTRUCTIONS]).toBeUndefined();
|
|
683
|
+
expect(eventAttrs[semantic_convention_1.default.GEN_AI_TOOL_DEFINITIONS]).toBeUndefined();
|
|
684
|
+
});
|
|
685
|
+
});
|
|
686
|
+
});
|
|
687
|
+
//# sourceMappingURL=groq-trace-comparison.test.js.map
|