question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

trackTrace model being manipulated to invalid

See original GitHub issue

Hello,

We have used AppInsights JS SDK for quite a while now (currently on v2.7.2). Recently we noticed in our logs we were not receiving everything we’re sending. Upon inspection it appears that sometimes when we use trackTrace the simple object of message (string), properties (object), and severityLevel (number) is being malformed and is causing the request to come over as an object instead.

While this is not according to spec it also does not always complain about this. Sometimes the message as an object is allowed and other times a 400 error is thrown. I have checked all of our code and we are passing a string for the message and an object for properties to the AppInsights JS SDK. This means something in the SDK is somtimes malforming the message to be an object with a message and properties property in it. Below are some example requests that are sent to the SDK as well as what the SDK sends to the server and what the server sends back:

Example 1: Requests submitted to SDK:

{
     message: "modules/a-module.connect() id=asdf-asdf-asdf-asdf",
     properties: {
          simulated: "false"
     },
     severityLevel: null
}
{
     message: "modules/a-module.discoveryResult() devices(s)",
     properties: [
          0: {
               label: "Device A",
               status: "online"
          },
          1: {
               label: "Device B",
               status: "offline"
          },
     ],
     severityLevel: null
}

Request submitted to server from SDK (removing some properties for brevity):

[
     0: {
          data: {
               baseData: {
                    message: "modules/a-module.connect() id=asdf-asdf-asdf-asdf",
                    properties: {
                         simulated: "false"
                    },
                    ver: 2
               },
               baseType: "MessageData"
          }
     },
     1: {
           data: {
                baseData: {
                     message: {
                          message: "modules/a-module.discoveryResult() devices(s)",
                          properties: [
                               0: {
                                    label: "Device A",
                                    status: "online"
                               },
                               1: {
                                    label: "Device B",
                                    status: "offline"
                               },
                          ],
                          severityLevel: null
                     },
                     properties: {},
                     ver: 2
                },
                baseType: "MessageData"
           }
      }
]

Note that in the above the first instance is correct (message is a string, properties is an object) and the server accepts it. In the second instance we have a malformed request now where message is now an object with properties message (string), properties (object), and severityLevel (number). The server still accepts this request and I can see both of these in the logs. Also to note is the first example does not have severityLevel in the SDK request but the second one does. In both instances our code sent a null for severityLevel.

Response from server:

{
     errors: {},
     itemsAccepted: 2,
     itemsReceived: 2
}

Example 2: Requests submitted to SDK:

{
     message: "modules/a-module.selectDevice()",
     properties: {
          label: "Device A",
          status: "online"
     },
     severityLevel: null
}

Request submitted to server from SDK (removing some properties for brevity):

[
     0: {
           data: {
                baseData: {
                     message: {
                          message: "modules/a-module.selectDevice()",
                          properties: [
                               0: {
                                    label: "Device A",
                                    status: "online"
                               }
                          ],
                          severityLevel: null
                     },
                     properties: {},
                     ver: 2
                },
                baseType: "MessageData"
           }
      }
]

In the above in this example it’s the same as the second request in the first example in terms of structure where message is not a string as it should be but rather an object with properties of message (string), properties (object), and severityLevel (number). Unlike the first example though, this rejected by the server and we cannot see it in the logs.

Response from server:

{
     errors: [{
          0: {
               index: 0,
               message: "106: Field 'message' on type 'MessageData' is of incorrect type. Expected: string, Actual: [object Object]",
               statusCode: 400
          }
     }],
     itemsAccepted: 0,
     itemsReceived: 1
}

There appears to be some issue within the SDK that is sometimes malforming the message to include other things like properties. This is causing the server to receive an object instead of a string. Additionally the server only sometimes rejects the malformed message object as bad. This is causing us to be partially blind into the actions the code is taking when there are issues. Our code only passes an object with properties message (string), properties (object), and severityLevel (number) to the trackTrace method. However for some reason sometimes the request the SDK sends to the server is correct and sometimes it is not. Likewise sometimes the server accepts the incorrect message object and other times rejects it.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:11 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
bgp1commented, Jan 13, 2022

Thanks for standing by. We’ve been in production with these changes for several days now and can confirm we are receiving all logging messages now vs before when it was only some. Removing the injected script from our views using the Nuget package was the issue causing the conflict.

0reactions
github-actions[bot]commented, Nov 15, 2022

This Issue will be closed in 30 days. Please remove the “Stale” label or comment to avoid closure with no action.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Diagnose exceptions in web apps with Application Insights
TrackEvent is typically used for monitoring usage patterns, but the data ... TrackTrace lets you send longer data such as POST information.
Read more >
ApplicationInsights-JS/Initialization.ts at master - GitHub
* approach is to create a new instance and initialize that instance. * This is due to possible unexpected side effects caused by...
Read more >
Disable Trace/Track in Apache HTTPD - Techstacks HOWTO's
TRACE is enabled by default in an apache installation. There are two ways to remediate. The first can be used if you are...
Read more >
What is the printStackTrace() method in Java? - Educative.io
The printStackTrace() method in Java is a tool used to handle exceptions and errors. It is a method of Java's ... public static...
Read more >
Tracing vs Logging vs Monitoring: What's the Difference?
Logging should be used in big applications and it can be put to use in ... When something inevitably goes wrong, such transformations...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found