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

Add sent_at to envelope header #2859

Merged
merged 19 commits into from
May 11, 2023
Merged

Conversation

denrase
Copy link
Collaborator

@denrase denrase commented Apr 4, 2023

📜 Description

  • Add sent_at to envelope header
  • Set to current date before sending out envelope in transport adapter

💡 Motivation and Context

Relates to getsentry/sentry-dart#1337
Documentation https://develop.sentry.dev/sdk/envelopes/

💚 How did you test it?

Added tests

📝 Checklist

You have to check all boxes before merging:

  • I reviewed the submitted code.
  • 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.
  • 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

Test if this works correctly wit hybrid (dart) sdks.

@github-actions
Copy link

github-actions bot commented Apr 4, 2023

Messages
📖 Do not forget to update Sentry-docs with your feature once the pull request gets approved.

Generated by 🚫 dangerJS against f3c8571

@denrase denrase marked this pull request as ready for review April 4, 2023 15:53
@github-actions
Copy link

github-actions bot commented Apr 4, 2023

Performance metrics 🚀

  Plain With Sentry Diff
Startup time 1218.57 ms 1227.84 ms 9.27 ms
Size 20.76 KiB 434.72 KiB 413.96 KiB

Baseline results on branch: main

Startup times

Revision Plain With Sentry Diff
4d68229 1233.50 ms 1262.92 ms 29.42 ms
8f397a7 1230.10 ms 1253.88 ms 23.77 ms
371db89 1226.40 ms 1251.54 ms 25.14 ms
fd6a31c 1204.73 ms 1222.34 ms 17.61 ms
d60f70a 1219.63 ms 1228.54 ms 8.91 ms
630ddf4 1216.50 ms 1235.94 ms 19.44 ms
25737cb 1235.02 ms 1250.06 ms 15.04 ms
06548c0 1226.71 ms 1252.37 ms 25.66 ms
c021422 1199.15 ms 1222.20 ms 23.05 ms
b2f82fa 1237.78 ms 1256.02 ms 18.24 ms

App size

Revision Plain With Sentry Diff
4d68229 20.76 KiB 432.34 KiB 411.58 KiB
8f397a7 20.76 KiB 420.55 KiB 399.79 KiB
371db89 20.76 KiB 427.31 KiB 406.55 KiB
fd6a31c 20.76 KiB 436.50 KiB 415.74 KiB
d60f70a 20.76 KiB 430.97 KiB 410.21 KiB
630ddf4 20.76 KiB 432.37 KiB 411.61 KiB
25737cb 20.76 KiB 436.29 KiB 415.53 KiB
06548c0 20.76 KiB 427.36 KiB 406.59 KiB
c021422 20.76 KiB 435.64 KiB 414.88 KiB
b2f82fa 20.76 KiB 419.62 KiB 398.86 KiB

Previous results on branch: feat/envelope-header-sent-at

Startup times

Revision Plain With Sentry Diff
30236ed 1239.67 ms 1252.84 ms 13.17 ms
3031b91 1235.29 ms 1246.32 ms 11.03 ms
6789a10 1209.59 ms 1232.30 ms 22.71 ms
7044a83 1242.82 ms 1264.12 ms 21.30 ms
f50cd0f 1218.71 ms 1225.84 ms 7.12 ms
1fe5466 1196.30 ms 1232.38 ms 36.08 ms
5d48ce8 1220.37 ms 1240.67 ms 20.30 ms
7078353 1217.05 ms 1243.16 ms 26.12 ms
8ef64f7 1236.76 ms 1263.14 ms 26.38 ms

App size

Revision Plain With Sentry Diff
30236ed 20.76 KiB 432.67 KiB 411.91 KiB
3031b91 20.76 KiB 434.72 KiB 413.96 KiB
6789a10 20.76 KiB 432.41 KiB 411.65 KiB
7044a83 20.76 KiB 433.29 KiB 412.53 KiB
f50cd0f 20.76 KiB 432.59 KiB 411.83 KiB
1fe5466 20.76 KiB 431.64 KiB 410.88 KiB
5d48ce8 20.76 KiB 435.04 KiB 414.28 KiB
7078353 20.76 KiB 432.67 KiB 411.91 KiB
8ef64f7 20.76 KiB 431.64 KiB 410.88 KiB

@codecov
Copy link

codecov bot commented Apr 4, 2023

Codecov Report

Merging #2859 (f3c8571) into main (0dfdaaa) will increase coverage by 0.025%.
The diff coverage is 100.000%.

Additional details and impacted files

Impacted file tree graph

@@              Coverage Diff              @@
##              main     #2859       +/-   ##
=============================================
+ Coverage   88.802%   88.827%   +0.025%     
=============================================
  Files          492       492               
  Lines        52878     52900       +22     
  Branches     18955     18966       +11     
=============================================
+ Hits         46957     46990       +33     
+ Misses        4954      4946        -8     
+ Partials       967       964        -3     
Impacted Files Coverage Δ
Sources/Sentry/SentryNSURLRequest.m 76.190% <ø> (-1.083%) ⬇️
Sources/Sentry/SentryHttpTransport.m 97.747% <100.000%> (+0.010%) ⬆️
Sources/Sentry/SentrySerialization.m 90.035% <100.000%> (+0.180%) ⬆️
.../SentryTests/Helper/SentrySerializationTests.swift 97.269% <100.000%> (+0.028%) ⬆️
Tests/SentryTests/Networking/SentryDsnTests.m 100.000% <100.000%> (ø)
...tryTests/Networking/SentryHttpTransportTests.swift 97.566% <100.000%> (+0.026%) ⬆️
...Tests/Networking/SentryTransportAdapterTests.swift 97.297% <100.000%> (ø)

... and 15 files with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 0dfdaaa...f3c8571. Read the comment docs.

Copy link
Contributor

@brustolin brustolin left a comment

Choose a reason for hiding this comment

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

LGTM

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.

Thanks for doing this, @denrase. We have to change two important pieces. See one h comment and we also have to remove the sentry_timestamp

[string
appendFormat:@"%@,",
newHeaderPart(@"sentry_timestamp", @((NSInteger)[[NSDate date] timeIntervalSince1970]))];

See docs:

Also note that the sent_at header replaces the sentry_timestamp key previously set in authorization headers, which has now been fully deprecated. You should only send sent_at, and not sentry_timestamp.

@@ -94,6 +95,7 @@ - (void)sendUserFeedback:(SentryUserFeedback *)userFeedback

- (void)sendEnvelope:(SentryEnvelope *)envelope
{
envelope.header.sentAt = SentryCurrentDate.date;
Copy link
Member

Choose a reason for hiding this comment

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

h: This sets the sentAt timestamp to when we are caching to disk, which we must not do according to the docs:

For example, SDKs that implement caching features should avoid writing the sent_at header when caching to disk. Only write it when actually sending the event to Sentry.

Instead, we have to set sentAt directly before we send it:

NSURLRequest *request = [self.requestBuilder createEnvelopeRequest:rateLimitedEnvelope
dsn:self.options.parsedDsn
didFailWithError:&requestError];

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

You are right, sry about that. Moved this to SentryHttpTransport.m

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.

Almost LGTM, thanks @denrase.

Sources/Sentry/SentryTransportAdapter.m Outdated Show resolved Hide resolved
@@ -52,14 +52,17 @@ class SentryHttpTransportTests: XCTestCase {
attachmentEnvelopeItem = SentryEnvelopeItem(attachment: TestData.dataAttachment, maxAttachmentSize: 5 * 1_024 * 1_024)!

eventEnvelope = SentryEnvelope(id: event.eventId, items: [SentryEnvelopeItem(event: event), attachmentEnvelopeItem])
eventEnvelope.header.sentAt = CurrentDate.date()
Copy link
Member

@philipphofmann philipphofmann Apr 18, 2023

Choose a reason for hiding this comment

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

m: Thanks for adapting the tests. It would be great if the tests fail, when setting the sentAt before creating the request, for example, in SentryHttpTransport.sendEnvelope. If it's too complicated to achieve, please don't do it. Adding a comment as explained in #2859 (comment) could also be sufficient.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Please check if the comment i added is sufficient.

Sources/Sentry/SentryHttpTransport.m Show resolved Hide resolved
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.

LGTM, but the Changelog needs some fixes.

CHANGELOG.md Show resolved Hide resolved
@denrase denrase requested a review from marandaneto April 25, 2023 08:18
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.

Again LGTM, @denrase. What's stopping you from merging this PR?

@krystofwoldrich
Copy link
Member

Hello everyone,
the unit tests are not happy, by the error message it looks like it could be related to the changes.

Could we get this merged soon? There are RN customers waiting for this as it will fix issues with clock drift in transactions.

@philipphofmann
Copy link
Member

@krystofwoldrich, @denrase is not working full-time for Sentry. I can take it and finish the PR if he doesn't get to it by Tuesday.

@krystofwoldrich
Copy link
Member

krystofwoldrich commented May 10, 2023

@philipphofmann Okay, thanks for the info, that would be awesome. What is missing, I thought it was done?

@philipphofmann philipphofmann merged commit b483671 into main May 11, 2023
@philipphofmann philipphofmann deleted the feat/envelope-header-sent-at branch May 11, 2023 13:15
@krystofwoldrich
Copy link
Member

@philipphofmann @denrase Thank you.

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.

5 participants