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

feat: add sample_rand / fix sample_rate in baggage #4751

Open
wants to merge 12 commits into
base: main
Choose a base branch
from

Conversation

philprime
Copy link
Contributor

@philprime philprime commented Jan 24, 2025

📜 Description

  • Add sample_rand to the baggage
  • Fixed sample_rate not added to baggage
  • Add additional initializer tests for public interfaces

💡 Motivation and Context

See #4687

💚 How did you test it?

📝 Checklist

You have to check all boxes before merging:

  • 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

  • Perform integrations tests

Copy link

github-actions bot commented Jan 24, 2025

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

Generated by 🚫 dangerJS against 6ad1eb7

Copy link

codecov bot commented Jan 24, 2025

Codecov Report

Attention: Patch coverage is 99.87700% with 2 lines in your changes missing coverage. Please review.

Project coverage is 91.306%. Comparing base (e76c341) to head (6ad1eb7).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
Sources/Sentry/SentrySampling.m 84.615% 2 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@              Coverage Diff              @@
##              main     #4751       +/-   ##
=============================================
+ Coverage   91.197%   91.306%   +0.108%     
=============================================
  Files          623       624        +1     
  Lines        72505     74081     +1576     
  Branches     26407     26006      -401     
=============================================
+ Hits         66123     67641     +1518     
- Misses        6284      6349       +65     
+ Partials        98        91        -7     
Files with missing lines Coverage Δ
Sources/Sentry/Profiling/SentryLaunchProfiling.m 91.129% <100.000%> (+0.145%) ⬆️
Sources/Sentry/SentryBaggage.m 100.000% <100.000%> (ø)
Sources/Sentry/SentryBuildAppStartSpans.m 100.000% <ø> (ø)
Sources/Sentry/SentryHub.m 97.981% <100.000%> (+0.018%) ⬆️
Sources/Sentry/SentrySamplerDecision.m 100.000% <100.000%> (ø)
Sources/Sentry/SentryTraceContext.m 96.644% <100.000%> (+2.289%) ⬆️
Sources/Sentry/SentryTransactionContext.mm 100.000% <100.000%> (ø)
...yProfilerTests/SentryAppLaunchProfilingTests.swift 100.000% <100.000%> (ø)
.../SentryTests/Helper/SentrySerializationTests.swift 99.807% <100.000%> (+0.010%) ⬆️
...sts/SentryTests/Protocol/SentryEnvelopeTests.swift 96.264% <100.000%> (+0.191%) ⬆️
... and 8 more

... and 24 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 e76c341...6ad1eb7. Read the comment docs.

Copy link

github-actions bot commented Jan 24, 2025

Performance metrics 🚀

  Plain With Sentry Diff
Startup time 1226.31 ms 1245.65 ms 19.35 ms
Size 22.31 KiB 776.94 KiB 754.62 KiB

Baseline results on branch: main

Startup times

Revision Plain With Sentry Diff
077e940 1218.33 ms 1243.24 ms 24.92 ms
f1ed6f8 1210.94 ms 1230.78 ms 19.84 ms
1f9387b 1229.25 ms 1242.62 ms 13.37 ms
35647ef 1250.42 ms 1251.87 ms 1.46 ms
b9a9ffd 1221.18 ms 1235.37 ms 14.19 ms
0001a09 1223.90 ms 1249.56 ms 25.66 ms
add9550 1221.20 ms 1250.04 ms 28.84 ms
c0b4b71 1246.98 ms 1256.77 ms 9.79 ms
061c982 1226.33 ms 1243.65 ms 17.33 ms
86e9bf2 1225.70 ms 1252.19 ms 26.49 ms

App size

Revision Plain With Sentry Diff
077e940 21.58 KiB 706.97 KiB 685.39 KiB
f1ed6f8 21.58 KiB 683.51 KiB 661.93 KiB
1f9387b 21.58 KiB 654.26 KiB 632.68 KiB
35647ef 21.58 KiB 706.97 KiB 685.39 KiB
b9a9ffd 21.58 KiB 418.43 KiB 396.85 KiB
0001a09 20.76 KiB 433.19 KiB 412.43 KiB
add9550 21.58 KiB 418.37 KiB 396.79 KiB
c0b4b71 20.76 KiB 430.98 KiB 410.22 KiB
061c982 21.58 KiB 683.51 KiB 661.93 KiB
86e9bf2 22.31 KiB 758.78 KiB 736.47 KiB

Previous results on branch: philprime/issue-4687-sampling-seed-propagation

Startup times

Revision Plain With Sentry Diff
544ce99 1216.27 ms 1227.33 ms 11.06 ms
a618a92 1221.79 ms 1242.41 ms 20.62 ms
ab1ebcb 1214.52 ms 1235.14 ms 20.62 ms
5400890 1230.16 ms 1243.23 ms 13.07 ms
63bb06c 1216.49 ms 1237.31 ms 20.82 ms
ca8ee23 1227.45 ms 1247.34 ms 19.89 ms

App size

Revision Plain With Sentry Diff
544ce99 22.31 KiB 777.60 KiB 755.29 KiB
a618a92 22.31 KiB 777.65 KiB 755.34 KiB
ab1ebcb 22.31 KiB 777.76 KiB 755.45 KiB
5400890 22.31 KiB 776.94 KiB 754.62 KiB
63bb06c 22.31 KiB 777.76 KiB 755.45 KiB
ca8ee23 22.31 KiB 775.60 KiB 753.29 KiB

@philprime philprime force-pushed the philprime/issue-4687-sampling-seed-propagation branch from a0f0b4f to 07f9ad4 Compare January 27, 2025 13:41
@philprime philprime force-pushed the philprime/issue-4687-sampling-seed-propagation branch from 07f9ad4 to 541c625 Compare January 27, 2025 16:40
@@ -153,9 +155,9 @@
SENTRY_LOG_INFO(@"Starting app launch trace profile at %llu.", getAbsoluteTime());
sentry_isTracingAppLaunch = YES;
sentry_launchTracer =
[[SentryTracer alloc] initWithTransactionContext:sentry_context(tracesRate)
[[SentryTracer alloc] initWithTransactionContext:sentry_context(tracesRate, @1.0)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is setting the random value to 1.0 the correct way? Should we set it to something < 1.0?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@armcknight do you have some input here?

@@ -78,6 +88,19 @@ SENTRY_NO_INIT
*/
- (instancetype)initWithOperation:(NSString *)operation sampled:(SentrySampleDecision)sampled;

/**
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Same as in #4751 (comment)

@@ -91,6 +114,23 @@ SENTRY_NO_INIT
operation:(NSString *)operation
sampled:(SentrySampleDecision)sampled;

/**
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ssame as in #4751 (comment)

@philprime philprime changed the title feat: add sample_rand to trace context feat: add sample_rand / fix sample_rate in baggage Jan 28, 2025
@philprime philprime marked this pull request as ready for review January 28, 2025 09:37
@philprime philprime marked this pull request as draft January 28, 2025 09:45
@philprime
Copy link
Contributor Author

Back to draft because I noticed missing test cases

@philprime philprime marked this pull request as ready for review January 28, 2025 11:47
@philprime philprime self-assigned this Jan 28, 2025
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.

I do have one comment that I think would short this PR a lot.

Sources/Sentry/Public/SentrySpanProtocol.h Outdated 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.

I will give this a full review once we remove the span changes, as this will significantly reduce the scope of the PR.

Comment on lines +51 to +56

run-test-server-sync:
cd ./test-server && swift build
cd ./test-server && swift run

.PHONY: run-test-server run-test-server-sync
Copy link
Member

Choose a reason for hiding this comment

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

l: Why did you have to change this? It would be great to put such changes in an extra PR to keep PRs smaller.

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 don't want to have a daemon test server running on my machine in the background, which I can not control anymore without opening Activity Monitor or using kill, especially when it relates to the currently checked out commit.

I considered this a small enough change to be part of any PR, but I am fine with adding it in another PR.

Copy link
Member

Choose a reason for hiding this comment

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

It's OK to keep it.

Sources/Sentry/Public/SentryBaggage.h Show resolved Hide resolved
Sources/Sentry/Public/SentrySpanProtocol.h Outdated 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, thanks for all the extra tests

return [[SentrySamplerDecision alloc] initWithDecision:decision forSampleRate:rate];
return [[SentrySamplerDecision alloc] initWithDecision:decision
forSampleRate:rate
withSampleRand:[NSNumber numberWithDouble:random]];
Copy link
Member

Choose a reason for hiding this comment

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

l: A bit shorter.

Suggested change
withSampleRand:[NSNumber numberWithDouble:random]];
withSampleRand:@(random)];

/**
* Random value used to determine if the trace is sampled.
*/
@property (nullable, nonatomic, readonly) NSString *sampleRand;
Copy link
Member

Choose a reason for hiding this comment

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

m: What a string? Ah, OK, I see that sampleRate is also a string. This is a bit confusing. Please add the reason for this as a comment. We do this in multiple places in the PR, so please update the PR everywhere.

@@ -162,6 +162,24 @@ class SentryEnvelopeTests: XCTestCase {
XCTAssertEqual(eventId, envelopeHeader.eventId)
XCTAssertEqual(traceContext, envelopeHeader.traceContext)
}

func testInitSentryEnvelopeHeader_withSampleRand_SetIdAndTraceState() {
Copy link
Member

Choose a reason for hiding this comment

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

m: What extra value does this test add? There aren't any changes in SentryEnvelopeHeader. We already have testInitSentryEnvelopeHeader_SetIdAndTraceState which validates that the init method of SentryEnvelopeHeader assigns the traceContext. Here, we only use a different initializer of the TraceContext. Am I missing something?

@@ -370,28 +370,68 @@ class SentryHubTests: XCTestCase {
XCTAssertEqual(span.sampled, .no)
}

@available(*, deprecated) // The test is marked as deprecated to silence the deprecation warning of the initializer
Copy link
Member

Choose a reason for hiding this comment

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

l: Maybe a bit cleaner.

Suggested change
@available(*, deprecated) // The test is marked as deprecated to silence the deprecation warning of the initializer
@available(*, deprecated, message: "The test is marked as deprecated to silence the deprecation warning of the initializer")

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.

4 participants