diff --git a/sentry-javascript/19572/README.md b/sentry-javascript/19572/README.md new file mode 100644 index 0000000..d65c359 --- /dev/null +++ b/sentry-javascript/19572/README.md @@ -0,0 +1,55 @@ +# Reproduction for sentry-javascript#19572 + +**Issue:** https://github.com/getsentry/sentry-javascript/issues/19572 + +## Description + +`localVariablesIntegration` does not capture nested object contents in AWS Lambda. Local variables that are objects appear as empty `{}` in Sentry, even though the same object attached via `Sentry.setExtra()` is fully preserved. Increasing `normalizeDepth` does not help. + +## Steps to Reproduce + +1. Export your Sentry DSN (or use the dummy one for local testing): + ```bash + export SENTRY_DSN= + ``` + +2. Install dependencies: + ```bash + npm install + ``` + +3. Run the reproduction: + ```bash + npm start + ``` + +## Expected Behavior + +The `payload` local variable should appear with its full nested structure in the Local Variables section, similar to how it appears when attached via `Sentry.setExtra()`. + +## Actual Behavior + +The `payload` local variable is captured as just `{}` (empty object) with no nested properties, while the exact same object attached via `Sentry.setExtra()` shows the complete structure: + +``` +--- Local variables captured for processRequest --- +{ + "simpleString": "hello world", // ✅ primitive string captured + "simpleNumber": 42, // ✅ primitive number captured + "flatObject": { "key": "value", "count": 10 }, // ✅ flat object captured + "payload": {} // ❌ nested object is empty! +} + +--- Same object attached via Sentry.setExtra() --- +{ + "user": { "id": 123, "profile": { "name": "Test User", ... } }, + "items": [{ "id": 1, "nested": { "deep": { "value": "should be visible" } } }] +} +``` + +Primitives and flat objects are captured correctly. Only deeply nested objects lose their contents. + +## Environment + +- @sentry/aws-serverless: 10.36.0 +- Node.js: v22+ diff --git a/sentry-javascript/19572/index.js b/sentry-javascript/19572/index.js new file mode 100644 index 0000000..1c8769c --- /dev/null +++ b/sentry-javascript/19572/index.js @@ -0,0 +1,95 @@ +const Sentry = require("@sentry/aws-serverless"); + +Sentry.init({ + dsn: process.env.SENTRY_DSN || "https://examplePublicKey@o0.ingest.sentry.io/0", + integrations: [ + Sentry.localVariablesIntegration({ includeOutOfAppFrames: true }), + Sentry.extraErrorDataIntegration(), + ], + includeLocalVariables: true, + // Try increasing normalizeDepth - the issue reports this doesn't help + normalizeDepth: 10, + beforeSend(event) { + // Inspect the local variables captured in stack frames + const frames = event.exception?.values?.[0]?.stacktrace?.frames || []; + for (const frame of frames) { + if (frame.vars && frame.function === "processRequest") { + console.log("\n--- Local variables captured for processRequest ---"); + console.log(JSON.stringify(frame.vars, null, 2)); + } + } + + // Also inspect extra data for comparison + if (event.extra?.payload_debug) { + console.log("\n--- Same object attached via Sentry.setExtra() ---"); + console.log(JSON.stringify(event.extra.payload_debug, null, 2)); + } + + return event; + }, +}); + +// Simulate a Lambda-like handler that processes a deeply nested payload +async function processRequest() { + // Simple (non-nested) local variables for comparison + const simpleString = "hello world"; + const simpleNumber = 42; + const flatObject = { key: "value", count: 10 }; + + // This is the deeply nested object that should appear in local variables + const payload = { + user: { + id: 123, + profile: { + name: "Test User", + address: { + street: "123 Main St", + city: "Springfield", + state: "IL", + geo: { + lat: 39.7817, + lng: -89.6501, + metadata: { + source: "geocoder", + confidence: 0.95, + details: { + provider: "mapbox", + timestamp: "2024-01-01T00:00:00Z", + }, + }, + }, + }, + }, + }, + items: [ + { + id: 1, + nested: { + deep: { + value: "should be visible", + }, + }, + }, + ], + }; + + // Attach via extra for comparison - this DOES show the full object in Sentry + Sentry.setExtra("payload_debug", payload); + + // BUG: When this error is captured, the `payload` local variable + // appears as just {} in Sentry's Local Variables panel, + // while the same object attached via setExtra() preserves all nesting. + throw new Error("Test error - check local variables for payload"); +} + +// Wait for LocalVariables worker thread to initialize before triggering the error +setTimeout(async () => { + try { + await processRequest(); + } catch (error) { + Sentry.captureException(error); + await Sentry.flush(5000); + console.log("\n--- Done ---"); + console.log("BUG: payload appears as {} in local variables but is fully preserved in extra data."); + } +}, 2000); diff --git a/sentry-javascript/19572/package.json b/sentry-javascript/19572/package.json new file mode 100644 index 0000000..3c9edf6 --- /dev/null +++ b/sentry-javascript/19572/package.json @@ -0,0 +1,12 @@ +{ + "name": "repro-sentry-javascript-19572", + "version": "1.0.0", + "private": true, + "description": "Reproduction for sentry-javascript#19572 - LocalVariables truncates nested objects", + "scripts": { + "start": "node index.js" + }, + "dependencies": { + "@sentry/aws-serverless": "10.36.0" + } +}