Skip to content

Conversation

@adinauer
Copy link
Member

@adinauer adinauer commented Jan 9, 2026

📜 Description

💡 Motivation and Context

💚 How did you test it?

📝 Checklist

  • I added GH Issue ID & Linear ID
  • I added tests to verify the changes.
  • No new PII added or SDK only sends newly added PII if sendDefaultPII is enabled.
  • I updated the docs if needed.
  • I updated the wizard if needed.
  • Review from the native team if needed.
  • No breaking change or entry added to the changelog.
  • No breaking change for hybrid SDKs or communicated to hybrid SDKs.

🔮 Next steps

@github-actions
Copy link
Contributor

github-actions bot commented Jan 9, 2026

Fails
🚫 Please consider adding a changelog entry for the next release.
Messages
📖 Do not forget to update Sentry-docs with your feature once the pull request gets approved.

Instructions and example for changelog

Please add an entry to CHANGELOG.md to the "Unreleased" section. Make sure the entry includes this PR's number.

Example:

## Unreleased

### Features

- [Trace Metrics 24] PR Feedback ([#5013](https://github.com/getsentry/sentry-java/pull/5013))

If none of the above apply, you can opt out of this check by adding #skip-changelog to the PR description or adding a skip-changelog label.

Generated by 🚫 dangerJS against f502ffe

This was referenced Jan 9, 2026
Copy link
Member Author

adinauer commented Jan 9, 2026

This stack of pull requests is managed by Graphite. Learn more about stacking.

@adinauer adinauer changed the title Final keyword in Metrics methods feat(metrics): [Trace Metrics 24] PR Feedback Jan 9, 2026
@github-actions
Copy link
Contributor

github-actions bot commented Jan 9, 2026

Performance metrics 🚀

  Plain With Sentry Diff
Startup time 327.59 ms 385.98 ms 58.39 ms
Size 1.58 MiB 2.20 MiB 635.32 KiB

Baseline results on branch: 01-08-add_e2e_tests_for_metrics

Startup times

Revision Plain With Sentry Diff
527a476 352.67 ms 429.67 ms 77.00 ms

App size

Revision Plain With Sentry Diff
527a476 1.58 MiB 2.13 MiB 561.00 KiB

Comment on lines +55 to +57
if (isShuttingDown) {
return;
}
Copy link

Choose a reason for hiding this comment

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

Bug: A race condition in MetricsBatchProcessor.close(false) can cause metrics to be silently dropped during shutdown if a metric is added after the final flush has completed.
Severity: HIGH

Suggested Fix

To fix this, consider synchronizing the check for isShuttingDown and the addition to the queue within the add method. Alternatively, the shutdown logic could be revised to ensure that any items added to the queue after the executor is closed are still flushed, potentially by re-checking the queue in a synchronized block after the initial flush loop in close completes.

Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent.
Verify if this is a real issue. If it is, propose a fix; if not, explain why it's not
valid.

Location: sentry/src/main/java/io/sentry/metrics/MetricsBatchProcessor.java#L55-L57

Potential issue: A race condition exists in the `close(false)` method of
`MetricsBatchProcessor`. A metric-producing thread can pass the initial `isShuttingDown`
check just before a separate shutdown thread sets the flag to true, closes the executor,
and drains the queue. If the metric-producing thread then adds its metric to the queue,
the metric will be stranded. The subsequent call to `maybeSchedule` will fail with a
`RejectedExecutionException` because the executor is closed, leading to silent metric
loss and an inconsistent `pendingCount`.

Did we get this right? 👍 / 👎 to inform future reviews.

@adinauer
Copy link
Member Author

cursor review

Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

✅ Bugbot reviewed your changes and found no bugs!

Base automatically changed from 01-08-add_e2e_tests_for_metrics to feat/trace-metrics January 14, 2026 10:52
@adinauer adinauer merged commit 552940b into feat/trace-metrics Jan 14, 2026
42 of 65 checks passed
@adinauer adinauer deleted the 01-08-final_keyword_in_metrics_methods branch January 14, 2026 10:53
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.

3 participants