sentry-java
sentry-java copied to clipboard
Add metrics API
:scroll: Description
Add metrics API to support delightful developer metrics. This PR intends to provide the basic functionality:
- Metrics API for counters, sets, gauges, distributions and timings
- A
MetricAggregatorto locally aggregate into 10s buckets - Flush / Closing functionality
- Hub integration
- Sending over the aggregated metrics using the new
statsdenvelope type
:question: Open Topics / Missing items
✅ How should the API entrypoint look like?
The aggregator is part of the hub, so it's either
IHub.getMetricsApi()and our typical convenienceSentry.getMetricsApi()shortcut. It should definitely be in a sub-space, as all the different metrics, likeSentry.increment()would just pollute our top level namespace.
After some discussion, let's go for Sentry.metrics().increment(...)
✅ Is it "Metric" or "Metrics"?
Let's go for metrics, as the aggregator actually deals with multiple of them.
✅ Rate Limiting / Caching
I need to check if we need special handling for metrics on this.
✅ Automatically add global tags (e.g. release, environment)
✅ Add more tests, especially for the aggregator
✅ Use CR32 for hashing Strings values for set metrics
Out of scope / Will be done with follow up PR
- Recording and sending code locations for metrics
- Any span handling / local span aggregation
:bulb: Motivation and Context
Implements first parts of https://github.com/getsentry/sentry-java/issues/3190
:green_heart: How did you test it?
Added unit tests, taking some inspiration from https://github.com/getsentry/sentry-python/blob/master/tests/test_metrics.py and .NET
:pencil: Checklist
- [x] I reviewed the submitted code.
- [x] I added tests to verify the changes.
- [x] No new PII added or SDK only sends newly added PII if
sendDefaultPIIis enabled. - [ ] I updated the docs if needed.
- [x] Review from the native team if needed.
- [x] No breaking change or entry added to the changelog.
- [x] No breaking change for hybrid SDKs or communicated to hybrid SDKs.
:crystal_ball: Next steps
| Messages | |
|---|---|
| :book: | Do not forget to update Sentry-docs with your feature once the pull request gets approved. |
Generated by :no_entry_sign: dangerJS against 9b1f4aaf4abdcd29607aaf43a7a2fedaad513c6a
Performance metrics :rocket:
| Plain | With Sentry | Diff | |
|---|---|---|---|
| Startup time | 300.54 ms | 361.31 ms | 60.76 ms |
| Size | 1.70 MiB | 2.28 MiB | 590.47 KiB |
Baseline results on branch: main
Startup times
| Revision | Plain | With Sentry | Diff |
|---|---|---|---|
| 0810952c95d04ff7e1b4be22b386cec9c79016d4 | 364.51 ms | 468.08 ms | 103.57 ms |
| 2fad834b55abd8bcbc05a5110122ad3e44fe4f92 | 390.07 ms | 470.80 ms | 80.73 ms |
| 2465853df157c4ad881166804873989c47c10f4d | 422.61 ms | 491.20 ms | 68.58 ms |
| 8ff8fd047e817d4c017858d44c2681c6a8ac4e52 | 432.77 ms | 495.18 ms | 62.41 ms |
| 2465853df157c4ad881166804873989c47c10f4d | 400.64 ms | 465.47 ms | 64.83 ms |
| 5e04ee8e63c5617dbc4c2b9706b866e8823cec20 | 365.26 ms | 448.49 ms | 83.23 ms |
| c554ca260c5f0fa79a30d592f6c0e08a850a5014 | 368.52 ms | 430.74 ms | 62.22 ms |
| 4e290632c3083233d83c696533ee1e0d284dfd42 | 384.14 ms | 447.74 ms | 63.60 ms |
| 0404ea31dd7e67983b3aa0133a0dc4fb6b983884 | 394.73 ms | 461.79 ms | 67.06 ms |
| 0404ea31dd7e67983b3aa0133a0dc4fb6b983884 | 332.47 ms | 401.12 ms | 68.66 ms |
App size
| Revision | Plain | With Sentry | Diff |
|---|---|---|---|
| 0810952c95d04ff7e1b4be22b386cec9c79016d4 | 1.72 MiB | 2.27 MiB | 558.21 KiB |
| 2fad834b55abd8bcbc05a5110122ad3e44fe4f92 | 1.72 MiB | 2.29 MiB | 577.53 KiB |
| 2465853df157c4ad881166804873989c47c10f4d | 1.70 MiB | 2.27 MiB | 583.82 KiB |
| 8ff8fd047e817d4c017858d44c2681c6a8ac4e52 | 1.72 MiB | 2.27 MiB | 558.15 KiB |
| 2465853df157c4ad881166804873989c47c10f4d | 1.70 MiB | 2.27 MiB | 583.82 KiB |
| 5e04ee8e63c5617dbc4c2b9706b866e8823cec20 | 1.70 MiB | 2.27 MiB | 584.64 KiB |
| c554ca260c5f0fa79a30d592f6c0e08a850a5014 | 1.70 MiB | 2.27 MiB | 582.25 KiB |
| 4e290632c3083233d83c696533ee1e0d284dfd42 | 1.72 MiB | 2.29 MiB | 578.38 KiB |
| 0404ea31dd7e67983b3aa0133a0dc4fb6b983884 | 1.72 MiB | 2.29 MiB | 577.52 KiB |
| 0404ea31dd7e67983b3aa0133a0dc4fb6b983884 | 1.72 MiB | 2.29 MiB | 577.52 KiB |
Previous results on branch: feat/metrics
Startup times
| Revision | Plain | With Sentry | Diff |
|---|---|---|---|
| 67ad7476a42e8fed6df4e6b6cf5592fb8c455aa3 | 424.90 ms | 467.60 ms | 42.70 ms |
| ac0ecb9800ce82e97444b405735c00814f026391 | 425.69 ms | 506.96 ms | 81.27 ms |
| f5d47c0c50e8cacde779e9a9ada036924638ff6f | 300.14 ms | 342.90 ms | 42.76 ms |
| 5254f26b15a1103f4a122aca3a7d76f3c121190c | 411.85 ms | 442.08 ms | 30.23 ms |
| 0140fbcbc32d46e1f467f2fa0393101824961246 | 399.74 ms | 470.37 ms | 70.63 ms |
| f5aa57f441b84c628ba696e496b3d55eab6cd233 | 413.70 ms | 552.20 ms | 138.50 ms |
| 0e0f3c4d1b07e78667abd3e0cf00e04413334248 | 385.67 ms | 458.14 ms | 72.47 ms |
| 4edc1f32ae881e60057a677fcc0256f15a07fd12 | 371.24 ms | 446.73 ms | 75.49 ms |
| 6dd67a4b475ac57ff1ed6e1e581709777fbc63eb | 381.21 ms | 445.40 ms | 64.19 ms |
| 038e0aeb4f0b67157fa9cc6096bcd63924e4bb7b | 364.92 ms | 446.39 ms | 81.47 ms |
App size
| Revision | Plain | With Sentry | Diff |
|---|---|---|---|
| 67ad7476a42e8fed6df4e6b6cf5592fb8c455aa3 | 1.70 MiB | 2.28 MiB | 592.10 KiB |
| ac0ecb9800ce82e97444b405735c00814f026391 | 1.70 MiB | 2.28 MiB | 590.22 KiB |
| f5d47c0c50e8cacde779e9a9ada036924638ff6f | 1.70 MiB | 2.27 MiB | 586.58 KiB |
| 5254f26b15a1103f4a122aca3a7d76f3c121190c | 1.70 MiB | 2.28 MiB | 592.06 KiB |
| 0140fbcbc32d46e1f467f2fa0393101824961246 | 1.70 MiB | 2.27 MiB | 587.40 KiB |
| f5aa57f441b84c628ba696e496b3d55eab6cd233 | 1.70 MiB | 2.28 MiB | 590.22 KiB |
| 0e0f3c4d1b07e78667abd3e0cf00e04413334248 | 1.70 MiB | 2.27 MiB | 587.24 KiB |
| 4edc1f32ae881e60057a677fcc0256f15a07fd12 | 1.70 MiB | 2.27 MiB | 586.13 KiB |
| 6dd67a4b475ac57ff1ed6e1e581709777fbc63eb | 1.70 MiB | 2.27 MiB | 587.20 KiB |
| 038e0aeb4f0b67157fa9cc6096bcd63924e4bb7b | 1.70 MiB | 2.28 MiB | 590.25 KiB |
- when using
Sentry.metrics().notifyAll();I get error
IllegalMonitorStateException: current thread is not owner
at java.lang.Object.notifyAll(Object.java)
at sentry.SentryMain.main(SentryMain.java:33)
- java 21, sentry 7.5.0