microsoft / ApplicationInsights-node.js

Microsoft Application Insights SDK for Node.js
MIT License
323 stars 141 forks source link

Logs of some users get saved on other users. #941

Open Devir0R opened 2 years ago

Devir0R commented 2 years ago

Description/Screenshot image image The Red marking hides once name, call it A, and the blue marking hides another name, call it B

this code is an interceptor that sits on all of the incoming requests. in the first image it shows "user assigned" and this bit of code responsible for it. this image shows the incorrect logging about the users, the passenger is unique per ID, so there shouldn't be different names for different users, but there are. The problem happens only for users with whose transaction are close. there are other instances of the problem in other parts of the code, but I sent one.

when I run the next query in appinsights logs: 'traces | where user_Id == XXX' I get different names for the same id, the second image demonstrate the issue.

how come the same ID get differently named users saved on it?

Thanks.

hectorhdzg commented 2 years ago

The context is used to build the telemetry envelopes that eventually would be send to ingestion endpoint, every "track" call will use it, having different user_id properties mean your "intercept" method is called multiple times before the envelope is created in Application Insights, you must be able to ensure the correct user_id is being passed manually calling trackTrace API and providing the property.

Devir0R commented 2 years ago

Can you elaborate more?

hectorhdzg commented 2 years ago

You could use Application Insights APIs to manually call trackTrace with the correct custom property you are adding, https://github.com/microsoft/ApplicationInsights-node.js#track-custom-telemetry

Eden1999 commented 2 years ago

@hectorhdzg Hello! We've tried your advice, but we ran into a problem. When we set the user id as a custom property we can see in the logs that the user id was set, but we see it as a new custom property and not as a custom event property as we can see below. image

Therefore, we cannot filter users by the original names of the properties. Is there a way to override the custom event properties when you manually provide the properties to the trackEvent (or any other track) ?

Thanks!

hectorhdzg commented 2 years ago

@Eden1999 you can pass tagOverrides as well when calling trackEvent API, something like this:

let tagOverrides = {}; tagOverrides["ai.user.id"] = "TestUser"; appInsights.defaultClient.trackEvent({ name: "TestEvent", tagOverrides: tagOverrides });