Instrumentation test error visibility #9979
Open
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.
What Does This Do
This improves visibility of errors in instrumentation tests built on top of
InstrumentationSpecificationby failing the test with details of the errors, in particular these cases:InstrumentationErrorsby the Byte BuddyExceptionHandlersclass.InstrumentationSpecification'sAgentBuilder.Listener.onError.Also,
ListWriterAssert.assertTraceswill now fail fast when the errors from the first two cases above are reported.Lastly, the code comment in
ExceptionHandlershas been updated to reflect the current implementation andInstrumentationContextexceptions are more explicit about the likely causes of why the methods might not have been rewritten.Motivation
These changes should reduce discovery and investigation time during development when there are instrumentation errors. Every single one of these issues are ones that I've run while developing instrumentations (most of them I've run into multiple times). ;-) These changes have helped me out enough (particularly for the first two use cases above) that I realized I really should see about contributing this back to help others--especially for those new to developing instrumentation, but also to assist those that have been doing it awhile when the inevitable error slips through.
Previously, the first error case above was not checked in tests using
InstrumentationSpecification, and was only visible in log output, and the other two error cases just included error counts. In all of these cases, the developer would have to go digging in log output to find existence and/or details of errors.When
ListWriterAssert.assertTraceswas used previously, if there were instrumentation errors that led to traces not being properly generated, tests will often fail due to failed assertions (missing spans, incorrect tags, etc.) and the developer might spend significant time chasing down the cause of the assertion failures to learn it was an instrumentation error. With these changes, if the cause was an underlying instrumentation error,ListWriterAssert.assertTraceswill fail fast for the first two use cases above and clearly indicate there was an instrumentation error.These changes will not only help our human developers by giving better context when there are failures, but also when using AI coding assistants.
Additional Notes
One possible improvement: The fail fast change could easily apply to all of the use cases above including the last use case if
InstrumentationSpecification'sAgentBuilder.Listener.onErrorrecorded the error toInstrumentationErrors.Best reviewed commit-by-commit:
Example output
InstrumentationErrors and InstrumentationContext exception
I commented-out the
contextStoremethod onHikariPoolInstrumentation.Contributor Checklist
type:and (comp:orinst:) labels in addition to any useful labelsclose,fixor any linking keywords when referencing an issue.Use
solvesinstead, and assign the PR milestone to the issueJira ticket: [PROJ-IDENT]