Skip to content

Conversation

@Harriethw
Copy link
Contributor

@Harriethw Harriethw commented Oct 17, 2025

Description

Follow the pattern set out with the Retry and Create Appt. command,
this ensures that any exceptions are captured by
Insights and we can monitor and alert on them.

Happy to go through the Insights UI to show how this feeds through, and there's more context on Jira

Screenshot 2025-10-17 at 12 20 22

Jira link

https://nhsd-jira.digital.nhs.uk/browse/DTOSS-11239

Review notes

@Harriethw Harriethw marked this pull request as ready for review October 17, 2025 16:13
@Harriethw Harriethw requested a review from a team October 17, 2025 16:13
Copy link
Contributor

@steventux steventux left a comment

Choose a reason for hiding this comment

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

Looks good, the commit around making the try...except block more obvious got me thinking about how we could formalise the common exception handling in another PR.

)
self.create_reports(options)
except Exception as e:
ApplicationInsightsLogging().exception(f"{INSIGHTS_ERROR_NAME}: {e}")
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we also need to log an exception and stack trace here? Perhaps already missing from this command. I'm just trying to identify if there is a pattern of:

logger.exception("Something bad", exc_info=True)
ApplicationInsightsLogging().exception(f"TheError: {e}")
raise CommandError(e)

in every command and if so how we could roll this up into one distinct contextmanager like:

with CommandExceptionHandler():
   do_some_stuff()
   do_more()
   and_some_more()

And CommandExceptionHandler would do the logging, AppInsights logging and reraise the exception.
Just an idea and not for this PR

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Logging to the Application Insights Logger also logs to stdout so there's no need to duplicate calls like that, afaik

Copy link
Contributor Author

Choose a reason for hiding this comment

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

but otherwise yep could bundle it all into some kind of shared wrapper!

As with the Retry command, this ensures any
exceptions thrown by job will be caught.
to make it clearer that everything is in try/catch
block
@Harriethw Harriethw force-pushed the DTOSS-11239-create-report-monitoring branch from e2d1ef9 to 001da38 Compare October 24, 2025 08:43
@Harriethw Harriethw merged commit 48f6ad4 into main Oct 24, 2025
12 checks passed
@Harriethw Harriethw deleted the DTOSS-11239-create-report-monitoring branch October 24, 2025 08:50
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