ApplicationInsights-JS icon indicating copy to clipboard operation
ApplicationInsights-JS copied to clipboard

Add `metadata` configuration object to TelemetryItem, for use in `.track(...)` function to enable customizing event property truncation threshold

Open MgenGlder opened this issue 5 months ago • 4 comments

[!NOTE] This is an early POC and draft. I'm looking for feedback and working through the best way to approach this addition.

References https://github.com/microsoft/ApplicationInsights-JS/issues/2383

Todo

  • [ ] Implement sanitization options for all event types, not just Event.
    • [ ] Dependency
    • [ ] Exception
    • [ ] Metric
    • [ ] PageView
    • [ ] Trace
    • [ ] PageViewPerformance
  • [ ] Add integration test around calling the .track function with metadata passed in, and having the maxLength configuration be respected.
  • [ ] Update public facing README.md docs with addition of configuration object and instructions and recommendations for how to use it.

Nice-To-Haves / Next Iteration Goals

  • It would be nice to have this configuration set when instantiating the ApplicationInsights client, and not passed every time you call the .track function. I'm limited by my understanding of the codebase at present, but I will look to attempt to add this in future iterations / PRs.

Summary

Enables customization for properties bag value truncation through a new metadata configuration object, passed through the .track(...) function.

Additions:

  • Add maxLength configuration to sanitizer.
  • Add metadata dictionary object to house user configurations when calling .track(...) function.

Context

We're using the ApplicationsInsights-web-basic npm package to make requests for an internal service that mimics the behavior of the ApplicationInsights managed service, sans the property size limit. We'd like to make it so you can configure the max length before truncation.

Use

You should now be able to pass a metadata object within your TelemetryItem when calling .track(...) via the ApplicationInsights client 👇🏾

let properties = [/* list of properties */]
let measurements = [/* list of measurements */]

let client = new ApplicationInsights({
            /* ... Other configuration properties ... */
            instrumentationKey: someKey,
            endpointUrl: someCustomUrl
            },
 });

this.client.track({
            name,
            tags: this.tags,
            data: {...properties, ...measurements},
            baseType: 'EventData',
            baseData: {name, properties, measurements},
            metadata: {
               "maxLength": 12000
           }
 });

Notes

This can be leveraged in the future for passing down custom configurations that can be used to override hard coded constants.

MgenGlder avatar Sep 20 '24 18:09 MgenGlder