Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Don't increase session's error count for dropped events #2374

Merged
merged 16 commits into from
Nov 17, 2022

Conversation

kevinrenskers
Copy link
Contributor

@kevinrenskers kevinrenskers commented Nov 9, 2022

📜 Description

Don't immediately update the session's error count. Only do this after running the beforeSend block.

💡 Motivation and Context

Closes #1777

💚 How did you test it?

Unit tests

📝 Checklist

  • I reviewed the submitted code
  • I added tests to verify the changes
  • I updated the docs if needed
  • Review from the native team if needed
  • No breaking changes

🔮 Next steps

Only do this after running the beforeSend block
@kevinrenskers
Copy link
Contributor Author

With this small change we first check if we still have an event after running the beforeSend block, and only then do we update the session's error count. But - [SentryClient captureSession:] is still executed, which still calls captureEnvelope which then sends the envelope. I guess we don't want to do that anymore if I read this correctly?

Second question: is this only for errors or also for exceptions? I.e. the whole captureException flow.

@github-actions
Copy link

github-actions bot commented Nov 9, 2022

Performance metrics 🚀

  Plain With Sentry Diff
Startup time 1244.64 ms 1272.50 ms 27.86 ms
Size 20.75 KiB 374.53 KiB 353.78 KiB

Baseline results on branch: master

Startup times

Revision Plain With Sentry Diff
f444dc4 1242.55 ms 1248.82 ms 6.27 ms
0fdf0b2 1243.92 ms 1250.86 ms 6.94 ms
59afa00 1209.29 ms 1237.88 ms 28.59 ms
411a940 1232.33 ms 1259.33 ms 27.01 ms
6dc0bd1 1220.49 ms 1237.44 ms 16.95 ms
9754750 1234.71 ms 1265.21 ms 30.49 ms
c2a9b60 1222.10 ms 1240.62 ms 18.52 ms
791123d 1217.52 ms 1253.08 ms 35.56 ms
4e037c4 1205.00 ms 1227.58 ms 22.58 ms
b15627c 1228.88 ms 1269.70 ms 40.82 ms

App size

Revision Plain With Sentry Diff
f444dc4 20.75 KiB 367.00 KiB 346.25 KiB
0fdf0b2 20.51 KiB 332.90 KiB 312.39 KiB
59afa00 20.50 KiB 365.16 KiB 344.65 KiB
411a940 20.50 KiB 361.79 KiB 341.29 KiB
6dc0bd1 20.51 KiB 333.58 KiB 313.07 KiB
9754750 20.75 KiB 374.16 KiB 353.41 KiB
c2a9b60 20.50 KiB 333.54 KiB 313.04 KiB
791123d 20.51 KiB 331.81 KiB 311.30 KiB
4e037c4 20.50 KiB 361.80 KiB 341.29 KiB
b15627c 20.50 KiB 337.76 KiB 317.25 KiB

Previous results on branch: feat/1777-no-session-update-for-dropped-events

Startup times

Revision Plain With Sentry Diff
0d5ca6b 1249.73 ms 1270.78 ms 21.05 ms
041dc77 1254.86 ms 1274.57 ms 19.71 ms
3ca16ab 1251.62 ms 1279.98 ms 28.36 ms
50e4603 1226.04 ms 1251.92 ms 25.88 ms
db3535b 1190.22 ms 1221.26 ms 31.04 ms
50e4603 1196.42 ms 1227.18 ms 30.76 ms
9f1fe4c 1263.76 ms 1269.14 ms 5.38 ms
5000a1e 1251.86 ms 1270.22 ms 18.36 ms
db3535b 1227.28 ms 1253.43 ms 26.15 ms
457f28e 1239.00 ms 1250.72 ms 11.72 ms

App size

Revision Plain With Sentry Diff
0d5ca6b 20.75 KiB 374.53 KiB 353.78 KiB
041dc77 20.75 KiB 374.19 KiB 353.44 KiB
3ca16ab 20.75 KiB 374.61 KiB 353.86 KiB
50e4603 20.75 KiB 374.61 KiB 353.86 KiB
db3535b 20.75 KiB 374.12 KiB 353.37 KiB
50e4603 20.75 KiB 374.61 KiB 353.86 KiB
9f1fe4c 20.75 KiB 374.24 KiB 353.48 KiB
5000a1e 20.75 KiB 367.28 KiB 346.52 KiB
db3535b 20.75 KiB 374.13 KiB 353.37 KiB
457f28e 20.75 KiB 374.50 KiB 353.74 KiB

@philipphofmann
Copy link
Member

philipphofmann commented Nov 11, 2022

Don't the docs state that clearly?

Events may be dropped by our filtering mechanisms (sample rate, beforeSend, event processors or ignored exception types). Only events dropped due to sampling should update the session despite being dropped as we assume the event was dropped to save quota but would have been something the developer cares about. Events dropped due to other reasons should not update the session as we assume they are more likely to be dropped because the developer chooses to ignore them.

These docs don't mention rate limiting, though. I'm going to clarify this. So just ignore it for now.

Basically, we need to change when we increment the session error count in the hub. I think the only change for our SDK now is to check if the event gets dropped in beforeSend or in an event processor. So we need to refactor the code that only if the event doesn't get dropped there, we update the session. That applies to anything updating the session, meaning exceptions, errors, events, crashes, etc. . I'm unsure what the best way is to solve this. Can you suggest a concept in this draft PR?

@kevinrenskers
Copy link
Contributor Author

Can you suggest a concept in this draft PR?

I do have a concept for error catching, and I guess this can pretty easily be extended to other events and exceptions and stuff.

@philipphofmann
Copy link
Member

@kevinrenskers, rate limited events should update the session, see getsentry/develop#756.

@kevinrenskers
Copy link
Contributor Author

Yes, rate limiting happens after this code runs so is unaffected by this change.

@kevinrenskers
Copy link
Contributor Author

I don't think you've answered the most important question:

But - [SentryClient captureSession:] is still executed, which still calls captureEnvelope which then sends the envelope. I guess we don't want to do that anymore if I read this correctly?

Can I please get some input on the code change I have made, if this is on the correct path, and if my assumption is correct?

…ents

* master:
  feat: Store breadcrumbs to disk for OOM events (#2347)
  Report pre-warmed app starts (#1969)
  fix: Too long flush duration (#2370)
  release: 7.30.2
  fix: profile payload issues (#2375)
…ents

* master:
  test: Fix MetricKit attachment filename (#2379)
…ents

* master:
  build(deps): bump github/codeql-action from 2.1.31 to 2.1.32 (#2386)
  build(deps): bump fastlane from 2.210.1 to 2.211.0 (#2385)
  ref: json serialization error reporting (#2355)
  release: 7.31.0
  ref: Fix outdated comment in SessionTracker (#2381)
  fix: Do not delete the app state (#2382)
  build: Split Swift and Clang format for pre-commit (#2380)
@kevinrenskers kevinrenskers marked this pull request as ready for review November 15, 2022 15:36
…ents

* master:
  Fix: Set the correct OOM event timestamp (#2394)
  test: Fix SentrySerializationTests.testSerializationFailsWithInvalidJSONObject (#2392)
  feat(hybrid-sdks): Add captureScreenshots to PrivateSDKOnly (#2384)
  ci: Increase test timeout for iOS 12 (#2391)
  test: Disable flaky testCrashReportCount1 (#2389)
  test: Disable flaky testSerializeWithUnderlyingNSException (#2387)
Copy link
Member

@philipphofmann philipphofmann left a comment

Choose a reason for hiding this comment

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

One important issue to address. Apart from that already looks great 😀

CHANGELOG.md Outdated Show resolved Hide resolved
Sources/Sentry/include/SentryHub+Private.h Outdated Show resolved Hide resolved
Tests/SentryTests/SentryClientTests.swift Show resolved Hide resolved
Tests/SentryTests/SentryClientTests.swift Outdated Show resolved Hide resolved
sut.capture(error: fixture.error, scope: fixture.scope).assertIsNotEmpty()

XCTAssertEqual(1, fixture.client.captureErrorWithSessionInvocations.count)
if let errorArguments = fixture.client.captureErrorWithSessionInvocations.first {
Copy link
Member

Choose a reason for hiding this comment

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

h: Sorry, I think I forgot to mention that yesterday on our call, or maybe we didn't touch that topic. If we don't increment the error count, there is not need to send a session update, as the session stays the same. In that case, we should only send the event without the session.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've made the change as we discussed at 14:30 but actually it doesn't change anything - we already didn't send the session update if the event was nil. That's because even though yes we were calling [self sendEvent:event withSession:session withScope:scope], that doesn't do anything at all if there is no event.

So in the end the most recent commit is just cleaning up, but doesn't change any behavior as nothing needed fixing.

kevinrenskers and others added 5 commits November 16, 2022 14:22
Co-authored-by: Philipp Hofmann <philipp.hofmann@sentry.io>
Co-authored-by: Philipp Hofmann <philipp.hofmann@sentry.io>
Copy link
Member

@philipphofmann philipphofmann left a comment

Choose a reason for hiding this comment

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

Thank you @kevinrenskers 👏

@@ -4,6 +4,7 @@

### Fixes

- Don't update session for dropped events (#2374)
Copy link
Member

Choose a reason for hiding this comment

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

m: That needs to move up a bit.

Copy link
Contributor Author

@kevinrenskers kevinrenskers Nov 17, 2022

Choose a reason for hiding this comment

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

It would be really nice to automate the changelogs :(
Like https://github.com/loopwerk/tag-changelog, or the many many other solutions out there.

@kevinrenskers kevinrenskers merged commit b45b682 into master Nov 17, 2022
@kevinrenskers kevinrenskers deleted the feat/1777-no-session-update-for-dropped-events branch November 17, 2022 15:11
kevinrenskers added a commit that referenced this pull request Nov 22, 2022
* 8.0.0:
  ref: Fix typos in OOMTracker (#2431)
  ref: Make SpanProtocol.data non nullable (#2409)
  ref: add/improve logging (#2420)
  ref: bump supported OS versions (#2414)
  test: shorten some tests (#2428)
  ref: Remove `- [SentryOptions initWithDict:didFailWithError:]` (#2404)
  ref: Mark [SpanProtocol setExtraValue:forKey] as deprecated (#2413)
  typos (#2421)
  test: Disable NSDataTracker in clearTestState (#2418)
  Update CHANGELOG.md (#2415)
  feat: Properly demangle Swift class name (#2162)
  chore: Create 8.0.0 branch
  test: include Sentry changes in hash keys (#2412)
  release: 7.31.2
  fix: Crash in Client when reading integrations (#2398)
  test: tooling improvements (#2400)
  fix: Don't increase session's error count for dropped events (#2374)
  Update CHANGELOG.md (#2396)
  release: 7.31.1
  Fix: Set the correct OOM event timestamp (#2394)

# Conflicts:
#	Sentry.xcodeproj/project.pbxproj
#	SentryPrivate.podspec
#	scripts/add-sentry-to-vlc.patch
kevinrenskers added a commit that referenced this pull request Nov 24, 2022
* master: (56 commits)
  meta: disable swiftlint file length check in TBDBClient.swift (#2435)
  Revert "test: shorten some tests (#2422)" (#2427)
  test: shorten some tests (#2422)
  test: include Sentry changes in hash keys (#2412)
  release: 7.31.2
  fix: Crash in Client when reading integrations (#2398)
  test: tooling improvements (#2400)
  fix: Don't increase session's error count for dropped events (#2374)
  Update CHANGELOG.md (#2396)
  release: 7.31.1
  Fix: Set the correct OOM event timestamp (#2394)
  test: Fix SentrySerializationTests.testSerializationFailsWithInvalidJSONObject (#2392)
  feat(hybrid-sdks): Add captureScreenshots to PrivateSDKOnly (#2384)
  ci: Increase test timeout for iOS 12 (#2391)
  test: Disable flaky testCrashReportCount1 (#2389)
  test: Disable flaky testSerializeWithUnderlyingNSException (#2387)
  build(deps): bump github/codeql-action from 2.1.31 to 2.1.32 (#2386)
  build(deps): bump fastlane from 2.210.1 to 2.211.0 (#2385)
  ref: json serialization error reporting (#2355)
  release: 7.31.0
  ...
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.

Align SDK with docs regarding session update for dropped events
2 participants