ApplicationInsights:Failed to read persisted file
ApplicationInsights:Failed to read persisted file [
SyntaxError: Unexpected token { in JSON at position 1286
at JSON.parse (<anonymous>)
at node_modules/applicationinsights/Library/Sender.ts:564:101
at FSReqCallback.oncomplete (fs.js:180:23)
at FSReqCallback.callbackTrampoline (internal/async_hooks.js:134:14)
This error occurs randomly.
CURRENT VERSIONS applicationinsights - v2.1.4 applicationinsights-native-metrics - v0.0.6
PREVIOUS VERSIONS applicationinsights - v1.8.10 applicationinsights-native-metrics - v0.0.6
I am also getting same error. Did you found the solution?
nope
@kevit-amish-faldu can you check following file and check the stored JSON events in there /tmp/appInsights-node/{YOUR_INSTUMENTATION_KEY} for Linux or USERDIR/AppData/Local/Temp/appInsights-node/{YOUR_INSTUMENTATION_KEY}, AI SDK will store telemetry in disk when it fails to deliver to ingestion endpoint, taking a look at the actual JSON may help us fix the issue.
There is no JSON file in the directory
@kevit-amish-faldu I can see now that AI SDK delete the file before trying to parse the JSON events, so when you hit this error it will not keep failing as the telemetry cannot be parsed and it is dropped, malformed JSON AI events could be caused by some extra properties added in the events using telemetryProcessors, sending custom events or adding extra custom properties to other events, common issues with parsing are related to unexpected commas. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Errors/JSON_bad_parse#json.parse_does_not_allow_trailing_commas
@hectorhdzg how can we find JSON that causing the error ? I mean in the error log it's giving trace of node modules only, so is there any way to add trace log to identify from where it's getting error to parse the JSON in the code?
@NiravMultani157 we don't add the full envelope in the Trace logs, mainly because of potential huge increase of telemetry size, something you can try is adding a telemetryProcessor and try to serialize the envelope to JSON, and do something when it fails, maybe store the envelope to disk or create a custom event with the envelope as a string property, telemetryProcessor code will be executed before we serialize and send to ingestion endpoint.
We're also encountering this with a slightly different "SyntaxError: Unexpected string in JSON"
We are not adding our own telemetryProcessors, sending custom events or adding extra custom properties to other events.
Could it be collecting the console logs causing the issue?
const appInsights = require('applicationinsights') appInsights .setup() .setAutoCollectConsole(true, true) appInsights.start()
@DevRCRun is possible, JSON serialization could happen with any field in the envelope, you can try what I suggested before to find which envelope is causing the issue.