Report event submission failures that the Datadog client returns instead of raising - #22
Open
eastagiletracker wants to merge 1 commit into
Conversation
…not raise them when it is muted (the default), and passing them to handleError so that events rejected by the API are reported instead of being silently dropped.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR proposes reporting event submission failures that the Datadog client returns instead of raising, so that an event the API rejects reaches
handleErrorrather than disappearing without a trace. We include this PR work along with a full history of your repo at https://eastagiletracker.com/projects/298. You can sign in with your GitHub ID to claim ownership of the project.What this fixes
DatadogLogHandler.emitwraps the submission intry/except Exceptionand hands failures tohandleError— the reporting route added in #15, "so that the errors can be reported by the base Handler". Thedatadogclient, though, is muted by default (datadog.api._muteisTrueunless callers passinitialize(mute=False)), and in that modeapi_client.pycatchesApiError/ClientError, logs it on thedatadog.apilogger, and returns the error payload —{"errors": [...]}— to the caller. SoEvent.createdoes not raise for the everyday failures: a wrong or expired API key (403{"errors": ["Forbidden"]}), a payload the API rejects, or a connection error.emitreads that response as success, and the log record is dropped with nothing surfaced through the handler's own error reporting — which is what "nothing shows up in Datadog" looks like from the application side.Reproduced on
masterat fe4bc06, with a local server standing in for the Events API and answering the way Datadog answers a bad key:On
masterthe entire output is the localERROR:root:Oh no!line; the event never reached Datadog and the handler said nothing about it. With this change the standard logging error report follows it:The change captures what
Event.createreturns and, when the response carries errors, raisesApiErrorinside the existingtryso the failure takes the same route as a raised exception. A successful submission is untouched (the API answers{"status": "ok", "event": {...}}, and an emptyerrorslist is treated as success too), an unmuted client still raises and is handled exactly as before, and no name or signature in the package changes.Verification, on Python 3.12 with the locked dev dependencies:
pytest12 passed before, 15 passed after;flake8andmypy(strict) clean before and after. The newtest_emit_calls_handle_error_when_response_contains_errorsfails against the currentmasterhandler withAssertionError: Expected 'handleError' to be called once. Called 0 times.and passes with the change; the two companion tests asserthandleErrorstays out of the way for a successful response and for{"errors": []}, and pass in both trees.How this was managed
The work above was tracked as a single story, Report event submission failures that the Datadog client returns instead of raising, on a board at https://eastagiletracker.com/projects/298 that was populated from this repository's own issues and pull requests (21 stories, 3 labels), so the history you see there is yours.
If you'd rather not receive contributions like this, reply
no-more-prson this pull request and we won't open any further ones on your repositories.Lawrence W. Sinclair
CEO / East Agile
linkedin.com/in/lwsinclair/
eastagile.com