Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Track exceptions in Application Insights publisher #302

Merged

Conversation

inkel
Copy link
Contributor

@inkel inkel commented Oct 15, 2019

This PR implements exception tracking on App Insights as described in #299.

My initial reaction was to add this only in the detailed report, but then I realized that I wanted to have the exceptions tracked, regardless of whether it's a detailed or summarized report.

While working on this I also found that it could be possible to refactor the code to be more DRY (e.g. creating the properties dictionary could be extracted to a method), and also that by using a mock TelemetryChannel tests could be added for this publisher. I didn't include those changes because I think they're out of the scope of this PR description.

Previous version ignored reporting any exception contained in
reports. Most of the Xabaril health checks do send a value for
HealthCheckResult.Exception when the check fails, but they weren't
being reported to App Insights.

Note that there is lot of room for improvements on this class, so far
I've only added a simple additional method to track exceptions.
Copy link
Collaborator

@unaizorrilla unaizorrilla left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @inkel

Can you check my comments on this PR?

return Task.CompletedTask;
}
private void TrackExceptions(HealthReport report, TelemetryClient client)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the health report contains exception, you can save also detailed report and exception? probably detailed and generalized report will contain exception information without create any other method

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a good question. Initially, I was going to TelemetryClient.TrackException only in the detailed report, but I think it's information you would like to have even in the summary report, that's why I've added the TrackExceptions method.

Also, note that for detailed report you could choose to not report healthy results; it probably doesn't make much sense but it could happen that a report is healthy but it also includes an exception and this is why the TrackExceptions method is called regardless you choose a summary or detailed report.


public ApplicationInsightsPublisher(string instrumentationKey = default, bool saveDetailedReport = false, bool excludeHealthyReports = false)
public ApplicationInsightsPublisher(string instrumentationKey = default, bool saveDetailedReport = false, bool excludeHealthyReports = false, bool trackExceptions = true)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How you can change TrackException parameters? probably you need to add a new overload or default parameter on ApplicationInsightsHealthCheckBuilderExtensions.cs

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are correct, I was going to add a default on ApplicationInsightsHealthCheckBuilderExtensions. Again, the plan is adding a default bool trackExceptions = true rather than false because I think having a report on exceptions happened is something one would like for default (at least I know it's what I wanted).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've add the parameter to the extension method in 0c2e389.

@inkel
Copy link
Contributor Author

inkel commented Oct 21, 2019

@unaizorrilla thanks for the comments! I've left some answers, and I'll be working on some of those suggestions.

I'll also try to add a basic test for this new operation.

inkel added 2 commits October 21, 2019 10:42
This commit only includes tests for tracking exceptions in
ApplicationInsightsPublisher. Tests for existing tracking methods are
left until this one is approved or rejected. If approved I'll add the
tests in a new pull request, as adding those is out of the scope of
the current pull request Xabaril#302.
@inkel inkel force-pushed the appinsights-publisher-track-exceptions branch from 0c2e389 to 52d77d9 Compare October 21, 2019 14:19
While at it add some simple unit tests for this extension method.
@inkel inkel force-pushed the appinsights-publisher-track-exceptions branch from 52d77d9 to 9a85635 Compare October 21, 2019 14:23
@inkel
Copy link
Contributor Author

inkel commented Oct 21, 2019

@unaizorrilla I've made some changes and added some tests, I think it's ready for another round of review. Thank you!

@unaizorrilla
Copy link
Collaborator

Hi @inkel

I try to review this again today!

@unaizorrilla
Copy link
Collaborator

I'm so sorry for delaying on review the PR! :-( I try to do ASAP

@inkel
Copy link
Contributor Author

inkel commented Oct 30, 2019

@unaizorrilla don't worry about it! 😸

While at it add some simple unit tests for this extension method.
@unaizorrilla unaizorrilla merged commit 0e62a0b into Xabaril:master Nov 6, 2019
@unaizorrilla
Copy link
Collaborator

Hi @inkel

I perform some changes in the pr and merge it to master, many thanks to contribute on this.

My changes try to preserve your intention, track exception on ai also as part of telemetry information. But I consider to do only when you set detailed reports and not a separate method.

Also I need to work more on unit test to improve our coverage...

Thanks again to contribute and so sorry to do changes in your pr withut normal way

@inkel
Copy link
Contributor Author

inkel commented Nov 6, 2019

@unaizorrilla hi, thanks! I'm more than ok with you making changes 😸 though for some reason GitHub is not showing those to me. Anyway, thanks for being open to receive, review and merge this PR ❤️

Also I need to work more on unit test to improve our coverage...

Would you like me to help you with that? One of the reasons I've added the tests for this publishe was that secretly I planned on submitting another PR that added more tests to it for the existing features 😊

@inkel inkel deleted the appinsights-publisher-track-exceptions branch November 6, 2019 13:32
@sungam3r sungam3r mentioned this pull request Jul 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants