Repository navigation
Make decorator exception safe 1/3 - #11998
PerfectSlayer wants to merge 7 commits into
Conversation
This comment has been minimized.
This comment has been minimized.
84a8583 to
e1206aa
Compare
🟢 Java Benchmark SLOs — All performance SLOs passed
PR vs. master results
Commit: Load and DaCapo benchmarks can be triggered manually in the GitLab pipeline. Results will appear in the Benchmarking Platform UI after completion. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 5e4fd8b9d1
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
There was a problem hiding this comment.
In OpenAiDecorator.doBeforeFinish, the override incorrectly calls super.doBeforeFinish(span) instead of super.doBeforeFinish(context): span is derived from the context via fromContext and can be null (violating @Nonnull), and even when non-null it is semantically wrong — the original context may carry additional keyed data that would be silently dropped if a parent class ever adds a non-empty doBeforeFinish body. The fix — already committed — is a one-line change to pass context instead of span.
📊 Validated against 6 scenarios · Open Bits AI session
🤖 Datadog Autotest · Commit 5e4fd8b · What is Autotest? · Any feedback? Reach out in #autotest
| Decorator lifecycle hooks (`onError`, `beforeFinish`, …) are called from advice around | ||
| `scope.close()` / `span.finish()`, so a decorator that throws would leak scopes and spans — and | ||
| force every call site into defensive `try/finally` blocks. To prevent this, decorators make | ||
| these public methods `final` and routes them through an exception barrier that logs and swallows any |
There was a problem hiding this comment.
| these public methods `final` and routes them through an exception barrier that logs and swallows any | |
| these public methods `final` and route them through an exception barrier that logs and swallows any |
| protected void finishInferredProxySpan(Context context) { | ||
| InferredProxySpan inferredProxySpan; | ||
| if ((inferredProxySpan = InferredProxySpan.fromContext(context)) != null) { | ||
| inferredProxySpan.finish(AgentSpan.fromContext(context)); |
There was a problem hiding this comment.
I'd keep AgentSpan.fromContext throughout here as the class tells what it's extracting
|
|
||
| protected void doOnError( | ||
| @Nullable final AgentSpan span, @Nullable final Throwable throwable, byte errorPriority) { | ||
| if (throwable != null && span != null) { |
There was a problem hiding this comment.
WDYT about moving these null checks to the outermost onError methods, like you did for beforeFinish?
That way anyone extending doOnError won't have to check them again
mcculls
left a comment
There was a problem hiding this comment.
Nice improvement - just a small suggestion about moving the null checks out of doOnError and into the respective onError final methods
|
Merged in #12017 |
What Does This Do
This is a follow up of #11951 and proposes an improvement to instrumentation API decorators to make them "exception safe".
The main ideas are:
beforeFinishto call /doBeforeFinishto implementation, where safety is done onbeforeFinishthat can't be overridden.Additionally:
onEventwith null values when the even did not happen),Motivation
The goal is to simplify how write instrumentations, and make the dumb way safe.
Additional Notes
This part is part of stack PRs:
Contributor Checklist
type:and (comp:orinst:) labels in addition to any other useful labelsclose,fix, or any linking keywords when referencing an issueUse
solvesinstead, and assign the PR milestone to the issueJira ticket: [PROJ-IDENT]