@sentry/core 10.47.0 → 10.49.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/build/cjs/attributes.js +43 -0
- package/build/cjs/attributes.js.map +1 -1
- package/build/cjs/client.js +13 -6
- package/build/cjs/client.js.map +1 -1
- package/build/cjs/envelope.js +4 -3
- package/build/cjs/envelope.js.map +1 -1
- package/build/cjs/fetch.js +36 -17
- package/build/cjs/fetch.js.map +1 -1
- package/build/cjs/index.js +53 -18
- package/build/cjs/index.js.map +1 -1
- package/build/cjs/integration.js +6 -0
- package/build/cjs/integration.js.map +1 -1
- package/build/cjs/integrations/conversationId.js +11 -0
- package/build/cjs/integrations/conversationId.js.map +1 -1
- package/build/cjs/integrations/express/index.js +243 -0
- package/build/cjs/integrations/express/index.js.map +1 -0
- package/build/cjs/integrations/express/patch-layer.js +257 -0
- package/build/cjs/integrations/express/patch-layer.js.map +1 -0
- package/build/cjs/integrations/express/request-layer-store.js +25 -0
- package/build/cjs/integrations/express/request-layer-store.js.map +1 -0
- package/build/cjs/integrations/express/set-sdk-processing-metadata.js +17 -0
- package/build/cjs/integrations/express/set-sdk-processing-metadata.js.map +1 -0
- package/build/cjs/integrations/express/types.js +17 -0
- package/build/cjs/integrations/express/types.js.map +1 -0
- package/build/cjs/integrations/express/utils.js +238 -0
- package/build/cjs/integrations/express/utils.js.map +1 -0
- package/build/cjs/integrations/mcp-server/correlation.js +5 -1
- package/build/cjs/integrations/mcp-server/correlation.js.map +1 -1
- package/build/cjs/integrations/mcp-server/handlers.js +18 -10
- package/build/cjs/integrations/mcp-server/handlers.js.map +1 -1
- package/build/cjs/integrations/mcp-server/index.js +2 -1
- package/build/cjs/integrations/mcp-server/index.js.map +1 -1
- package/build/cjs/integrations/mcp-server/transport.js +1 -1
- package/build/cjs/integrations/mcp-server/transport.js.map +1 -1
- package/build/cjs/integrations/mcp-server/validation.js +7 -5
- package/build/cjs/integrations/mcp-server/validation.js.map +1 -1
- package/build/cjs/integrations/requestdata.js.map +1 -1
- package/build/cjs/integrations/spanStreaming.js +48 -0
- package/build/cjs/integrations/spanStreaming.js.map +1 -0
- package/build/cjs/semanticAttributes.js +35 -3
- package/build/cjs/semanticAttributes.js.map +1 -1
- package/build/cjs/tracing/ai/gen-ai-attributes.js +3 -89
- package/build/cjs/tracing/ai/gen-ai-attributes.js.map +1 -1
- package/build/cjs/tracing/ai/utils.js +74 -0
- package/build/cjs/tracing/ai/utils.js.map +1 -1
- package/build/cjs/tracing/anthropic-ai/index.js +6 -17
- package/build/cjs/tracing/anthropic-ai/index.js.map +1 -1
- package/build/cjs/tracing/anthropic-ai/streaming.js +2 -100
- package/build/cjs/tracing/anthropic-ai/streaming.js.map +1 -1
- package/build/cjs/tracing/anthropic-ai/utils.js +4 -2
- package/build/cjs/tracing/anthropic-ai/utils.js.map +1 -1
- package/build/cjs/tracing/dynamicSamplingContext.js +2 -1
- package/build/cjs/tracing/dynamicSamplingContext.js.map +1 -1
- package/build/cjs/tracing/google-genai/constants.js +1 -6
- package/build/cjs/tracing/google-genai/constants.js.map +1 -1
- package/build/cjs/tracing/google-genai/index.js +40 -35
- package/build/cjs/tracing/google-genai/index.js.map +1 -1
- package/build/cjs/tracing/google-genai/streaming.js +2 -23
- package/build/cjs/tracing/google-genai/streaming.js.map +1 -1
- package/build/cjs/tracing/langchain/embeddings.js +132 -0
- package/build/cjs/tracing/langchain/embeddings.js.map +1 -0
- package/build/cjs/tracing/langchain/index.js +3 -0
- package/build/cjs/tracing/langchain/index.js.map +1 -1
- package/build/cjs/tracing/langchain/utils.js +12 -4
- package/build/cjs/tracing/langchain/utils.js.map +1 -1
- package/build/cjs/tracing/langgraph/index.js +4 -3
- package/build/cjs/tracing/langgraph/index.js.map +1 -1
- package/build/cjs/tracing/openai/index.js +14 -34
- package/build/cjs/tracing/openai/index.js.map +1 -1
- package/build/cjs/tracing/openai/streaming.js +3 -34
- package/build/cjs/tracing/openai/streaming.js.map +1 -1
- package/build/cjs/tracing/openai/utils.js +78 -204
- package/build/cjs/tracing/openai/utils.js.map +1 -1
- package/build/cjs/tracing/sentryNonRecordingSpan.js +7 -0
- package/build/cjs/tracing/sentryNonRecordingSpan.js.map +1 -1
- package/build/cjs/tracing/sentrySpan.js +39 -0
- package/build/cjs/tracing/sentrySpan.js.map +1 -1
- package/build/cjs/tracing/spans/beforeSendSpan.js +43 -0
- package/build/cjs/tracing/spans/beforeSendSpan.js.map +1 -0
- package/build/cjs/tracing/spans/captureSpan.js +126 -0
- package/build/cjs/tracing/spans/captureSpan.js.map +1 -0
- package/build/cjs/tracing/spans/envelope.js +38 -0
- package/build/cjs/tracing/spans/envelope.js.map +1 -0
- package/build/cjs/tracing/spans/estimateSize.js +41 -0
- package/build/cjs/tracing/spans/estimateSize.js.map +1 -0
- package/build/cjs/tracing/spans/hasSpanStreamingEnabled.js +11 -0
- package/build/cjs/tracing/spans/hasSpanStreamingEnabled.js.map +1 -0
- package/build/cjs/tracing/spans/spanBuffer.js +158 -0
- package/build/cjs/tracing/spans/spanBuffer.js.map +1 -0
- package/build/cjs/tracing/trace.js +83 -13
- package/build/cjs/tracing/trace.js.map +1 -1
- package/build/cjs/tracing/utils.js +3 -37
- package/build/cjs/tracing/utils.js.map +1 -1
- package/build/cjs/tracing/vercel-ai/constants.js +15 -23
- package/build/cjs/tracing/vercel-ai/constants.js.map +1 -1
- package/build/cjs/tracing/vercel-ai/index.js +32 -45
- package/build/cjs/tracing/vercel-ai/index.js.map +1 -1
- package/build/cjs/tracing/vercel-ai/utils.js +11 -42
- package/build/cjs/tracing/vercel-ai/utils.js.map +1 -1
- package/build/cjs/tracing/vercel-ai/vercel-ai-attributes.js +4 -1
- package/build/cjs/tracing/vercel-ai/vercel-ai-attributes.js.map +1 -1
- package/build/cjs/utils/browser.js +2 -3
- package/build/cjs/utils/browser.js.map +1 -1
- package/build/cjs/utils/featureFlags.js +6 -0
- package/build/cjs/utils/featureFlags.js.map +1 -1
- package/build/cjs/utils/object.js +33 -0
- package/build/cjs/utils/object.js.map +1 -1
- package/build/cjs/utils/spanUtils.js +116 -13
- package/build/cjs/utils/spanUtils.js.map +1 -1
- package/build/cjs/utils/stacktrace.js +3 -1
- package/build/cjs/utils/stacktrace.js.map +1 -1
- package/build/cjs/utils/string.js +3 -0
- package/build/cjs/utils/string.js.map +1 -1
- package/build/cjs/utils/version.js +1 -1
- package/build/cjs/utils/weakRef.js +62 -0
- package/build/cjs/utils/weakRef.js.map +1 -0
- package/build/esm/attributes.js +43 -1
- package/build/esm/attributes.js.map +1 -1
- package/build/esm/client.js +8 -1
- package/build/esm/client.js.map +1 -1
- package/build/esm/envelope.js +2 -1
- package/build/esm/envelope.js.map +1 -1
- package/build/esm/fetch.js +36 -17
- package/build/esm/fetch.js.map +1 -1
- package/build/esm/index.js +12 -3
- package/build/esm/index.js.map +1 -1
- package/build/esm/integration.js +6 -0
- package/build/esm/integration.js.map +1 -1
- package/build/esm/integrations/conversationId.js +11 -0
- package/build/esm/integrations/conversationId.js.map +1 -1
- package/build/esm/integrations/express/index.js +239 -0
- package/build/esm/integrations/express/index.js.map +1 -0
- package/build/esm/integrations/express/patch-layer.js +255 -0
- package/build/esm/integrations/express/patch-layer.js.map +1 -0
- package/build/esm/integrations/express/request-layer-store.js +22 -0
- package/build/esm/integrations/express/request-layer-store.js.map +1 -0
- package/build/esm/integrations/express/set-sdk-processing-metadata.js +15 -0
- package/build/esm/integrations/express/set-sdk-processing-metadata.js.map +1 -0
- package/build/esm/integrations/express/types.js +10 -0
- package/build/esm/integrations/express/types.js.map +1 -0
- package/build/esm/integrations/express/utils.js +225 -0
- package/build/esm/integrations/express/utils.js.map +1 -0
- package/build/esm/integrations/mcp-server/correlation.js +5 -1
- package/build/esm/integrations/mcp-server/correlation.js.map +1 -1
- package/build/esm/integrations/mcp-server/handlers.js +18 -10
- package/build/esm/integrations/mcp-server/handlers.js.map +1 -1
- package/build/esm/integrations/mcp-server/index.js +2 -1
- package/build/esm/integrations/mcp-server/index.js.map +1 -1
- package/build/esm/integrations/mcp-server/transport.js +1 -1
- package/build/esm/integrations/mcp-server/transport.js.map +1 -1
- package/build/esm/integrations/mcp-server/validation.js +7 -5
- package/build/esm/integrations/mcp-server/validation.js.map +1 -1
- package/build/esm/integrations/requestdata.js.map +1 -1
- package/build/esm/integrations/spanStreaming.js +46 -0
- package/build/esm/integrations/spanStreaming.js.map +1 -0
- package/build/esm/package.json +1 -1
- package/build/esm/semanticAttributes.js +26 -4
- package/build/esm/semanticAttributes.js.map +1 -1
- package/build/esm/tracing/ai/gen-ai-attributes.js +3 -76
- package/build/esm/tracing/ai/gen-ai-attributes.js.map +1 -1
- package/build/esm/tracing/ai/utils.js +73 -2
- package/build/esm/tracing/ai/utils.js.map +1 -1
- package/build/esm/tracing/anthropic-ai/index.js +8 -19
- package/build/esm/tracing/anthropic-ai/index.js.map +1 -1
- package/build/esm/tracing/anthropic-ai/streaming.js +3 -101
- package/build/esm/tracing/anthropic-ai/streaming.js.map +1 -1
- package/build/esm/tracing/anthropic-ai/utils.js +5 -3
- package/build/esm/tracing/anthropic-ai/utils.js.map +1 -1
- package/build/esm/tracing/dynamicSamplingContext.js +2 -1
- package/build/esm/tracing/dynamicSamplingContext.js.map +1 -1
- package/build/esm/tracing/google-genai/constants.js +2 -5
- package/build/esm/tracing/google-genai/constants.js.map +1 -1
- package/build/esm/tracing/google-genai/index.js +42 -37
- package/build/esm/tracing/google-genai/index.js.map +1 -1
- package/build/esm/tracing/google-genai/streaming.js +2 -23
- package/build/esm/tracing/google-genai/streaming.js.map +1 -1
- package/build/esm/tracing/langchain/embeddings.js +129 -0
- package/build/esm/tracing/langchain/embeddings.js.map +1 -0
- package/build/esm/tracing/langchain/index.js +4 -1
- package/build/esm/tracing/langchain/index.js.map +1 -1
- package/build/esm/tracing/langchain/utils.js +13 -5
- package/build/esm/tracing/langchain/utils.js.map +1 -1
- package/build/esm/tracing/langgraph/index.js +5 -4
- package/build/esm/tracing/langgraph/index.js.map +1 -1
- package/build/esm/tracing/openai/index.js +16 -36
- package/build/esm/tracing/openai/index.js.map +1 -1
- package/build/esm/tracing/openai/streaming.js +4 -35
- package/build/esm/tracing/openai/streaming.js.map +1 -1
- package/build/esm/tracing/openai/utils.js +79 -196
- package/build/esm/tracing/openai/utils.js.map +1 -1
- package/build/esm/tracing/sentryNonRecordingSpan.js +7 -0
- package/build/esm/tracing/sentryNonRecordingSpan.js.map +1 -1
- package/build/esm/tracing/sentrySpan.js +40 -1
- package/build/esm/tracing/sentrySpan.js.map +1 -1
- package/build/esm/tracing/spans/beforeSendSpan.js +40 -0
- package/build/esm/tracing/spans/beforeSendSpan.js.map +1 -0
- package/build/esm/tracing/spans/captureSpan.js +122 -0
- package/build/esm/tracing/spans/captureSpan.js.map +1 -0
- package/build/esm/tracing/spans/envelope.js +36 -0
- package/build/esm/tracing/spans/envelope.js.map +1 -0
- package/build/esm/tracing/spans/estimateSize.js +39 -0
- package/build/esm/tracing/spans/estimateSize.js.map +1 -0
- package/build/esm/tracing/spans/hasSpanStreamingEnabled.js +9 -0
- package/build/esm/tracing/spans/hasSpanStreamingEnabled.js.map +1 -0
- package/build/esm/tracing/spans/spanBuffer.js +156 -0
- package/build/esm/tracing/spans/spanBuffer.js.map +1 -0
- package/build/esm/tracing/trace.js +84 -14
- package/build/esm/tracing/trace.js.map +1 -1
- package/build/esm/tracing/utils.js +3 -37
- package/build/esm/tracing/utils.js.map +1 -1
- package/build/esm/tracing/vercel-ai/constants.js +15 -19
- package/build/esm/tracing/vercel-ai/constants.js.map +1 -1
- package/build/esm/tracing/vercel-ai/index.js +29 -42
- package/build/esm/tracing/vercel-ai/index.js.map +1 -1
- package/build/esm/tracing/vercel-ai/utils.js +14 -44
- package/build/esm/tracing/vercel-ai/utils.js.map +1 -1
- package/build/esm/tracing/vercel-ai/vercel-ai-attributes.js +4 -1
- package/build/esm/tracing/vercel-ai/vercel-ai-attributes.js.map +1 -1
- package/build/esm/utils/browser.js +2 -3
- package/build/esm/utils/browser.js.map +1 -1
- package/build/esm/utils/featureFlags.js +6 -0
- package/build/esm/utils/featureFlags.js.map +1 -1
- package/build/esm/utils/object.js +33 -1
- package/build/esm/utils/object.js.map +1 -1
- package/build/esm/utils/spanUtils.js +112 -14
- package/build/esm/utils/spanUtils.js.map +1 -1
- package/build/esm/utils/stacktrace.js +3 -1
- package/build/esm/utils/stacktrace.js.map +1 -1
- package/build/esm/utils/string.js +3 -0
- package/build/esm/utils/string.js.map +1 -1
- package/build/esm/utils/version.js +1 -1
- package/build/esm/utils/weakRef.js +59 -0
- package/build/esm/utils/weakRef.js.map +1 -0
- package/build/types/attributes.d.ts +5 -0
- package/build/types/attributes.d.ts.map +1 -1
- package/build/types/build-time-plugins/buildTimeOptionsBase.d.ts +13 -0
- package/build/types/build-time-plugins/buildTimeOptionsBase.d.ts.map +1 -1
- package/build/types/client.d.ts +35 -1
- package/build/types/client.d.ts.map +1 -1
- package/build/types/envelope.d.ts.map +1 -1
- package/build/types/fetch.d.ts +12 -8
- package/build/types/fetch.d.ts.map +1 -1
- package/build/types/index.d.ts +16 -5
- package/build/types/index.d.ts.map +1 -1
- package/build/types/integration.d.ts.map +1 -1
- package/build/types/integrations/conversationId.d.ts.map +1 -1
- package/build/types/integrations/express/index.d.ts +82 -0
- package/build/types/integrations/express/index.d.ts.map +1 -0
- package/build/types/integrations/express/patch-layer.d.ts +32 -0
- package/build/types/integrations/express/patch-layer.d.ts.map +1 -0
- package/build/types/integrations/express/request-layer-store.d.ts +32 -0
- package/build/types/integrations/express/request-layer-store.d.ts.map +1 -0
- package/build/types/integrations/express/set-sdk-processing-metadata.d.ts +35 -0
- package/build/types/integrations/express/set-sdk-processing-metadata.d.ts.map +1 -0
- package/build/types/integrations/express/types.d.ts +158 -0
- package/build/types/integrations/express/types.d.ts.map +1 -0
- package/build/types/integrations/express/utils.d.ts +93 -0
- package/build/types/integrations/express/utils.d.ts.map +1 -0
- package/build/types/integrations/mcp-server/correlation.d.ts +2 -1
- package/build/types/integrations/mcp-server/correlation.d.ts.map +1 -1
- package/build/types/integrations/mcp-server/handlers.d.ts +9 -4
- package/build/types/integrations/mcp-server/handlers.d.ts.map +1 -1
- package/build/types/integrations/mcp-server/index.d.ts +2 -1
- package/build/types/integrations/mcp-server/index.d.ts.map +1 -1
- package/build/types/integrations/mcp-server/types.d.ts +40 -7
- package/build/types/integrations/mcp-server/types.d.ts.map +1 -1
- package/build/types/integrations/mcp-server/validation.d.ts +4 -1
- package/build/types/integrations/mcp-server/validation.d.ts.map +1 -1
- package/build/types/integrations/requestdata.d.ts.map +1 -1
- package/build/types/integrations/spanStreaming.d.ts +2 -0
- package/build/types/integrations/spanStreaming.d.ts.map +1 -0
- package/build/types/semanticAttributes.d.ts +23 -3
- package/build/types/semanticAttributes.d.ts.map +1 -1
- package/build/types/tracing/ai/gen-ai-attributes.d.ts +4 -44
- package/build/types/tracing/ai/gen-ai-attributes.d.ts.map +1 -1
- package/build/types/tracing/ai/utils.d.ts +32 -2
- package/build/types/tracing/ai/utils.d.ts.map +1 -1
- package/build/types/tracing/anthropic-ai/index.d.ts.map +1 -1
- package/build/types/tracing/anthropic-ai/streaming.d.ts.map +1 -1
- package/build/types/tracing/anthropic-ai/types.d.ts +5 -0
- package/build/types/tracing/anthropic-ai/types.d.ts.map +1 -1
- package/build/types/tracing/anthropic-ai/utils.d.ts +1 -1
- package/build/types/tracing/anthropic-ai/utils.d.ts.map +1 -1
- package/build/types/tracing/dynamicSamplingContext.d.ts.map +1 -1
- package/build/types/tracing/google-genai/constants.d.ts +1 -3
- package/build/types/tracing/google-genai/constants.d.ts.map +1 -1
- package/build/types/tracing/google-genai/index.d.ts.map +1 -1
- package/build/types/tracing/google-genai/streaming.d.ts.map +1 -1
- package/build/types/tracing/google-genai/types.d.ts +5 -0
- package/build/types/tracing/google-genai/types.d.ts.map +1 -1
- package/build/types/tracing/index.d.ts +1 -0
- package/build/types/tracing/index.d.ts.map +1 -1
- package/build/types/tracing/langchain/embeddings.d.ts +27 -0
- package/build/types/tracing/langchain/embeddings.d.ts.map +1 -0
- package/build/types/tracing/langchain/index.d.ts +1 -0
- package/build/types/tracing/langchain/index.d.ts.map +1 -1
- package/build/types/tracing/langchain/types.d.ts +5 -0
- package/build/types/tracing/langchain/types.d.ts.map +1 -1
- package/build/types/tracing/langchain/utils.d.ts +2 -2
- package/build/types/tracing/langchain/utils.d.ts.map +1 -1
- package/build/types/tracing/langgraph/index.d.ts.map +1 -1
- package/build/types/tracing/langgraph/types.d.ts +5 -0
- package/build/types/tracing/langgraph/types.d.ts.map +1 -1
- package/build/types/tracing/openai/index.d.ts.map +1 -1
- package/build/types/tracing/openai/streaming.d.ts.map +1 -1
- package/build/types/tracing/openai/types.d.ts +5 -0
- package/build/types/tracing/openai/types.d.ts.map +1 -1
- package/build/types/tracing/openai/utils.d.ts +4 -49
- package/build/types/tracing/openai/utils.d.ts.map +1 -1
- package/build/types/tracing/sentryNonRecordingSpan.d.ts +12 -1
- package/build/types/tracing/sentryNonRecordingSpan.d.ts.map +1 -1
- package/build/types/tracing/sentrySpan.d.ts +10 -1
- package/build/types/tracing/sentrySpan.d.ts.map +1 -1
- package/build/types/tracing/spans/beforeSendSpan.d.ts +35 -0
- package/build/types/tracing/spans/beforeSendSpan.d.ts.map +1 -0
- package/build/types/tracing/spans/captureSpan.d.ts +26 -0
- package/build/types/tracing/spans/captureSpan.d.ts.map +1 -0
- package/build/types/tracing/spans/envelope.d.ts +8 -0
- package/build/types/tracing/spans/envelope.d.ts.map +1 -0
- package/build/types/tracing/spans/estimateSize.d.ts +12 -0
- package/build/types/tracing/spans/estimateSize.d.ts.map +1 -0
- package/build/types/tracing/spans/hasSpanStreamingEnabled.d.ts +6 -0
- package/build/types/tracing/spans/hasSpanStreamingEnabled.d.ts.map +1 -0
- package/build/types/tracing/spans/spanBuffer.d.ts +60 -0
- package/build/types/tracing/spans/spanBuffer.d.ts.map +1 -0
- package/build/types/tracing/trace.d.ts.map +1 -1
- package/build/types/tracing/utils.d.ts.map +1 -1
- package/build/types/tracing/vercel-ai/constants.d.ts +2 -5
- package/build/types/tracing/vercel-ai/constants.d.ts.map +1 -1
- package/build/types/tracing/vercel-ai/index.d.ts.map +1 -1
- package/build/types/tracing/vercel-ai/utils.d.ts +1 -5
- package/build/types/tracing/vercel-ai/utils.d.ts.map +1 -1
- package/build/types/tracing/vercel-ai/vercel-ai-attributes.d.ts +0 -480
- package/build/types/tracing/vercel-ai/vercel-ai-attributes.d.ts.map +1 -1
- package/build/types/types-hoist/envelope.d.ts +22 -2
- package/build/types/types-hoist/envelope.d.ts.map +1 -1
- package/build/types/types-hoist/integration.d.ts +8 -0
- package/build/types/types-hoist/integration.d.ts.map +1 -1
- package/build/types/types-hoist/link.d.ts +2 -2
- package/build/types/types-hoist/link.d.ts.map +1 -1
- package/build/types/types-hoist/options.d.ts +26 -2
- package/build/types/types-hoist/options.d.ts.map +1 -1
- package/build/types/types-hoist/span.d.ts +35 -0
- package/build/types/types-hoist/span.d.ts.map +1 -1
- package/build/types/types-hoist/view-hierarchy.d.ts +1 -0
- package/build/types/types-hoist/view-hierarchy.d.ts.map +1 -1
- package/build/types/utils/browser.d.ts +1 -1
- package/build/types/utils/browser.d.ts.map +1 -1
- package/build/types/utils/featureFlags.d.ts.map +1 -1
- package/build/types/utils/object.d.ts +10 -0
- package/build/types/utils/object.d.ts.map +1 -1
- package/build/types/utils/spanUtils.d.ts +27 -2
- package/build/types/utils/spanUtils.d.ts.map +1 -1
- package/build/types/utils/stacktrace.d.ts.map +1 -1
- package/build/types/utils/string.d.ts +2 -2
- package/build/types/utils/string.d.ts.map +1 -1
- package/build/types/utils/weakRef.d.ts +34 -0
- package/build/types/utils/weakRef.d.ts.map +1 -0
- package/build/types-ts3.8/attributes.d.ts +5 -0
- package/build/types-ts3.8/build-time-plugins/buildTimeOptionsBase.d.ts +13 -0
- package/build/types-ts3.8/client.d.ts +35 -1
- package/build/types-ts3.8/fetch.d.ts +14 -10
- package/build/types-ts3.8/index.d.ts +16 -5
- package/build/types-ts3.8/integrations/express/index.d.ts +82 -0
- package/build/types-ts3.8/integrations/express/patch-layer.d.ts +32 -0
- package/build/types-ts3.8/integrations/express/request-layer-store.d.ts +32 -0
- package/build/types-ts3.8/integrations/express/set-sdk-processing-metadata.d.ts +35 -0
- package/build/types-ts3.8/integrations/express/types.d.ts +158 -0
- package/build/types-ts3.8/integrations/express/utils.d.ts +96 -0
- package/build/types-ts3.8/integrations/mcp-server/correlation.d.ts +2 -1
- package/build/types-ts3.8/integrations/mcp-server/handlers.d.ts +9 -4
- package/build/types-ts3.8/integrations/mcp-server/index.d.ts +2 -1
- package/build/types-ts3.8/integrations/mcp-server/types.d.ts +40 -7
- package/build/types-ts3.8/integrations/mcp-server/validation.d.ts +4 -1
- package/build/types-ts3.8/integrations/spanStreaming.d.ts +2 -0
- package/build/types-ts3.8/semanticAttributes.d.ts +23 -3
- package/build/types-ts3.8/tracing/ai/gen-ai-attributes.d.ts +4 -44
- package/build/types-ts3.8/tracing/ai/utils.d.ts +32 -2
- package/build/types-ts3.8/tracing/anthropic-ai/types.d.ts +5 -0
- package/build/types-ts3.8/tracing/anthropic-ai/utils.d.ts +1 -1
- package/build/types-ts3.8/tracing/google-genai/constants.d.ts +1 -3
- package/build/types-ts3.8/tracing/google-genai/types.d.ts +5 -0
- package/build/types-ts3.8/tracing/index.d.ts +1 -0
- package/build/types-ts3.8/tracing/langchain/embeddings.d.ts +27 -0
- package/build/types-ts3.8/tracing/langchain/index.d.ts +1 -0
- package/build/types-ts3.8/tracing/langchain/types.d.ts +5 -0
- package/build/types-ts3.8/tracing/langchain/utils.d.ts +2 -2
- package/build/types-ts3.8/tracing/langgraph/types.d.ts +5 -0
- package/build/types-ts3.8/tracing/openai/types.d.ts +5 -0
- package/build/types-ts3.8/tracing/openai/utils.d.ts +4 -49
- package/build/types-ts3.8/tracing/sentryNonRecordingSpan.d.ts +12 -1
- package/build/types-ts3.8/tracing/sentrySpan.d.ts +10 -1
- package/build/types-ts3.8/tracing/spans/beforeSendSpan.d.ts +35 -0
- package/build/types-ts3.8/tracing/spans/captureSpan.d.ts +26 -0
- package/build/types-ts3.8/tracing/spans/envelope.d.ts +8 -0
- package/build/types-ts3.8/tracing/spans/estimateSize.d.ts +12 -0
- package/build/types-ts3.8/tracing/spans/hasSpanStreamingEnabled.d.ts +6 -0
- package/build/types-ts3.8/tracing/spans/spanBuffer.d.ts +60 -0
- package/build/types-ts3.8/tracing/vercel-ai/constants.d.ts +2 -5
- package/build/types-ts3.8/tracing/vercel-ai/utils.d.ts +1 -5
- package/build/types-ts3.8/tracing/vercel-ai/vercel-ai-attributes.d.ts +0 -480
- package/build/types-ts3.8/types-hoist/envelope.d.ts +22 -2
- package/build/types-ts3.8/types-hoist/integration.d.ts +8 -0
- package/build/types-ts3.8/types-hoist/link.d.ts +2 -2
- package/build/types-ts3.8/types-hoist/options.d.ts +26 -2
- package/build/types-ts3.8/types-hoist/span.d.ts +35 -0
- package/build/types-ts3.8/types-hoist/view-hierarchy.d.ts +1 -0
- package/build/types-ts3.8/utils/browser.d.ts +1 -1
- package/build/types-ts3.8/utils/object.d.ts +10 -0
- package/build/types-ts3.8/utils/spanUtils.d.ts +27 -2
- package/build/types-ts3.8/utils/string.d.ts +2 -2
- package/build/types-ts3.8/utils/weakRef.d.ts +34 -0
- package/package.json +1 -1
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
3
3
|
const currentScopes = require('../currentScopes.js');
|
|
4
4
|
const integration = require('../integration.js');
|
|
5
5
|
const semanticAttributes = require('../semanticAttributes.js');
|
|
6
|
+
const spanUtils = require('../utils/spanUtils.js');
|
|
6
7
|
|
|
7
8
|
const INTEGRATION_NAME = 'ConversationId';
|
|
8
9
|
|
|
@@ -17,6 +18,16 @@ const _conversationIdIntegration = (() => {
|
|
|
17
18
|
const conversationId = scopeData.conversationId || isolationScopeData.conversationId;
|
|
18
19
|
|
|
19
20
|
if (conversationId) {
|
|
21
|
+
const { op, data: attributes, description: name } = spanUtils.spanToJSON(span);
|
|
22
|
+
|
|
23
|
+
// Only apply conversation ID to gen_ai spans.
|
|
24
|
+
// We also check for Vercel AI spans (ai.operationId attribute or ai.* span name)
|
|
25
|
+
// because the Vercel AI integration sets the gen_ai.* op in its own spanStart handler
|
|
26
|
+
// which fires after this, so the op is not yet available at this point.
|
|
27
|
+
if (!op?.startsWith('gen_ai.') && !attributes['ai.operationId'] && !name?.startsWith('ai.')) {
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
|
|
20
31
|
span.setAttribute(semanticAttributes.GEN_AI_CONVERSATION_ID_ATTRIBUTE, conversationId);
|
|
21
32
|
}
|
|
22
33
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"conversationId.js","sources":["../../../src/integrations/conversationId.ts"],"sourcesContent":["import type { Client } from '../client';\nimport { getCurrentScope, getIsolationScope } from '../currentScopes';\nimport { defineIntegration } from '../integration';\nimport { GEN_AI_CONVERSATION_ID_ATTRIBUTE } from '../semanticAttributes';\nimport type { IntegrationFn } from '../types-hoist/integration';\nimport type { Span } from '../types-hoist/span';\n\nconst INTEGRATION_NAME = 'ConversationId';\n\nconst _conversationIdIntegration = (() => {\n return {\n name: INTEGRATION_NAME,\n setup(client: Client) {\n client.on('spanStart', (span: Span) => {\n const scopeData = getCurrentScope().getScopeData();\n const isolationScopeData = getIsolationScope().getScopeData();\n\n const conversationId = scopeData.conversationId || isolationScopeData.conversationId;\n\n if (conversationId) {\n span.setAttribute(GEN_AI_CONVERSATION_ID_ATTRIBUTE, conversationId);\n }\n });\n },\n };\n}) satisfies IntegrationFn;\n\n/**\n * Automatically applies conversation ID from scope to spans.\n *\n * This integration reads the conversation ID from the current or isolation scope\n * and applies it to spans when they start. This ensures the conversation ID is\n * available for all AI-related operations.\n */\nexport const conversationIdIntegration = defineIntegration(_conversationIdIntegration);\n"],"names":["getCurrentScope","getIsolationScope","GEN_AI_CONVERSATION_ID_ATTRIBUTE","defineIntegration"],"mappings":"
|
|
1
|
+
{"version":3,"file":"conversationId.js","sources":["../../../src/integrations/conversationId.ts"],"sourcesContent":["import type { Client } from '../client';\nimport { getCurrentScope, getIsolationScope } from '../currentScopes';\nimport { defineIntegration } from '../integration';\nimport { GEN_AI_CONVERSATION_ID_ATTRIBUTE } from '../semanticAttributes';\nimport type { IntegrationFn } from '../types-hoist/integration';\nimport type { Span } from '../types-hoist/span';\nimport { spanToJSON } from '../utils/spanUtils';\n\nconst INTEGRATION_NAME = 'ConversationId';\n\nconst _conversationIdIntegration = (() => {\n return {\n name: INTEGRATION_NAME,\n setup(client: Client) {\n client.on('spanStart', (span: Span) => {\n const scopeData = getCurrentScope().getScopeData();\n const isolationScopeData = getIsolationScope().getScopeData();\n\n const conversationId = scopeData.conversationId || isolationScopeData.conversationId;\n\n if (conversationId) {\n const { op, data: attributes, description: name } = spanToJSON(span);\n\n // Only apply conversation ID to gen_ai spans.\n // We also check for Vercel AI spans (ai.operationId attribute or ai.* span name)\n // because the Vercel AI integration sets the gen_ai.* op in its own spanStart handler\n // which fires after this, so the op is not yet available at this point.\n if (!op?.startsWith('gen_ai.') && !attributes['ai.operationId'] && !name?.startsWith('ai.')) {\n return;\n }\n\n span.setAttribute(GEN_AI_CONVERSATION_ID_ATTRIBUTE, conversationId);\n }\n });\n },\n };\n}) satisfies IntegrationFn;\n\n/**\n * Automatically applies conversation ID from scope to spans.\n *\n * This integration reads the conversation ID from the current or isolation scope\n * and applies it to spans when they start. This ensures the conversation ID is\n * available for all AI-related operations.\n */\nexport const conversationIdIntegration = defineIntegration(_conversationIdIntegration);\n"],"names":["getCurrentScope","getIsolationScope","spanToJSON","GEN_AI_CONVERSATION_ID_ATTRIBUTE","defineIntegration"],"mappings":";;;;;;;AAQA,MAAM,gBAAA,GAAmB,gBAAgB;;AAEzC,MAAM,0BAAA,IAA8B,MAAM;AAC1C,EAAE,OAAO;AACT,IAAI,IAAI,EAAE,gBAAgB;AAC1B,IAAI,KAAK,CAAC,MAAM,EAAU;AAC1B,MAAM,MAAM,CAAC,EAAE,CAAC,WAAW,EAAE,CAAC,IAAI,KAAW;AAC7C,QAAQ,MAAM,YAAYA,6BAAe,EAAE,CAAC,YAAY,EAAE;AAC1D,QAAQ,MAAM,qBAAqBC,+BAAiB,EAAE,CAAC,YAAY,EAAE;;AAErE,QAAQ,MAAM,iBAAiB,SAAS,CAAC,cAAA,IAAkB,kBAAkB,CAAC,cAAc;;AAE5F,QAAQ,IAAI,cAAc,EAAE;AAC5B,UAAU,MAAM,EAAE,EAAE,EAAE,IAAI,EAAE,UAAU,EAAE,WAAW,EAAE,MAAK,GAAIC,oBAAU,CAAC,IAAI,CAAC;;AAE9E;AACA;AACA;AACA;AACA,UAAU,IAAI,CAAC,EAAE,EAAE,UAAU,CAAC,SAAS,CAAA,IAAK,CAAC,UAAU,CAAC,gBAAgB,CAAA,IAAK,CAAC,IAAI,EAAE,UAAU,CAAC,KAAK,CAAC,EAAE;AACvG,YAAY;AACZ,UAAU;;AAEV,UAAU,IAAI,CAAC,YAAY,CAACC,mDAAgC,EAAE,cAAc,CAAC;AAC7E,QAAQ;AACR,MAAM,CAAC,CAAC;AACR,IAAI,CAAC;AACL,GAAG;AACH,CAAC,CAAA;;AAED;AACA;AACA;AACA;AACA;AACA;AACA;MACa,yBAAA,GAA4BC,6BAAiB,CAAC,0BAA0B;;;;"}
|
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
|
|
3
|
+
const debugLogger = require('../../utils/debug-logger.js');
|
|
4
|
+
const _exports = require('../../exports.js');
|
|
5
|
+
const debugBuild = require('../../debug-build.js');
|
|
6
|
+
const utils = require('./utils.js');
|
|
7
|
+
const object = require('../../utils/object.js');
|
|
8
|
+
const patchLayer = require('./patch-layer.js');
|
|
9
|
+
const setSdkProcessingMetadata = require('./set-sdk-processing-metadata.js');
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Platform-portable Express tracing integration.
|
|
13
|
+
*
|
|
14
|
+
* @module
|
|
15
|
+
*
|
|
16
|
+
* This Sentry integration is a derivative work based on the OpenTelemetry
|
|
17
|
+
* Express instrumentation.
|
|
18
|
+
*
|
|
19
|
+
* <https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/packages/instrumentation-express>
|
|
20
|
+
*
|
|
21
|
+
* Extended under the terms of the Apache 2.0 license linked below:
|
|
22
|
+
*
|
|
23
|
+
* ----
|
|
24
|
+
*
|
|
25
|
+
* Copyright The OpenTelemetry Authors
|
|
26
|
+
*
|
|
27
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
28
|
+
* you may not use this file except in compliance with the License.
|
|
29
|
+
* You may obtain a copy of the License at
|
|
30
|
+
*
|
|
31
|
+
* https://www.apache.org/licenses/LICENSE-2.0
|
|
32
|
+
*
|
|
33
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
34
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
35
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
36
|
+
* See the License for the specific language governing permissions and
|
|
37
|
+
* limitations under the License.
|
|
38
|
+
*/
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
const getExpressExport = (express) =>
|
|
42
|
+
utils.hasDefaultProp(express) ? express.default : (express );
|
|
43
|
+
|
|
44
|
+
function isLegacyOptions(
|
|
45
|
+
options,
|
|
46
|
+
) {
|
|
47
|
+
return !!(options ).express;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// TODO: remove this deprecation handling in v11
|
|
51
|
+
let didLegacyDeprecationWarning = false;
|
|
52
|
+
function deprecationWarning() {
|
|
53
|
+
if (!didLegacyDeprecationWarning) {
|
|
54
|
+
didLegacyDeprecationWarning = true;
|
|
55
|
+
debugBuild.DEBUG_BUILD &&
|
|
56
|
+
debugLogger.debug.warn(
|
|
57
|
+
'[Express] `patchExpressModule(options)` is deprecated. Use `patchExpressModule(moduleExports, getOptions)` instead.',
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* This is a portable instrumentatiton function that works in any environment
|
|
64
|
+
* where Express can be loaded, without depending on OpenTelemetry.
|
|
65
|
+
*
|
|
66
|
+
* @example
|
|
67
|
+
* ```javascript
|
|
68
|
+
* import express from 'express';
|
|
69
|
+
* import * as Sentry from '@sentry/deno'; // or any SDK that extends core
|
|
70
|
+
*
|
|
71
|
+
* Sentry.patchExpressModule(express, () => ({}));
|
|
72
|
+
* ```
|
|
73
|
+
*/
|
|
74
|
+
|
|
75
|
+
function patchExpressModule(
|
|
76
|
+
optionsOrExports,
|
|
77
|
+
maybeGetOptions,
|
|
78
|
+
) {
|
|
79
|
+
let getOptions;
|
|
80
|
+
let moduleExports;
|
|
81
|
+
if (!maybeGetOptions && isLegacyOptions(optionsOrExports)) {
|
|
82
|
+
const { express, ...options } = optionsOrExports;
|
|
83
|
+
moduleExports = express;
|
|
84
|
+
getOptions = () => options;
|
|
85
|
+
deprecationWarning();
|
|
86
|
+
} else if (typeof maybeGetOptions !== 'function') {
|
|
87
|
+
throw new TypeError('`patchExpressModule(moduleExports, getOptions)` requires a `getOptions` callback');
|
|
88
|
+
} else {
|
|
89
|
+
getOptions = maybeGetOptions;
|
|
90
|
+
moduleExports = optionsOrExports ;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// pass in the require() or import() result of express
|
|
94
|
+
const express = getExpressExport(moduleExports);
|
|
95
|
+
const routerProto = utils.isExpressWithRouterPrototype(express)
|
|
96
|
+
? express.Router.prototype // Express v5
|
|
97
|
+
: utils.isExpressWithoutRouterPrototype(express)
|
|
98
|
+
? express.Router // Express v4
|
|
99
|
+
: undefined;
|
|
100
|
+
|
|
101
|
+
if (!routerProto) {
|
|
102
|
+
throw new TypeError('no valid Express route function to instrument');
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// oxlint-disable-next-line @typescript-eslint/unbound-method
|
|
106
|
+
const originalRouteMethod = routerProto.route;
|
|
107
|
+
try {
|
|
108
|
+
object.wrapMethod(
|
|
109
|
+
routerProto,
|
|
110
|
+
'route',
|
|
111
|
+
function routeTrace( ...args) {
|
|
112
|
+
const route = originalRouteMethod.apply(this, args);
|
|
113
|
+
const layer = this.stack[this.stack.length - 1] ;
|
|
114
|
+
patchLayer.patchLayer(getOptions, layer, utils.getLayerPath(args));
|
|
115
|
+
return route;
|
|
116
|
+
},
|
|
117
|
+
);
|
|
118
|
+
} catch (e) {
|
|
119
|
+
debugBuild.DEBUG_BUILD && debugLogger.debug.error('Failed to patch express route method:', e);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
// oxlint-disable-next-line @typescript-eslint/unbound-method
|
|
123
|
+
const originalRouterUse = routerProto.use;
|
|
124
|
+
try {
|
|
125
|
+
object.wrapMethod(
|
|
126
|
+
routerProto,
|
|
127
|
+
'use',
|
|
128
|
+
function useTrace( ...args) {
|
|
129
|
+
const route = originalRouterUse.apply(this, args);
|
|
130
|
+
const layer = this.stack[this.stack.length - 1];
|
|
131
|
+
if (!layer) {
|
|
132
|
+
return route;
|
|
133
|
+
}
|
|
134
|
+
patchLayer.patchLayer(getOptions, layer, utils.getLayerPath(args));
|
|
135
|
+
return route;
|
|
136
|
+
},
|
|
137
|
+
);
|
|
138
|
+
} catch (e) {
|
|
139
|
+
debugBuild.DEBUG_BUILD && debugLogger.debug.error('Failed to patch express use method:', e);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
const { application } = express;
|
|
143
|
+
const originalApplicationUse = application.use;
|
|
144
|
+
try {
|
|
145
|
+
object.wrapMethod(
|
|
146
|
+
application,
|
|
147
|
+
'use',
|
|
148
|
+
function appUseTrace(
|
|
149
|
+
|
|
150
|
+
...args
|
|
151
|
+
) {
|
|
152
|
+
// If we access app.router in express 4.x we trigger an assertion error.
|
|
153
|
+
// This property existed in v3, was removed in v4 and then re-added in v5.
|
|
154
|
+
const route = originalApplicationUse.apply(this, args);
|
|
155
|
+
const router = utils.isExpressWithRouterPrototype(express) ? this.router : this._router;
|
|
156
|
+
if (router) {
|
|
157
|
+
const layer = router.stack[router.stack.length - 1];
|
|
158
|
+
if (layer) {
|
|
159
|
+
patchLayer.patchLayer(getOptions, layer, utils.getLayerPath(args));
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
return route;
|
|
163
|
+
},
|
|
164
|
+
);
|
|
165
|
+
} catch (e) {
|
|
166
|
+
debugBuild.DEBUG_BUILD && debugLogger.debug.error('Failed to patch express application.use method:', e);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
return express;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* An Express-compatible error handler, used by setupExpressErrorHandler
|
|
174
|
+
*/
|
|
175
|
+
function expressErrorHandler(options) {
|
|
176
|
+
return function sentryErrorMiddleware(
|
|
177
|
+
error,
|
|
178
|
+
request,
|
|
179
|
+
res,
|
|
180
|
+
next,
|
|
181
|
+
) {
|
|
182
|
+
// When an error happens, the `expressRequestHandler` middleware does not run, so we set it here too
|
|
183
|
+
setSdkProcessingMetadata.setSDKProcessingMetadata(request);
|
|
184
|
+
const shouldHandleError = options?.shouldHandleError || utils.defaultShouldHandleError;
|
|
185
|
+
|
|
186
|
+
if (shouldHandleError(error)) {
|
|
187
|
+
const eventId = _exports.captureException(error, {
|
|
188
|
+
mechanism: { type: 'auto.middleware.express', handled: false },
|
|
189
|
+
});
|
|
190
|
+
(res ).sentry = eventId;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
next(error);
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
* Add an Express error handler to capture errors to Sentry.
|
|
199
|
+
*
|
|
200
|
+
* The error handler must be before any other middleware and after all controllers.
|
|
201
|
+
*
|
|
202
|
+
* @param app The Express instances
|
|
203
|
+
* @param options {ExpressHandlerOptions} Configuration options for the handler
|
|
204
|
+
*
|
|
205
|
+
* @example
|
|
206
|
+
* ```javascript
|
|
207
|
+
* import * as Sentry from 'sentry/deno'; // or any other @sentry/<platform>
|
|
208
|
+
* import * as express from 'express';
|
|
209
|
+
*
|
|
210
|
+
* Sentry.instrumentExpress(express);
|
|
211
|
+
*
|
|
212
|
+
* const app = express();
|
|
213
|
+
*
|
|
214
|
+
* // Add your routes, etc.
|
|
215
|
+
*
|
|
216
|
+
* // Add this after all routes,
|
|
217
|
+
* // but before any and other error-handling middlewares are defined
|
|
218
|
+
* Sentry.setupExpressErrorHandler(app);
|
|
219
|
+
*
|
|
220
|
+
* app.listen(3000);
|
|
221
|
+
* ```
|
|
222
|
+
*/
|
|
223
|
+
function setupExpressErrorHandler(
|
|
224
|
+
app
|
|
225
|
+
|
|
226
|
+
,
|
|
227
|
+
options,
|
|
228
|
+
) {
|
|
229
|
+
app.use(expressRequestHandler());
|
|
230
|
+
app.use(expressErrorHandler(options));
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
function expressRequestHandler() {
|
|
234
|
+
return function sentryRequestMiddleware(request, _res, next) {
|
|
235
|
+
setSdkProcessingMetadata.setSDKProcessingMetadata(request);
|
|
236
|
+
next();
|
|
237
|
+
};
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
exports.expressErrorHandler = expressErrorHandler;
|
|
241
|
+
exports.patchExpressModule = patchExpressModule;
|
|
242
|
+
exports.setupExpressErrorHandler = setupExpressErrorHandler;
|
|
243
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../../src/integrations/express/index.ts"],"sourcesContent":["/**\n * Platform-portable Express tracing integration.\n *\n * @module\n *\n * This Sentry integration is a derivative work based on the OpenTelemetry\n * Express instrumentation.\n *\n * <https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/packages/instrumentation-express>\n *\n * Extended under the terms of the Apache 2.0 license linked below:\n *\n * ----\n *\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { debug } from '../../utils/debug-logger';\nimport { captureException } from '../../exports';\nimport { DEBUG_BUILD } from '../../debug-build';\nimport type {\n ExpressApplication,\n ExpressErrorMiddleware,\n ExpressExport,\n ExpressHandlerOptions,\n ExpressIntegrationOptions,\n ExpressLayer,\n ExpressMiddleware,\n ExpressModuleExport,\n ExpressRequest,\n ExpressResponse,\n ExpressRouter,\n ExpressRouterv4,\n ExpressRouterv5,\n MiddlewareError,\n} from './types';\nimport {\n defaultShouldHandleError,\n getLayerPath,\n hasDefaultProp,\n isExpressWithoutRouterPrototype,\n isExpressWithRouterPrototype,\n} from './utils';\nimport { wrapMethod } from '../../utils/object';\nimport { patchLayer } from './patch-layer';\nimport { setSDKProcessingMetadata } from './set-sdk-processing-metadata';\n\nconst getExpressExport = (express: ExpressModuleExport): ExpressExport =>\n hasDefaultProp(express) ? express.default : (express as ExpressExport);\n\nfunction isLegacyOptions(\n options: ExpressModuleExport | (ExpressIntegrationOptions & { express: ExpressModuleExport }),\n): options is ExpressIntegrationOptions & { express: ExpressModuleExport } {\n return !!(options as { express: ExpressModuleExport }).express;\n}\n\n// TODO: remove this deprecation handling in v11\nlet didLegacyDeprecationWarning = false;\nfunction deprecationWarning() {\n if (!didLegacyDeprecationWarning) {\n didLegacyDeprecationWarning = true;\n DEBUG_BUILD &&\n debug.warn(\n '[Express] `patchExpressModule(options)` is deprecated. Use `patchExpressModule(moduleExports, getOptions)` instead.',\n );\n }\n}\n\n/**\n * This is a portable instrumentatiton function that works in any environment\n * where Express can be loaded, without depending on OpenTelemetry.\n *\n * @example\n * ```javascript\n * import express from 'express';\n * import * as Sentry from '@sentry/deno'; // or any SDK that extends core\n *\n * Sentry.patchExpressModule(express, () => ({}));\n * ```\n */\nexport function patchExpressModule(\n moduleExports: ExpressModuleExport,\n getOptions: () => ExpressIntegrationOptions,\n): ExpressModuleExport;\n/**\n * @deprecated Pass the Express module export as the first argument and options getter as the second argument.\n */\nexport function patchExpressModule(\n options: ExpressIntegrationOptions & { express: ExpressModuleExport },\n): ExpressModuleExport;\nexport function patchExpressModule(\n optionsOrExports: ExpressModuleExport | (ExpressIntegrationOptions & { express: ExpressModuleExport }),\n maybeGetOptions?: () => ExpressIntegrationOptions,\n): ExpressModuleExport {\n let getOptions: () => ExpressIntegrationOptions;\n let moduleExports: ExpressModuleExport;\n if (!maybeGetOptions && isLegacyOptions(optionsOrExports)) {\n const { express, ...options } = optionsOrExports;\n moduleExports = express;\n getOptions = () => options;\n deprecationWarning();\n } else if (typeof maybeGetOptions !== 'function') {\n throw new TypeError('`patchExpressModule(moduleExports, getOptions)` requires a `getOptions` callback');\n } else {\n getOptions = maybeGetOptions;\n moduleExports = optionsOrExports as ExpressModuleExport;\n }\n\n // pass in the require() or import() result of express\n const express = getExpressExport(moduleExports);\n const routerProto: ExpressRouterv4 | ExpressRouterv5 | undefined = isExpressWithRouterPrototype(express)\n ? express.Router.prototype // Express v5\n : isExpressWithoutRouterPrototype(express)\n ? express.Router // Express v4\n : undefined;\n\n if (!routerProto) {\n throw new TypeError('no valid Express route function to instrument');\n }\n\n // oxlint-disable-next-line @typescript-eslint/unbound-method\n const originalRouteMethod = routerProto.route;\n try {\n wrapMethod(\n routerProto,\n 'route',\n function routeTrace(this: ExpressRouter, ...args: Parameters<typeof originalRouteMethod>[]) {\n const route = originalRouteMethod.apply(this, args);\n const layer = this.stack[this.stack.length - 1] as ExpressLayer;\n patchLayer(getOptions, layer, getLayerPath(args));\n return route;\n },\n );\n } catch (e) {\n DEBUG_BUILD && debug.error('Failed to patch express route method:', e);\n }\n\n // oxlint-disable-next-line @typescript-eslint/unbound-method\n const originalRouterUse = routerProto.use;\n try {\n wrapMethod(\n routerProto,\n 'use',\n function useTrace(this: ExpressApplication, ...args: Parameters<typeof originalRouterUse>) {\n const route = originalRouterUse.apply(this, args);\n const layer = this.stack[this.stack.length - 1];\n if (!layer) {\n return route;\n }\n patchLayer(getOptions, layer, getLayerPath(args));\n return route;\n },\n );\n } catch (e) {\n DEBUG_BUILD && debug.error('Failed to patch express use method:', e);\n }\n\n const { application } = express;\n const originalApplicationUse = application.use;\n try {\n wrapMethod(\n application,\n 'use',\n function appUseTrace(\n this: ExpressApplication & {\n _router?: ExpressRouter;\n router?: ExpressRouter;\n },\n ...args: Parameters<ExpressApplication['use']>\n ) {\n // If we access app.router in express 4.x we trigger an assertion error.\n // This property existed in v3, was removed in v4 and then re-added in v5.\n const route = originalApplicationUse.apply(this, args);\n const router = isExpressWithRouterPrototype(express) ? this.router : this._router;\n if (router) {\n const layer = router.stack[router.stack.length - 1];\n if (layer) {\n patchLayer(getOptions, layer, getLayerPath(args));\n }\n }\n return route;\n },\n );\n } catch (e) {\n DEBUG_BUILD && debug.error('Failed to patch express application.use method:', e);\n }\n\n return express;\n}\n\n/**\n * An Express-compatible error handler, used by setupExpressErrorHandler\n */\nexport function expressErrorHandler(options?: ExpressHandlerOptions): ExpressErrorMiddleware {\n return function sentryErrorMiddleware(\n error: MiddlewareError,\n request: ExpressRequest,\n res: ExpressResponse,\n next: (error: MiddlewareError) => void,\n ): void {\n // When an error happens, the `expressRequestHandler` middleware does not run, so we set it here too\n setSDKProcessingMetadata(request);\n const shouldHandleError = options?.shouldHandleError || defaultShouldHandleError;\n\n if (shouldHandleError(error)) {\n const eventId = captureException(error, {\n mechanism: { type: 'auto.middleware.express', handled: false },\n });\n (res as { sentry?: string }).sentry = eventId;\n }\n\n next(error);\n };\n}\n\n/**\n * Add an Express error handler to capture errors to Sentry.\n *\n * The error handler must be before any other middleware and after all controllers.\n *\n * @param app The Express instances\n * @param options {ExpressHandlerOptions} Configuration options for the handler\n *\n * @example\n * ```javascript\n * import * as Sentry from 'sentry/deno'; // or any other @sentry/<platform>\n * import * as express from 'express';\n *\n * Sentry.instrumentExpress(express);\n *\n * const app = express();\n *\n * // Add your routes, etc.\n *\n * // Add this after all routes,\n * // but before any and other error-handling middlewares are defined\n * Sentry.setupExpressErrorHandler(app);\n *\n * app.listen(3000);\n * ```\n */\nexport function setupExpressErrorHandler(\n app: {\n //oxlint-disable-next-line no-explicit-any\n use: (middleware: any) => unknown;\n },\n options?: ExpressHandlerOptions,\n): void {\n app.use(expressRequestHandler());\n app.use(expressErrorHandler(options));\n}\n\nfunction expressRequestHandler(): ExpressMiddleware {\n return function sentryRequestMiddleware(request: ExpressRequest, _res: ExpressResponse, next: () => void): void {\n setSDKProcessingMetadata(request);\n next();\n };\n}\n"],"names":["hasDefaultProp","DEBUG_BUILD","debug","isExpressWithRouterPrototype","isExpressWithoutRouterPrototype","wrapMethod","patchLayer","getLayerPath","setSDKProcessingMetadata","defaultShouldHandleError","captureException"],"mappings":";;;;;;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AAgCA,MAAM,gBAAA,GAAmB,CAAC,OAAO;AACjC,EAAEA,oBAAc,CAAC,OAAO,CAAA,GAAI,OAAO,CAAC,OAAA,IAAW,OAAA,EAAyB;;AAExE,SAAS,eAAe;AACxB,EAAE,OAAO;AACT,EAA2E;AAC3E,EAAE,OAAO,CAAC,CAAC,CAAC,OAAA,GAA6C,OAAO;AAChE;;AAEA;AACA,IAAI,2BAAA,GAA8B,KAAK;AACvC,SAAS,kBAAkB,GAAG;AAC9B,EAAE,IAAI,CAAC,2BAA2B,EAAE;AACpC,IAAI,2BAAA,GAA8B,IAAI;AACtC,IAAIC,sBAAA;AACJ,MAAMC,iBAAK,CAA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SAAS,EAAE,EAAE,IAAI,EAAE,yBAAyB,EAAE,OAAO,EAAE,KAAA,EAAO;AACtE,OAAO,CAAC;AACR,MAAM,CAAC,GAAA,GAA4B,MAAA,GAAS,OAAO;AACnD,IAAI;;AAEJ,IAAI,IAAI,CAAC,KAAK,CAAC;AACf,EAAE,CAAC;AACH;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAAS,wBAAwB;AACxC,EAAE;;AAGA;AACF,EAAE,OAAO;AACT,EAAQ;AACR,EAAE,GAAG,CAAC,GAAG,CAAC,qBAAqB,EAAE,CAAC;AAClC,EAAE,GAAG,CAAC,GAAG,CAAC,mBAAmB,CAAC,OAAO,CAAC,CAAC;AACvC;;AAEA,SAAS,qBAAqB,GAAsB;AACpD,EAAE,OAAO,SAAS,uBAAuB,CAAC,OAAO,EAAkB,IAAI,EAAmB,IAAI,EAAoB;AAClH,IAAIF,iDAAwB,CAAC,OAAO,CAAC;AACrC,IAAI,IAAI,EAAE;AACV,EAAE,CAAC;AACH;;;;;;"}
|
|
@@ -0,0 +1,257 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
|
|
3
|
+
const debugBuild = require('../../debug-build.js');
|
|
4
|
+
const semanticAttributes = require('../../semanticAttributes.js');
|
|
5
|
+
const debugLogger = require('../../utils/debug-logger.js');
|
|
6
|
+
const spanUtils = require('../../utils/spanUtils.js');
|
|
7
|
+
const spanstatus = require('../../tracing/spanstatus.js');
|
|
8
|
+
const object = require('../../utils/object.js');
|
|
9
|
+
const currentScopes = require('../../currentScopes.js');
|
|
10
|
+
const trace = require('../../tracing/trace.js');
|
|
11
|
+
const requestLayerStore = require('./request-layer-store.js');
|
|
12
|
+
const types = require('./types.js');
|
|
13
|
+
const utils = require('./utils.js');
|
|
14
|
+
const defaultScopes = require('../../defaultScopes.js');
|
|
15
|
+
const setSdkProcessingMetadata = require('./set-sdk-processing-metadata.js');
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Platform-portable Express tracing integration.
|
|
19
|
+
*
|
|
20
|
+
* @module
|
|
21
|
+
*
|
|
22
|
+
* This Sentry integration is a derivative work based on the OpenTelemetry
|
|
23
|
+
* Express instrumentation.
|
|
24
|
+
*
|
|
25
|
+
* <https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/packages/instrumentation-express>
|
|
26
|
+
*
|
|
27
|
+
* Extended under the terms of the Apache 2.0 license linked below:
|
|
28
|
+
*
|
|
29
|
+
* ----
|
|
30
|
+
*
|
|
31
|
+
* Copyright The OpenTelemetry Authors
|
|
32
|
+
*
|
|
33
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
34
|
+
* you may not use this file except in compliance with the License.
|
|
35
|
+
* You may obtain a copy of the License at
|
|
36
|
+
*
|
|
37
|
+
* https://www.apache.org/licenses/LICENSE-2.0
|
|
38
|
+
*
|
|
39
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
40
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
41
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
42
|
+
* See the License for the specific language governing permissions and
|
|
43
|
+
* limitations under the License.
|
|
44
|
+
*/
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
function patchLayer(
|
|
48
|
+
getOptions,
|
|
49
|
+
maybeLayer,
|
|
50
|
+
layerPath,
|
|
51
|
+
) {
|
|
52
|
+
if (!maybeLayer?.handle) {
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
const layer = maybeLayer;
|
|
56
|
+
|
|
57
|
+
const layerHandleOriginal = layer.handle;
|
|
58
|
+
|
|
59
|
+
// avoid patching multiple times the same layer
|
|
60
|
+
if (object.getOriginalFunction(layerHandleOriginal)) {
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
if (layerHandleOriginal.length === 4) {
|
|
65
|
+
// todo: instrument error handlers
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function layerHandlePatched(
|
|
70
|
+
|
|
71
|
+
req,
|
|
72
|
+
res,
|
|
73
|
+
//oxlint-disable-next-line no-explicit-any
|
|
74
|
+
...otherArgs
|
|
75
|
+
) {
|
|
76
|
+
const options = getOptions();
|
|
77
|
+
|
|
78
|
+
// Set normalizedRequest here because expressRequestHandler middleware
|
|
79
|
+
// (registered via setupExpressErrorHandler) is added after routes and
|
|
80
|
+
// therefore never runs for successful requests — route handlers typically
|
|
81
|
+
// send a response without calling next(). It would be safe to set this
|
|
82
|
+
// multiple times, since the data is identical, but more performant not to.
|
|
83
|
+
setSdkProcessingMetadata.setSDKProcessingMetadata(req);
|
|
84
|
+
|
|
85
|
+
// Only create spans when there's an active parent span
|
|
86
|
+
// Without a parent span, this request is being ignored, so skip it
|
|
87
|
+
const parentSpan = spanUtils.getActiveSpan();
|
|
88
|
+
if (!parentSpan) {
|
|
89
|
+
return layerHandleOriginal.apply(this, [req, res, ...otherArgs]);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
if (layerPath) {
|
|
93
|
+
requestLayerStore.storeLayer(req, layerPath);
|
|
94
|
+
}
|
|
95
|
+
const storedLayers = requestLayerStore.getStoredLayers(req);
|
|
96
|
+
const isLayerPathStored = !!layerPath;
|
|
97
|
+
|
|
98
|
+
const constructedRoute = utils.getConstructedRoute(req);
|
|
99
|
+
const actualMatchedRoute = utils.getActualMatchedRoute(req, constructedRoute);
|
|
100
|
+
|
|
101
|
+
options.onRouteResolved?.(actualMatchedRoute);
|
|
102
|
+
|
|
103
|
+
const metadata = utils.getLayerMetadata(constructedRoute, layer, layerPath);
|
|
104
|
+
const name = metadata.attributes[types.ATTR_EXPRESS_NAME];
|
|
105
|
+
const type = metadata.attributes[types.ATTR_EXPRESS_TYPE];
|
|
106
|
+
const attributes = Object.assign(metadata.attributes, {
|
|
107
|
+
[semanticAttributes.SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.http.express',
|
|
108
|
+
[semanticAttributes.SEMANTIC_ATTRIBUTE_SENTRY_OP]: `${type}.express`,
|
|
109
|
+
});
|
|
110
|
+
if (actualMatchedRoute) {
|
|
111
|
+
attributes[types.ATTR_HTTP_ROUTE] = actualMatchedRoute;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// verify against the config if the layer should be ignored
|
|
115
|
+
if (utils.isLayerIgnored(metadata.attributes[types.ATTR_EXPRESS_NAME], type, options)) {
|
|
116
|
+
// XXX: the isLayerPathStored guard here is *not* present in the
|
|
117
|
+
// original @opentelemetry/instrumentation-express impl, but was
|
|
118
|
+
// suggested by the Sentry code review bot. It appears to correctly
|
|
119
|
+
// prevent improper layer calculation in the case where there's a
|
|
120
|
+
// middleware without a layerPath argument. It's unclear whether
|
|
121
|
+
// that's possible, or if any existing code depends on that "bug".
|
|
122
|
+
if (isLayerPathStored) {
|
|
123
|
+
storedLayers.pop();
|
|
124
|
+
}
|
|
125
|
+
return layerHandleOriginal.apply(this, [req, res, ...otherArgs]);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
const currentScope = currentScopes.getIsolationScope();
|
|
129
|
+
if (currentScope !== defaultScopes.getDefaultIsolationScope()) {
|
|
130
|
+
if (type === 'request_handler') {
|
|
131
|
+
// type cast b/c Otel unfortunately types info.request as any :(
|
|
132
|
+
const method = req.method ? req.method.toUpperCase() : 'GET';
|
|
133
|
+
currentScope.setTransactionName(`${method} ${constructedRoute}`);
|
|
134
|
+
}
|
|
135
|
+
} else {
|
|
136
|
+
debugBuild.DEBUG_BUILD && debugLogger.debug.warn('Isolation scope is still default isolation scope - skipping setting transactionName');
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
return trace.startSpanManual({ name, attributes }, span => {
|
|
140
|
+
let spanHasEnded = false;
|
|
141
|
+
// TODO: Fix router spans (getRouterPath does not work properly) to
|
|
142
|
+
// have useful names before removing this branch
|
|
143
|
+
if (metadata.attributes[types.ATTR_EXPRESS_TYPE] === types.ExpressLayerType_ROUTER) {
|
|
144
|
+
span.end();
|
|
145
|
+
spanHasEnded = true;
|
|
146
|
+
}
|
|
147
|
+
// listener for response.on('finish')
|
|
148
|
+
const onResponseFinish = () => {
|
|
149
|
+
if (!spanHasEnded) {
|
|
150
|
+
spanHasEnded = true;
|
|
151
|
+
span.end();
|
|
152
|
+
}
|
|
153
|
+
};
|
|
154
|
+
|
|
155
|
+
// verify we have a callback
|
|
156
|
+
for (let i = 0; i < otherArgs.length; i++) {
|
|
157
|
+
const callback = otherArgs[i] ;
|
|
158
|
+
if (typeof callback !== 'function') {
|
|
159
|
+
continue;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
//oxlint-disable-next-line no-explicit-any
|
|
163
|
+
otherArgs[i] = function (...args) {
|
|
164
|
+
// express considers anything but an empty value, "route" or "router"
|
|
165
|
+
// passed to its callback to be an error
|
|
166
|
+
const maybeError = args[0];
|
|
167
|
+
const isError = !!maybeError && maybeError !== 'route' && maybeError !== 'router';
|
|
168
|
+
if (!spanHasEnded && isError) {
|
|
169
|
+
const [_, message] = utils.asErrorAndMessage(maybeError);
|
|
170
|
+
// intentionally do not record the exception here, because
|
|
171
|
+
// the error handler we assign does that, provided the user
|
|
172
|
+
// correctly calls setupExpressErrorHandler.
|
|
173
|
+
// TODO: A future enhancement can automatically attach
|
|
174
|
+
// the error handler if we detect that it has not been added.
|
|
175
|
+
span.setStatus({
|
|
176
|
+
code: spanstatus.SPAN_STATUS_ERROR,
|
|
177
|
+
message,
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
if (!spanHasEnded) {
|
|
182
|
+
spanHasEnded = true;
|
|
183
|
+
res.removeListener('finish', onResponseFinish);
|
|
184
|
+
span.end();
|
|
185
|
+
}
|
|
186
|
+
if (!(req.route && isError) && isLayerPathStored) {
|
|
187
|
+
storedLayers.pop();
|
|
188
|
+
}
|
|
189
|
+
// execute the callback back in the parent's scope, so that
|
|
190
|
+
// we bubble up each level as next() is called.
|
|
191
|
+
return trace.withActiveSpan(parentSpan, () => callback.apply(this, args));
|
|
192
|
+
};
|
|
193
|
+
break;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
try {
|
|
197
|
+
return layerHandleOriginal.apply(this, [req, res, ...otherArgs]);
|
|
198
|
+
} catch (anyError) {
|
|
199
|
+
const [_, message] = utils.asErrorAndMessage(anyError);
|
|
200
|
+
// intentionally do not record the exception here, because
|
|
201
|
+
// the error handler we assign does that, provided the user
|
|
202
|
+
// correctly calls setupExpressErrorHandler.
|
|
203
|
+
// TODO: A future enhancement can automatically attach
|
|
204
|
+
// the error handler if we detect that it has not been added.
|
|
205
|
+
span.setStatus({
|
|
206
|
+
code: spanstatus.SPAN_STATUS_ERROR,
|
|
207
|
+
message,
|
|
208
|
+
});
|
|
209
|
+
throw anyError;
|
|
210
|
+
/* v8 ignore next - it sees the block end at the throw */
|
|
211
|
+
} finally {
|
|
212
|
+
// At this point if the callback wasn't called, that means
|
|
213
|
+
// either the layer is asynchronous (so it will call the
|
|
214
|
+
// callback later on) or that the layer directly ends the
|
|
215
|
+
// http response, so we'll hook into the "finish" event to
|
|
216
|
+
// handle the later case.
|
|
217
|
+
if (!spanHasEnded) {
|
|
218
|
+
res.once('finish', onResponseFinish);
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
// `handle` isn't just a regular function in some cases. It also contains
|
|
225
|
+
// some properties holding metadata and state so we need to proxy them
|
|
226
|
+
// through through patched function. Use a for-in to also pick up properties
|
|
227
|
+
// that other libraries might add to the prototype before we instrument.
|
|
228
|
+
// ref: https://github.com/open-telemetry/opentelemetry-js-contrib/issues/1950
|
|
229
|
+
// ref: https://github.com/open-telemetry/opentelemetry-js-contrib/issues/2271
|
|
230
|
+
// oxlint-disable-next-line guard-for-in
|
|
231
|
+
for (const key in layerHandleOriginal ) {
|
|
232
|
+
// skip standard function prototype fields that both have
|
|
233
|
+
if (key in layerHandlePatched) {
|
|
234
|
+
continue;
|
|
235
|
+
}
|
|
236
|
+
Object.defineProperty(layerHandlePatched, key, {
|
|
237
|
+
get() {
|
|
238
|
+
return layerHandleOriginal[key];
|
|
239
|
+
},
|
|
240
|
+
set(value) {
|
|
241
|
+
layerHandleOriginal[key] = value;
|
|
242
|
+
},
|
|
243
|
+
});
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
object.markFunctionWrapped(layerHandlePatched, layerHandleOriginal);
|
|
247
|
+
|
|
248
|
+
Object.defineProperty(layer, 'handle', {
|
|
249
|
+
enumerable: true,
|
|
250
|
+
configurable: true,
|
|
251
|
+
writable: true,
|
|
252
|
+
value: layerHandlePatched,
|
|
253
|
+
});
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
exports.patchLayer = patchLayer;
|
|
257
|
+
//# sourceMappingURL=patch-layer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"patch-layer.js","sources":["../../../../src/integrations/express/patch-layer.ts"],"sourcesContent":["/**\n * Platform-portable Express tracing integration.\n *\n * @module\n *\n * This Sentry integration is a derivative work based on the OpenTelemetry\n * Express instrumentation.\n *\n * <https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/packages/instrumentation-express>\n *\n * Extended under the terms of the Apache 2.0 license linked below:\n *\n * ----\n *\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { DEBUG_BUILD } from '../../debug-build';\nimport { SEMANTIC_ATTRIBUTE_SENTRY_OP, SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN } from '../../semanticAttributes';\nimport { SPAN_STATUS_ERROR, startSpanManual, withActiveSpan } from '../../tracing';\nimport { debug } from '../../utils/debug-logger';\nimport type { SpanAttributes } from '../../types-hoist/span';\nimport { getActiveSpan } from '../../utils/spanUtils';\nimport { getStoredLayers, storeLayer } from './request-layer-store';\nimport {\n type ExpressRequest,\n type ExpressResponse,\n type ExpressIntegrationOptions,\n type ExpressLayer,\n ATTR_HTTP_ROUTE,\n ATTR_EXPRESS_TYPE,\n ATTR_EXPRESS_NAME,\n ExpressLayerType_ROUTER,\n} from './types';\nimport {\n asErrorAndMessage,\n getActualMatchedRoute,\n getConstructedRoute,\n getLayerMetadata,\n isLayerIgnored,\n} from './utils';\nimport { getIsolationScope } from '../../currentScopes';\nimport { getDefaultIsolationScope } from '../../defaultScopes';\nimport { getOriginalFunction, markFunctionWrapped } from '../../utils/object';\nimport { setSDKProcessingMetadata } from './set-sdk-processing-metadata';\n\nexport type ExpressPatchLayerOptions = Pick<\n ExpressIntegrationOptions,\n 'onRouteResolved' | 'ignoreLayers' | 'ignoreLayersType'\n>;\n\nexport function patchLayer(\n getOptions: () => ExpressPatchLayerOptions,\n maybeLayer?: ExpressLayer,\n layerPath?: string,\n): void {\n if (!maybeLayer?.handle) {\n return;\n }\n const layer = maybeLayer;\n\n const layerHandleOriginal = layer.handle;\n\n // avoid patching multiple times the same layer\n if (getOriginalFunction(layerHandleOriginal)) {\n return;\n }\n\n if (layerHandleOriginal.length === 4) {\n // todo: instrument error handlers\n return;\n }\n\n function layerHandlePatched(\n this: ExpressLayer,\n req: ExpressRequest,\n res: ExpressResponse,\n //oxlint-disable-next-line no-explicit-any\n ...otherArgs: any[]\n ) {\n const options = getOptions();\n\n // Set normalizedRequest here because expressRequestHandler middleware\n // (registered via setupExpressErrorHandler) is added after routes and\n // therefore never runs for successful requests — route handlers typically\n // send a response without calling next(). It would be safe to set this\n // multiple times, since the data is identical, but more performant not to.\n setSDKProcessingMetadata(req);\n\n // Only create spans when there's an active parent span\n // Without a parent span, this request is being ignored, so skip it\n const parentSpan = getActiveSpan();\n if (!parentSpan) {\n return layerHandleOriginal.apply(this, [req, res, ...otherArgs]);\n }\n\n if (layerPath) {\n storeLayer(req, layerPath);\n }\n const storedLayers = getStoredLayers(req);\n const isLayerPathStored = !!layerPath;\n\n const constructedRoute = getConstructedRoute(req);\n const actualMatchedRoute = getActualMatchedRoute(req, constructedRoute);\n\n options.onRouteResolved?.(actualMatchedRoute);\n\n const metadata = getLayerMetadata(constructedRoute, layer, layerPath);\n const name = metadata.attributes[ATTR_EXPRESS_NAME];\n const type = metadata.attributes[ATTR_EXPRESS_TYPE];\n const attributes: SpanAttributes = Object.assign(metadata.attributes, {\n [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.http.express',\n [SEMANTIC_ATTRIBUTE_SENTRY_OP]: `${type}.express`,\n });\n if (actualMatchedRoute) {\n attributes[ATTR_HTTP_ROUTE] = actualMatchedRoute;\n }\n\n // verify against the config if the layer should be ignored\n if (isLayerIgnored(metadata.attributes[ATTR_EXPRESS_NAME], type, options)) {\n // XXX: the isLayerPathStored guard here is *not* present in the\n // original @opentelemetry/instrumentation-express impl, but was\n // suggested by the Sentry code review bot. It appears to correctly\n // prevent improper layer calculation in the case where there's a\n // middleware without a layerPath argument. It's unclear whether\n // that's possible, or if any existing code depends on that \"bug\".\n if (isLayerPathStored) {\n storedLayers.pop();\n }\n return layerHandleOriginal.apply(this, [req, res, ...otherArgs]);\n }\n\n const currentScope = getIsolationScope();\n if (currentScope !== getDefaultIsolationScope()) {\n if (type === 'request_handler') {\n // type cast b/c Otel unfortunately types info.request as any :(\n const method = req.method ? req.method.toUpperCase() : 'GET';\n currentScope.setTransactionName(`${method} ${constructedRoute}`);\n }\n } else {\n DEBUG_BUILD && debug.warn('Isolation scope is still default isolation scope - skipping setting transactionName');\n }\n\n return startSpanManual({ name, attributes }, span => {\n let spanHasEnded = false;\n // TODO: Fix router spans (getRouterPath does not work properly) to\n // have useful names before removing this branch\n if (metadata.attributes[ATTR_EXPRESS_TYPE] === ExpressLayerType_ROUTER) {\n span.end();\n spanHasEnded = true;\n }\n // listener for response.on('finish')\n const onResponseFinish = () => {\n if (!spanHasEnded) {\n spanHasEnded = true;\n span.end();\n }\n };\n\n // verify we have a callback\n for (let i = 0; i < otherArgs.length; i++) {\n const callback = otherArgs[i] as Function;\n if (typeof callback !== 'function') {\n continue;\n }\n\n //oxlint-disable-next-line no-explicit-any\n otherArgs[i] = function (...args: any[]) {\n // express considers anything but an empty value, \"route\" or \"router\"\n // passed to its callback to be an error\n const maybeError = args[0];\n const isError = !!maybeError && maybeError !== 'route' && maybeError !== 'router';\n if (!spanHasEnded && isError) {\n const [_, message] = asErrorAndMessage(maybeError);\n // intentionally do not record the exception here, because\n // the error handler we assign does that, provided the user\n // correctly calls setupExpressErrorHandler.\n // TODO: A future enhancement can automatically attach\n // the error handler if we detect that it has not been added.\n span.setStatus({\n code: SPAN_STATUS_ERROR,\n message,\n });\n }\n\n if (!spanHasEnded) {\n spanHasEnded = true;\n res.removeListener('finish', onResponseFinish);\n span.end();\n }\n if (!(req.route && isError) && isLayerPathStored) {\n storedLayers.pop();\n }\n // execute the callback back in the parent's scope, so that\n // we bubble up each level as next() is called.\n return withActiveSpan(parentSpan, () => callback.apply(this, args));\n };\n break;\n }\n\n try {\n return layerHandleOriginal.apply(this, [req, res, ...otherArgs]);\n } catch (anyError) {\n const [_, message] = asErrorAndMessage(anyError);\n // intentionally do not record the exception here, because\n // the error handler we assign does that, provided the user\n // correctly calls setupExpressErrorHandler.\n // TODO: A future enhancement can automatically attach\n // the error handler if we detect that it has not been added.\n span.setStatus({\n code: SPAN_STATUS_ERROR,\n message,\n });\n throw anyError;\n /* v8 ignore next - it sees the block end at the throw */\n } finally {\n // At this point if the callback wasn't called, that means\n // either the layer is asynchronous (so it will call the\n // callback later on) or that the layer directly ends the\n // http response, so we'll hook into the \"finish\" event to\n // handle the later case.\n if (!spanHasEnded) {\n res.once('finish', onResponseFinish);\n }\n }\n });\n }\n\n // `handle` isn't just a regular function in some cases. It also contains\n // some properties holding metadata and state so we need to proxy them\n // through through patched function. Use a for-in to also pick up properties\n // that other libraries might add to the prototype before we instrument.\n // ref: https://github.com/open-telemetry/opentelemetry-js-contrib/issues/1950\n // ref: https://github.com/open-telemetry/opentelemetry-js-contrib/issues/2271\n // oxlint-disable-next-line guard-for-in\n for (const key in layerHandleOriginal as Function & Record<string, unknown>) {\n // skip standard function prototype fields that both have\n if (key in layerHandlePatched) {\n continue;\n }\n Object.defineProperty(layerHandlePatched, key, {\n get() {\n return layerHandleOriginal[key];\n },\n set(value) {\n layerHandleOriginal[key] = value;\n },\n });\n }\n\n markFunctionWrapped(layerHandlePatched, layerHandleOriginal);\n\n Object.defineProperty(layer, 'handle', {\n enumerable: true,\n configurable: true,\n writable: true,\n value: layerHandlePatched,\n });\n}\n"],"names":["getOriginalFunction","setSDKProcessingMetadata","getActiveSpan","storeLayer","getStoredLayers","getConstructedRoute","getActualMatchedRoute","getLayerMetadata","ATTR_EXPRESS_NAME","ATTR_EXPRESS_TYPE","SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN","SEMANTIC_ATTRIBUTE_SENTRY_OP","ATTR_HTTP_ROUTE","isLayerIgnored","getIsolationScope","getDefaultIsolationScope","DEBUG_BUILD","debug","startSpanManual","ExpressLayerType_ROUTER","asErrorAndMessage","SPAN_STATUS_ERROR","withActiveSpan","markFunctionWrapped"],"mappings":";;;;;;;;;;;;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AAoCO,SAAS,UAAU;AAC1B,EAAE,UAAU;AACZ,EAAE,UAAU;AACZ,EAAE,SAAS;AACX,EAAQ;AACR,EA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MAAA,CAAA;AACA,MAAA,GAAA,CAAA,KAAA,EAAA;AACA,QAAA,mBAAA,CAAA,GAAA,CAAA,GAAA,KAAA;AACA,MAAA,CAAA;AACA,KAAA,CAAA;AACA,EAAA;;AAEA,EAAAE,0BAAA,CAAA,kBAAA,EAAA,mBAAA,CAAA;;AAEA,EAAA,MAAA,CAAA,cAAA,CAAA,KAAA,EAAA,QAAA,EAAA;AACA,IAAA,UAAA,EAAA,IAAA;AACA,IAAA,YAAA,EAAA,IAAA;AACA,IAAA,QAAA,EAAA,IAAA;AACA,IAAA,KAAA,EAAA,kBAAA;AACA,GAAA,CAAA;AACA;;;;"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
|
|
3
|
+
// map of patched request objects to stored layers
|
|
4
|
+
const requestLayerStore = new WeakMap();
|
|
5
|
+
const storeLayer = (req, layer) => {
|
|
6
|
+
const store = requestLayerStore.get(req);
|
|
7
|
+
if (!store) {
|
|
8
|
+
requestLayerStore.set(req, [layer]);
|
|
9
|
+
} else {
|
|
10
|
+
store.push(layer);
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
const getStoredLayers = (req) => {
|
|
15
|
+
let store = requestLayerStore.get(req);
|
|
16
|
+
if (!store) {
|
|
17
|
+
store = [];
|
|
18
|
+
requestLayerStore.set(req, store);
|
|
19
|
+
}
|
|
20
|
+
return store;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
exports.getStoredLayers = getStoredLayers;
|
|
24
|
+
exports.storeLayer = storeLayer;
|
|
25
|
+
//# sourceMappingURL=request-layer-store.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"request-layer-store.js","sources":["../../../../src/integrations/express/request-layer-store.ts"],"sourcesContent":["/**\n * Platform-portable Express tracing integration.\n *\n * @module\n *\n * This Sentry integration is a derivative work based on the OpenTelemetry\n * Express instrumentation.\n *\n * <https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/packages/instrumentation-express>\n *\n * Extended under the terms of the Apache 2.0 license linked below:\n *\n * ----\n *\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type { ExpressRequest } from './types';\n\n// map of patched request objects to stored layers\nconst requestLayerStore = new WeakMap<ExpressRequest, string[]>();\nexport const storeLayer = (req: ExpressRequest, layer: string) => {\n const store = requestLayerStore.get(req);\n if (!store) {\n requestLayerStore.set(req, [layer]);\n } else {\n store.push(layer);\n }\n};\n\nexport const getStoredLayers = (req: ExpressRequest) => {\n let store = requestLayerStore.get(req);\n if (!store) {\n store = [];\n requestLayerStore.set(req, store);\n }\n return store;\n};\n"],"names":[],"mappings":";;AA+BA;AACA,MAAM,iBAAA,GAAoB,IAAI,OAAO,EAA4B;AAC1D,MAAM,aAAa,CAAC,GAAG,EAAkB,KAAK,KAAa;AAClE,EAAE,MAAM,QAAQ,iBAAiB,CAAC,GAAG,CAAC,GAAG,CAAC;AAC1C,EAAE,IAAI,CAAC,KAAK,EAAE;AACd,IAAI,iBAAiB,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,CAAC;AACvC,EAAE,OAAO;AACT,IAAI,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC;AACrB,EAAE;AACF;;MAEa,eAAA,GAAkB,CAAC,GAAG,KAAqB;AACxD,EAAE,IAAI,QAAQ,iBAAiB,CAAC,GAAG,CAAC,GAAG,CAAC;AACxC,EAAE,IAAI,CAAC,KAAK,EAAE;AACd,IAAI,KAAA,GAAQ,EAAE;AACd,IAAI,iBAAiB,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC;AACrC,EAAE;AACF,EAAE,OAAO,KAAK;AACd;;;;;"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
|
|
3
|
+
const currentScopes = require('../../currentScopes.js');
|
|
4
|
+
const request = require('../../utils/request.js');
|
|
5
|
+
|
|
6
|
+
// TODO: consider moving this into a core util, eg
|
|
7
|
+
// setSDKProcessingMetadataFromRequest(..), if other integrations need it.
|
|
8
|
+
function setSDKProcessingMetadata(request$1) {
|
|
9
|
+
const sdkProcMeta = currentScopes.getIsolationScope()?.getScopeData()?.sdkProcessingMetadata;
|
|
10
|
+
if (!sdkProcMeta?.normalizedRequest) {
|
|
11
|
+
const normalizedRequest = request.httpRequestToRequestData(request$1);
|
|
12
|
+
currentScopes.getIsolationScope().setSDKProcessingMetadata({ normalizedRequest });
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
exports.setSDKProcessingMetadata = setSDKProcessingMetadata;
|
|
17
|
+
//# sourceMappingURL=set-sdk-processing-metadata.js.map
|