Azure Application Insight. Custom attribute length restriction
Asked Answered
L

1

9

I'm using Azure App Insight as a logging tool and store log data by the following code:

    private void SendTrace(LoggingEvent loggingEvent)
    {
        loggingEvent.GetProperties();
        string message = "TestMessage";

        var trace = new TraceTelemetry(message)
        {
            SeverityLevel = SeverityLevel.Information
        };

        trace.Properties.Add("TestKey", "TestValue");
        var telemetryClient = new TelemetryClient();
        telemetryClient.Context.InstrumentationKey = this.InstrumentationKey;
        telemetryClient.Track(trace);
    }

everything works well. I see logged record in App insight as well as in App insight analytics (in trace table). My custom attributes are written in special app insight row section - customDimensions. For example, the above code will add new attribute with "TestKey" key and "TestValue" value into customDimensions section.

But when I try to write some big text (for example JSON document with more then 15k letters) I still can do it without any exceptions, but the writable text will be cut off after some document length. As the result, the custom attribute value in customDimensions section will be cropped too and will have only first part of document. As I understand there is the restriction for max text length which is allowed to be written in app insight custom attribute.

Could someone know how can I get around with this?

Levitate answered 20/7, 2018 at 16:3 Comment(0)
U
22

The message has the highest allowed limit of 32768. For items in the property collection, value has max limit of 8192.

So you can try one of the following options:

  1. Use message field to the fullest by putting the big text there.

  2. Split the data into multiple, and add to properties collection separately.

    eg:

    trace.Properties.Add("key_part1", "Bigtext1_upto8192");

    trace.Properties.Add("key_part2", "Bigtext2_upto8192");

Reference: https://github.com/MicrosoftDocs/azure-docs/blob/master/includes/application-insights-limits.md

Upton answered 20/7, 2018 at 16:37 Comment(4)
Is it possible to increase the length of the property collectionStamm
no, as they are enforced in backend and changes to the limits are unlikely to be entertained.Upton
How would chunking these logs work when using logging in a Python Azure Function? Today, my logs are created using logging.info() within the Function. App Insights logs are truncated when the Function runs large, multi-part uploads to a web service. I can't see the end of the log (the "Success" message).Bini
Another question: If I create App Insights alerts on one of these log messages, but the message is truncated, will the alert fire? My guess is no.Bini

© 2022 - 2024 — McMap. All rights reserved.