Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions sentry-javascript/19572/README.md
Original file line number Diff line number Diff line change
@@ -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=<your-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+
95 changes: 95 additions & 0 deletions sentry-javascript/19572/index.js
Original file line number Diff line number Diff line change
@@ -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);
12 changes: 12 additions & 0 deletions sentry-javascript/19572/package.json
Original file line number Diff line number Diff line change
@@ -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"
}
}