Skip to content

ExceptionTelemetry with large / deep stack traces are silently omitted #482

Closed

Description

@larsgx

When using the Logback appender ApplicationInsightsAppender and so indirectly the components of the applicationinsights-core artifact from
com.microsoft.azure:applicationinsights-logging-logback:1.0.9
com.microsoft.azure:applicationinsights-core:1.0.9
where is a problem with log statements that include an exception with deep / long stack traces (ExceptionTelemetry).

Deep stack traces are being serialized as event JSON object correctly which has been verified by debugging the applicationinsights-core code.
But when the resulting JSON of the parse stack (shown in Insights Analytics as "details.parsedStack" and stored in Java class ExceptionTelemetry.ExceptionData.ExceptionDetails.parsedStack) exceeds as certain size (which seems to be 32k according to https://github.com/Microsoft/ApplicationInsights-Home/blob/master/EndpointSpecs/Schemas/Docs/ExceptionData.md), the complete log statement is omitted and not shown in Azure Insights Analytics.

I'm not 100% sure if the ExceptionTelemetry is omitted by applicationinsights-core or by Azure Insights instance itself.
But everything indicates that Azure Insights is receiving the JSON and omitting it remotely.

Omitting an ExceptionTelemetry silently is a very problematic behaviour from a development and operations point of view.
The artifact applicationinsights-core or Application Insights itself should know and respect the Azure Insigts limits and provide a robust behaviour:
If stack traces exceed the given limits, at least the log statement without the deep "parsed stack trace" should be stored and shown in Analytics.
Otherwise application exceptions will never be recognized which is a no-go for a monitoring platform.

Activity

  1. dhaval24 commented on Dec 8, 2017

    @dhaval24
    Contributor

    @LarsGielsok, I see your point here and it is very valid. Here is my understanding:

    1. Application Insights Java SDK - used to run on old schema definition which had lower limits of accepting the stack trace details apparently 1024 character until SDK v1.0.10 where we updated to new schema which supports 32k.
    2. From the SDK v1.0.10 when the exception message exceeds the size of 32k then we truncate it to 32k and still report it to the portal.

    Have you got a chance to try the Application Insights SDK v1.0.10?

  2. larsgx commented on Dec 8, 2017

    @larsgx
    Author
  3. dhaval24 commented on Dec 8, 2017

    @dhaval24
    Contributor

    Yes there was an issue with sanitization and setting the severity level whose changes are already merged in master. So hopefully that should fix this issue also.

  4. larsgx commented on Dec 9, 2017

    @larsgx
    Author

    when do you plan to release this fix? Is there any workaround in the meanwhile?

  5. dhaval24 commented on Dec 9, 2017

    @dhaval24
    Contributor

    @LarsGielsok we plan to release the new version by end of next week most probably if things go right. In the mean while I would be very happy if you would have a chance to build the SDK locally and try and test it out. In this way we would come to know if any issues still persist (however we haven't noticed it on our test applications). Here are the steps to build the SDK locally :

    1. Fork the repository.
    2. Run the following gradle commands from the command prompt the location
      gradlew clean, gradlew assemble, gradlew test and gradlew build.
    3. You would need JDK 1.7 / 1.8 and Gradle 3.5 to build this project.
    4. core, web and agent jars would be found in the respective directories of the project.

    Please give it a shot if you have some time. Also I would like to point you to #468 and #469 for our future SDK release plan and just in case you are interested to complete brief survey.

  6. dhaval24 commented on Dec 13, 2017

    @dhaval24
    Contributor

    @LarsGielsok were you able to try building the SDK locally? The Master branch is now most upto-date and you can build master directly.

  7. larsgx commented on Dec 13, 2017

    @larsgx
    Author
  8. dhaval24 commented on Dec 14, 2017

    @dhaval24
    Contributor

    @LarsGielsok oh, I see. We might have to dig more into this. We plan to release the SDK 2.0.0-BETA soon so I think it would be hard to lock down this particular issue into the upcoming release. I would investigate this further and update the thread. Hopefully we can get it down in 2.0.1 patch release. (Thank you very much for trying). In the mean while if you find some sort of possible solution which might be lying inside ExceptionTelemetry.java class feel free to send out a PR. Note that max size supported by the end point is 32k. We prune if the size exceeds the max size.

  9. added this to the 2.0.1 milestone on Jan 3, 2018
  10. dhaval24 commented on Jan 3, 2018

    @dhaval24
    Contributor

    @LarsGielsok there is a PR out there #507 which will fix this issue. Feel free to have a look if you wish to. The max size of exception depth we would allow is 10 (To be in sync with our other SDKs). Also the max size of the parsed stack which would be allowed is 32768 chars.

  11. larsgx commented on Jan 11, 2018

    @larsgx
    Author
  12. dhaval24 commented on Jan 11, 2018

    @dhaval24
    Contributor

    @LarsGielsok thank you very much for this constructive feedback and taking time to try out the PR. It's much valuable and that's why the PR is not yet merged. Yes I agree with you that the size restriction might be for the entire Packet that gets sent to AI endpoint. Also it might be the case that the implementation of getStackFrameSize() might be too basic. Do you have any better suggestion on how we can efficiently compute the size of stackFrame() {i.e what all parameters to count for etc.} . Also the idea behind this was that if the size exceeds truncate with a self exception indicating truncation.

    Further, clearly your experiment by reducing the size to 20k shows that issue is pertaining to the size of the item. If you have any better approach on how to do this, it would be great. Looking forward to hear.

  13. 2 remaining items

  14. vlev commented on Jan 8, 2019

    @vlev

    Hi guys,

    I think one of the approaches to mitigate this issue could be a parameterization of maximum exception's graph length and trace depth (per exception).

    We could add two parameters in TelemetryConfiguration (also in XML and SB config): exceptionDepth and traceDepth.
    ExceptionTelemetry.convertExceptionTree method is already able to cut the exceptions graph's length.
    Adding capability of cutting trace length should be relatively easy to implement.

    If you are ok with this approach, I could provide the PR.

  15. vlev commented on Jan 8, 2019

    @vlev

    Also, I've found that RuntimeExceptionDecider (from module "agent") can use stackTrace property (which is actually treated as a cap on exceptions graph length). It seems that this property can be configured via "stackSize" element. Maybe it's worth keeping this property name for back compatibility reasons even though it doesn't reflect actual use case.

  16. dhaval24 commented on Jan 17, 2019

    @dhaval24
    Contributor

    vlev that seems very interesting approach. We always appreciate any contributions. I would suggest that you create another issue, and elaborate your apporach a bit more there. You can then create a PR for it. Your contribution would be greatly appreciated.

  17. gondar commented on May 6, 2019

    @gondar

    Is there any news on this issue Dhaval Doshi (@dhaval24) we just recently found out that not all exceptions are logged to application insights. That was very confusing for us. Simple reproduction is just trying to log stackOverflow exception e.g compare following:

    private void doInfiniteLoop() {
        doInfiniteLoop();
    }
    
    public void logStackOverflow() {
        try {
            doInfiniteLoop();
        } catch (StackOverflowError ex) {
            log.info("Logging StackOverflow");
            log.error("StackOverflow", ex);
        }
    }
    
    public void logSimple() {
        try {
            throw new Exception("Oh Dear!");
        } catch (Exception ex) {
            log.info("Logging Simple");
            log.error("Simple", ex);
        }
    }
    
  18. dhaval24 commented on May 6, 2019

    @dhaval24
    Contributor

    Marcin Bazydlo (@gondar) I have responded on the vlev 's PR. Arthur Little (@littleaj) / Trask Stalnaker (@trask) might have more context and can help you more : Let me know if the processor example provided there works for you.

  19. ghost locked as resolved and limited conversation to collaborators on Jul 21, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions