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.

[BUG] trackTrace with ICustomProperties does not allow numeric values

See original GitHub issue

I’m using applicationinsights-web with an Angular application. When logging a trace message using a custom properties object, any values which are not strings are ignored (with no error message). If I intercept the properties object and convert the values to strings then all the values are logged as expected. As far as I understand the index signature { key: string]: any } should allow numeric values to be logged?

Example of logging code with the workaround in place:

logTrace(
    message: string,
    severityLevel: SeverityLevel,
    properties?: { [key: string]: any }
  ) {
    // convert the properties object into keys with only string values
    Object.keys(properties).forEach(k => { properties[k] = properties[k].toString() })

    this.appInsights.trackTrace(
      { message: message, severityLevel: severityLevel },
      properties
    );
  }

Steps to Reproduce

this.appInsights = new ApplicationInsights({
    config: {
      connectionString: config.connectionStringAI,
      enableAutoRouteTracking: true,
      disableFetchTracking: false, 
      enableUnhandledPromiseRejectionTracking: true, 
    },
  });
  this.appInsights.loadAppInsights();
  this.appInsights.addTelemetryInitializer((envelope) => {
    envelope.data.appVersion = environment.appVersion;
    envelope.tags['ai.cloud.role'] = 'IonicAngularApp'; 
  });

Issues #1737 and #1057 may be related?

Expected behavior Numeric or boolean or other types should be logged against object keys (strings) in object with type ICustomProperties

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:1
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
MSNevcommented, Mar 10, 2022

@Karlie-777 can you please investigate this a bit further (create a repro and a unit test for the issue and then address any issues).

For reference get flattened, stringified or ignored altogether. is the design but the ignored should be causing some logging / failures (for exceptions), this may only currently be documented in the code so we should add this somewhere more visible as per @baxxos suggestion.

I don’t think we want to change the ICustomProperties to be specific as I’m aware of several internal / external users the use the get flattened (JSON.stringify()) functionality of the any aspect.

1reaction
baxxoscommented, Mar 10, 2022

The properties interface is defined in a way that allows us to pass in any kind of value - e.g. a deeply nested object, but from my experience, it only works reliably with strings. More complex values will either get flattened, stringified or ignored altogether.

Example:

appInsights?.trackTrace({
  message,
  severityLevel: SeverityLevel.Information,
  properties: {
    level1: { level2: { level3: 'level3value' } },
  },
})

results in: image

It would be nice to define the ICustomProperties in a way that would reflect only the supported data types or describe the value processing behavior in documentation.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Send custom complex properties to Telemetry to Azure Portal ...
The problem is with the SDK version. In Azure portal and in tags property from browser AJAX calls it shows that i'm using...
Read more >
Tracing and logging with Application Insights - Andrei Dzimchuk
Metrics allow you to send numeric data such as time measurements or uploaded data size that you want to be associated with the...
Read more >
Azure Application Insights for JavaScript web apps
Add the JavaScript SDK; Configuration; Cookie handling; Enable ... If you use the npm setup, don't use the snippet and vice versa.
Read more >
Azure Application Insights series part 1: How to instrument ...
Instrumentation is code added to an application that allows us to ... Note: The instrumentation key is not considered a secret value.
Read more >
Error.prototype.stack - JavaScript - MDN Web Docs - Mozilla
Value. A string. Because the stack property is non-standard, implementations differ about where it's installed.
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