Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deeply Nested objects aren't being serialised #1964

Closed
1 of 3 tasks
drwharris opened this issue Mar 28, 2019 · 16 comments
Closed
1 of 3 tasks

Deeply Nested objects aren't being serialised #1964

drwharris opened this issue Mar 28, 2019 · 16 comments

Comments

@drwharris
Copy link

Important Details

I have a Node JS 11.9 application

  • On-Premise docker [Version xyz]
  • Saas (sentry.io)
  • Other AWS Fargate

Description

Just upgraded the package to "@sentry/node": "^4.6.5" from "@sentry/node": "^4.5.4".

When adding objects to Addition Data I would see the following logged:

{
	ExMessage: ,
	level: error,
	Payload: {
		AcquisitionId: ,
		ClientId: ,
		DeviceData: {  <<  - Note this 
			Browser: {
				major: ,
				name: ,
				version:
			},
			Cpu: {},
			Device: {
				type:
			},
			Engine: {
				name: ,
				version:
			},
			Os: {
				name: ,
				version:
			}
		},
		Environment: ,
		EventDate: {},  <<  - Note this 
		Fingerprint: ,
		Geographical: {}, <<  - Note this 
		IpAddress: ,
		Referer: ,
		Sequence: ,
		SessionId: ,
		Type: ,
		Url: ,
		UserAgent: ,
		UserName: ,
		Version: ,
		Weather: {} <<  - Note this
	}
}

Unfortunately, now after upgrading I am getting:

{
	ExMessage: ,
	level: ,
	Payload: {
		AcquisitionId: ,
		ClientId: ,
		DeviceData: [Object],  <<- Note this
		Environment: ,
		EventDate: [Object],  <<- Note this
		Fingerprint: ,
		Geographical: [Object],  <<- Note this
		IpAddress: ,
		Referer: ,
		Sequence: ,
		SessionId: ,
		Type: ,
		Url: ,
		UserAgent: ,
		UserName: ,
		Version: ,
		Weather: [Object] <<- Note this
	}
}

Steps to Reproduce

I have this class

export class TrackerError extends Error {
	Payload: any;
	ExMessage: string;
	constructor(message: string, err: Error, payload: any) {
		super(message);
		if (err) {
			this.stack = this.stack
				.split("\n")
				.slice(0, 2)
				.join("\n") +
				"\n" +
				err.stack;
			this.ExMessage = err.message;
		} else {
			Error.captureStackTrace(this, this.constructor);
		}

		if (payload) {
			this.Payload = payload;
		}
	}
}

which I then use as follows:

Sentry.captureException(new TrackerError("My Error Message", myErrObj, myPayloadObj));

What you expected to happen

As per previous versions, deep objects should be logged in detail

@mattrobenolt mattrobenolt transferred this issue from getsentry/sentry Mar 28, 2019
@HazAT
Copy link
Member

HazAT commented Mar 28, 2019

You should be able to define the depth yourself:

Sentry.init({
...
integrations: [new Sentry.Integrations.ExtraErrorData({ depth: 10 })],
...
});

We reduced the limit drastically since it caused many problems for users.
Hope this helps.

@HazAT HazAT closed this as completed Mar 28, 2019
@drwharris
Copy link
Author

drwharris commented Mar 28, 2019

@HazAT
Where is this documented? And is this specific to the JS library?

@HazAT
Copy link
Member

HazAT commented Mar 28, 2019

TBH, this is sadly poorly documented and should be here:
https://docs.sentry.io/platforms/javascript/default-integrations/#extraerrordata

I will write this down to improve, and yes, this is JS specific.

@drwharris
Copy link
Author

OK Thank you.

@drwharris
Copy link
Author

Sorry to come back to this but I have just updated to 5.4.0 and its now erroring with:

Property 'ExtraErrorData' does not exist on type '{ Console: typeof Console; Http: typeof Http; OnUncaughtException: typeof OnUncaughtException; OnUnhandledRejection: typeof OnUnhandledRejection; LinkedErrors: typeof LinkedErrors; Modules: typeof Modules; FunctionToString: typeof FunctionToString; InboundFilters: typeof InboundFilters; }'.

21 integrations: [new Sentry.Integrations.ExtraErrorData({ depth: 10 })]

@kamilogorek
Copy link
Contributor

kamilogorek commented Jun 12, 2019

@drwharris

import { ExtraErrorData } from '@sentry/integrations';

@drwharris
Copy link
Author

drwharris commented Apr 9, 2020

This seems to have regressed. I have this:

import { ExtraErrorData } from '@sentry/integrations';
Sentry.init({
        dsn: 'MYDSN',
        release: `${Settings.name}@${module.exports.version}`,
        integrations: [new ExtraErrorData({ depth: 10 })],
    });


And I get this

{
	AcquisitionId: "",
	ClientId: "",
	DeviceData: [Object], <<- Note this
	Environment: "",
	EventDate: [Object], <<- Note this
	Fingerprint: "",
	Geographical: [Object], <<- Note this
	IpAddress: "",
	Referer: "", 
	Sequence: "", 
	SessionId: "", 
	Type: "", 
	Url: "", 
	UserAgent: "", 
	UserName: "", 
	Version: ""
}

@mcastets
Copy link

mcastets commented May 7, 2020

You need to use the undocumented new param normalizeDepth and set it to normalizeDepth: depth + 1 :

In your example:

Sentry.init({
        dsn: 'MYDSN',
        release: `${Settings.name}@${module.exports.version}`,
        integrations: [new ExtraErrorData({ depth: 10 })],
        normalizeDepth: 11
    });

See also: #2404

@gr2m
Copy link

gr2m commented Sep 7, 2020

I've run into the same problem and can confirm that adding normalizeDepth resolves the problem. I also double checked if integrations: [new ExtraErrorData({ depth: 10 })], is necessary at all and it turns out it is not, removing it results in the same output on Sentry.

The option was add in #2404 (shipped in v5.12.0), but I could not find any documentation

@kamilogorek
Copy link
Contributor

We are aware of this issue - #2539 (comment)
It will be fixed in v6, as it's breaking change.

@FabienCH
Copy link

FabienCH commented Sep 30, 2020

Hello,

I have an issue that might be related and that I can not get to work. Just to be sure, [new ExtraErrorData({ depth: 10 })] is supposed to modify ADDITIONAL DATA field depth in the error report right ?

If so, I am using Sentry 5.22.1 and it doesn't seems to work:

 Sentry.init({
      dsn: 'https://mydsn',
      integrations: [new ExtraErrorData({ depth: 9 })],
      normalizeDepth: 10,
    });

And the additional data __serialized__ object looks loke this:

{
  error: {
    errors: {
      Views: [Array]
    }, 
    status: 400, 
    ...
  },
  ...
} 

@kamilogorek
Copy link
Contributor

I just verified it locally and it works just fine for me:

image

Sentry.init({
  dsn: "__public_dsn__",
  integrations: [new Sentry.Integrations.ExtraErrorData({ depth: 9 })],
  normalizeDepth: 10,
  beforeSend(event) {
    console.log(event);
    return null;
  },
});

const err = new Error("foo");
err.some = {
  additional: {
    data: [{ foo: { bar: 123 } }],
  },
};

Sentry.captureException(err);

@FabienCH
Copy link

Ok, thank you for your reply, I'll try to figure out where my problem comes from.

@rojomaldit
Copy link

I work only with normalizeDepth: 11

Sentry.init({ dsn: process.env.SENTRYDSN, debug: true, environment: process.env.NODE_ENV, enabled: process.env.SENTRY === 'true', logLevel: 1, integrations: [ new Sentry.Integrations.Http({ tracing: true }), ], normalizeDepth: 11, });

@lobsterkatie
Copy link
Member

Duplicate of #2539

@captbilard
Copy link

I work only with normalizeDepth: 11

Sentry.init({ dsn: process.env.SENTRYDSN, debug: true, environment: process.env.NODE_ENV, enabled: process.env.SENTRY === 'true', logLevel: 1, integrations: [ new Sentry.Integrations.Http({ tracing: true }), ], normalizeDepth: 11, });

Same here, adding only normalizeDepth worked for me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants