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

Do not know how to serialize a BigInt #1249

Open
brianpham93 opened this issue Dec 2, 2023 · 7 comments
Open

Do not know how to serialize a BigInt #1249

brianpham93 opened this issue Dec 2, 2023 · 7 comments

Comments

@brianpham93
Copy link
Contributor

brianpham93 commented Dec 2, 2023

I use winston and winston-azure-application-insights to log directly to application insights
I'm getting this error when log an object that contains BigInt data

ApplicationInsights:Failed to serialize payload [
  TypeError: Do not know how to serialize a BigInt
      at JSON.stringify (<anonymous>)
      at Util.stringify (./my-project/node_modules/applicationinsights/out/Library/Util.js:373:25)
      at EnvelopeFactory.truncateProperties (./my-project/node_modules/applicationinsights/out/Library/EnvelopeFactory.js:135:60)
      at EnvelopeFactory.createTraceData (./my-project/node_modules/applicationinsights/out/Library/EnvelopeFactory.js:153:33)
      at EnvelopeFactory.createEnvelope (./my-project/node_modules/applicationinsights/out/Library/EnvelopeFactory.js:24:40)
      at TelemetryClient.track (./my-project/node_modules/applicationinsights/out/Library/TelemetryClient.js:134:44)
      at TelemetryClient.trackTrace (./my-project/node_modules/applicationinsights/out/Library/TelemetryClient.js:60:14)
      at ./my-project/node_modules/applicationinsights/out/AutoCollection/diagnostic-channel/winston.sub.js:55:20
      at Array.forEach (<anonymous>)
      at subscriber (./my-project/node_modules/applicationinsights/out/AutoCollection/diagnostic-channel/winston.sub.js:40:13)

Does ApplicationInsights support BigInt or is there anything wrong with the way i'm logging data ?

Version: 2.9.1
Host: macOS 14, Apple Silicon

@brianpham93 brianpham93 changed the title ApplicationInsights:Failed to serialize payload Do not know how to serialize a BigInt Dec 2, 2023
@hectorhdzg
Copy link
Member

@brianpham93 looks like the issue is in JSON.stringify, after a quick internet search looks like some type replacement can be done to prevent this error, can you share some sample winston log we can use to reproduce?

@JacksonWeber
Copy link
Contributor

@brianpham93 Did you have any luck with your serialization issue?

@brianpham93
Copy link
Contributor Author

@brianpham93 Did you have any luck with your serialization issue?

i'm using this working around temporarily

BigInt.prototype.toJSON = function () {
	return this.toString();
};

@JacksonWeber
Copy link
Contributor

@brianpham93 Is there anything about your scenario that makes converting the Big Int to a string not work for you in the long term?

@brianpham93
Copy link
Contributor Author

@JacksonWeber So far i haven't found out any issue with current approach

@JacksonWeber
Copy link
Contributor

@brianpham93 Awesome! Mind if I mark this issue as complete in that case?

@brianpham93
Copy link
Contributor Author

@JacksonWeber No issue. It would be better if this is supported natively in app insights via a separate PR

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

3 participants