Skip to content

Commit

Permalink
add tons of tests and fixed to baggage
Browse files Browse the repository at this point in the history
  • Loading branch information
philprime committed Jan 27, 2025
1 parent 2862f33 commit 541c625
Show file tree
Hide file tree
Showing 30 changed files with 2,021 additions and 91 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,17 @@

- Use strlcpy to save session replay info path (#4740)
- `sentryReplayUnmask` and `sentryReplayUnmask` preventing interaction (#4749)
- Fix missing `sample_rate` in baggage (#4751)

### Improvements

- Add SentryHub to all log messages in the Hub (#4753)
- More detailed log message when can't start session in SentryHub (#4752)

### Features

- Add `sample_rand` to baggage (#4751)

## 8.44.0-beta.1

### Fixes
Expand Down
7 changes: 6 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,12 @@ test:
run-test-server:
cd ./test-server && swift build
cd ./test-server && swift run &
.PHONY: run-test-server

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

.PHONY: run-test-server run-test-server-sync

test-alamofire:
./scripts/test-alamofire.sh
Expand Down
2 changes: 1 addition & 1 deletion SentryTestUtils/SentryLaunchProfiling+Tests.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ BOOL sentry_willProfileNextLaunch(SentryOptions *options);
*/
void _sentry_nondeduplicated_startLaunchProfile(void);

SentryTransactionContext *sentry_context(NSNumber *tracesRate);
SentryTransactionContext *sentry_context(NSNumber *tracesRate, NSNumber *tracesRand);

NS_ASSUME_NONNULL_END

Expand Down
16 changes: 9 additions & 7 deletions Sources/Sentry/Profiling/SentryLaunchProfiling.m
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,13 @@
SentryTracer *_Nullable sentry_launchTracer;

SentryTracerConfiguration *
sentry_config(NSNumber *profilesRate)
sentry_config(NSNumber *profilesRate, NSNumber *profilesRand)
{
SentryTracerConfiguration *config = [SentryTracerConfiguration defaultConfiguration];
config.profilesSamplerDecision =
[[SentrySamplerDecision alloc] initWithDecision:kSentrySampleDecisionYes
forSampleRate:profilesRate];
forSampleRate:profilesRate
withSampleRand:profilesRand];
return config;
}

Expand Down Expand Up @@ -92,15 +93,16 @@
}

SentryTransactionContext *
sentry_context(NSNumber *tracesRate)
sentry_context(NSNumber *tracesRate, NSNumber *tracesRand)
{
SentryTransactionContext *context =
[[SentryTransactionContext alloc] initWithName:@"launch"
nameSource:kSentryTransactionNameSourceCustom
operation:SentrySpanOperation.appLifecycle
origin:SentryTraceOrigin.autoAppStartProfile
sampled:kSentrySampleDecisionYes];
context.sampleRate = tracesRate;
sampled:kSentrySampleDecisionYes
sampleRate:tracesRate
sampleRand:tracesRand];
return context;
}

Expand Down Expand Up @@ -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)
hub:nil
configuration:sentry_config(profilesRate)];
configuration:sentry_config(profilesRate, @1.0)];
}

# pragma mark - Public
Expand Down
18 changes: 18 additions & 0 deletions Sources/Sentry/Public/SentryBaggage.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@ NS_SWIFT_NAME(Baggage)
*/
@property (nullable, nonatomic, readonly) NSString *userSegment;

/**
* The random value used to determine if the trace is sampled.
*
* A float (`0.1234` notation) in the range of `[0, 1)` (including 0.0, excluding 1.0).
*/
@property (nullable, nonatomic, readonly) NSString *sampleRand;

/**
* The sample rate.
*/
Expand All @@ -67,6 +74,17 @@ NS_SWIFT_NAME(Baggage)
sampled:(nullable NSString *)sampled
replayId:(nullable NSString *)replayId;

- (instancetype)initWithTraceId:(SentryId *)traceId
publicKey:(NSString *)publicKey
releaseName:(nullable NSString *)releaseName
environment:(nullable NSString *)environment
transaction:(nullable NSString *)transaction
userSegment:(nullable NSString *)userSegment
sampleRate:(nullable NSString *)sampleRate
sampleRand:(nullable NSString *)sampleRand
sampled:(nullable NSString *)sampled
replayId:(nullable NSString *)replayId;

- (NSString *)toHTTPHeaderWithOriginalBaggage:(NSDictionary *_Nullable)originalBaggage;

@end
Expand Down
59 changes: 59 additions & 0 deletions Sources/Sentry/Public/SentrySpanContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,16 @@ SENTRY_NO_INIT
*/
@property (nonatomic, readonly) SentrySampleDecision sampled;

/**
* Rate of sampling
*/
@property (nullable, nonatomic, strong, readonly) NSNumber *sampleRate;

/**
* Random value used to determine if the span is sampled.
*/
@property (nullable, nonatomic, strong, readonly) NSNumber *sampleRand;

/**
* Short code identifying the type of operation the span is measuring.
*/
Expand Down Expand Up @@ -78,6 +88,19 @@ SENTRY_NO_INIT
*/
- (instancetype)initWithOperation:(NSString *)operation sampled:(SentrySampleDecision)sampled;

/**
* Init a @c SentryContext with an operation code and mark it as sampled or not.
* TraceId and SpanId with be randomly created.
* @param operation The operation this span is measuring.
* @param sampled Determines whether the trace should be sampled.
* @param sampleRate Rate of sampling
* @param sampleRand Random value used to determine if the trace is sampled.
*/
- (instancetype)initWithOperation:(NSString *)operation
sampled:(SentrySampleDecision)sampled
sampleRate:(nullable NSNumber *)sampleRate
sampleRand:(nullable NSNumber *)sampleRand;

/**
* @param traceId Determines which trace the Span belongs to.
* @param spanId The Span Id.
Expand All @@ -91,6 +114,23 @@ SENTRY_NO_INIT
operation:(NSString *)operation
sampled:(SentrySampleDecision)sampled;

/**
* @param traceId Determines which trace the Span belongs to.
* @param spanId The Span Id.
* @param operation The operation this span is measuring.
* @param parentId Id of a parent span.
* @param sampled Determines whether the trace should be sampled.
* @param sampleRate Rate of sampling
* @param sampleRand Random value used to determine if the trace is sampled.
*/
- (instancetype)initWithTraceId:(SentryId *)traceId
spanId:(SentrySpanId *)spanId
parentId:(nullable SentrySpanId *)parentId
operation:(NSString *)operation
sampled:(SentrySampleDecision)sampled
sampleRate:(nullable NSNumber *)sampleRate
sampleRand:(nullable NSNumber *)sampleRand;

/**
* @param traceId Determines which trace the Span belongs to.
* @param spanId The Span Id.
Expand All @@ -106,6 +146,25 @@ SENTRY_NO_INIT
spanDescription:(nullable NSString *)description
sampled:(SentrySampleDecision)sampled;

/**
* @param traceId Determines which trace the Span belongs to.
* @param spanId The Span Id.
* @param operation The operation this span is measuring.
* @param parentId Id of a parent span.
* @param description The span description.
* @param sampled Determines whether the trace should be sampled.
* @param sampleRate Rate of sampling
* @param sampleRand Random value used to determine if the trace is sampled.
*/
- (instancetype)initWithTraceId:(SentryId *)traceId
spanId:(SentrySpanId *)spanId
parentId:(nullable SentrySpanId *)parentId
operation:(NSString *)operation
spanDescription:(nullable NSString *)description
sampled:(SentrySampleDecision)sampled
sampleRate:(nullable NSNumber *)sampleRate
sampleRand:(nullable NSNumber *)sampleRand;

@end

NS_ASSUME_NONNULL_END
19 changes: 19 additions & 0 deletions Sources/Sentry/Public/SentryTraceContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ NS_SWIFT_NAME(TraceContext)
*/
@property (nullable, nonatomic, readonly) NSString *sampleRate;

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

/**
* Value indicating whether the trace was sampled.
*/
Expand All @@ -75,6 +80,20 @@ NS_SWIFT_NAME(TraceContext)
sampled:(nullable NSString *)sampled
replayId:(nullable NSString *)replayId;

/**
* Initializes a SentryTraceContext with given properties.
*/
- (instancetype)initWithTraceId:(SentryId *)traceId
publicKey:(NSString *)publicKey
releaseName:(nullable NSString *)releaseName
environment:(nullable NSString *)environment
transaction:(nullable NSString *)transaction
userSegment:(nullable NSString *)userSegment
sampleRate:(nullable NSString *)sampleRate
sampleRand:(nullable NSString *)sampleRand
sampled:(nullable NSString *)sampled
replayId:(nullable NSString *)replayId;

/**
* Initializes a SentryTraceContext with data from scope and options.
*/
Expand Down
37 changes: 35 additions & 2 deletions Sources/Sentry/Public/SentryTransactionContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,14 @@ SENTRY_NO_INIT
@property (nonatomic) SentrySampleDecision parentSampled;

/**
* Sample rate used for this transaction
* Parent sample rate used for this transaction
*/
@property (nonatomic, strong, nullable) NSNumber *sampleRate;
@property (nonatomic, strong, nullable) NSNumber *parentSampleRate;

/**
* Parent random value used to determine if the trace is sampled.
*/
@property (nonatomic, strong, nullable) NSNumber *parentSampleRand;

/**
* If app launch profiling is enabled via @c SentryOptions.enableAppLaunchProfiling and
Expand All @@ -56,6 +61,17 @@ SENTRY_NO_INIT
operation:(NSString *)operation
sampled:(SentrySampleDecision)sampled;

/**
* @param name Transaction name
* @param operation The operation this span is measuring.
* @param sampled Determines whether the trace should be sampled.
*/
- (instancetype)initWithName:(NSString *)name
operation:(NSString *)operation
sampled:(SentrySampleDecision)sampled
sampleRate:(nullable NSNumber *)sampleRate
sampleRand:(nullable NSNumber *)sampleRand;

/**
* @param name Transaction name
* @param operation The operation this span is measuring.
Expand All @@ -71,6 +87,23 @@ SENTRY_NO_INIT
parentSpanId:(nullable SentrySpanId *)parentSpanId
parentSampled:(SentrySampleDecision)parentSampled;

/**
* @param name Transaction name
* @param operation The operation this span is measuring.
* @param traceId Trace Id
* @param spanId Span Id
* @param parentSpanId Parent span id
* @param parentSampled Whether the parent is sampled
*/
- (instancetype)initWithName:(NSString *)name
operation:(NSString *)operation
traceId:(SentryId *)traceId
spanId:(SentrySpanId *)spanId
parentSpanId:(nullable SentrySpanId *)parentSpanId
parentSampled:(SentrySampleDecision)parentSampled
parentSampleRate:(nullable NSNumber *)parentSampleRate
parentSampleRand:(nullable NSNumber *)parentSampleRand;

@end

NS_ASSUME_NONNULL_END
28 changes: 28 additions & 0 deletions Sources/Sentry/SentryBaggage.m
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,29 @@ - (instancetype)initWithTraceId:(SentryId *)traceId
sampled:(nullable NSString *)sampled
replayId:(nullable NSString *)replayId
{
return [self initWithTraceId:traceId
publicKey:publicKey
releaseName:releaseName
environment:environment
transaction:transaction
userSegment:userSegment
sampleRate:sampleRate
sampleRand:nil
sampled:sampled
replayId:replayId];
}

- (instancetype)initWithTraceId:(SentryId *)traceId
publicKey:(NSString *)publicKey
releaseName:(nullable NSString *)releaseName
environment:(nullable NSString *)environment
transaction:(nullable NSString *)transaction
userSegment:(nullable NSString *)userSegment
sampleRate:(nullable NSString *)sampleRate
sampleRand:(nullable NSString *)sampleRand
sampled:(nullable NSString *)sampled
replayId:(nullable NSString *)replayId
{

if (self = [super init]) {
_traceId = traceId;
Expand All @@ -29,6 +52,7 @@ - (instancetype)initWithTraceId:(SentryId *)traceId
_transaction = transaction;
_userSegment = userSegment;
_sampleRate = sampleRate;
_sampleRand = sampleRand;
_sampled = sampled;
_replayId = replayId;
}
Expand Down Expand Up @@ -60,6 +84,10 @@ - (NSString *)toHTTPHeaderWithOriginalBaggage:(NSDictionary *_Nullable)originalB
[information setValue:_userSegment forKey:@"sentry-user_segment"];
}

if (_sampleRand != nil) {
[information setValue:_sampleRand forKey:@"sentry-sample_rand"];
}

if (_sampleRate != nil) {
[information setValue:_sampleRate forKey:@"sentry-sample_rate"];
}
Expand Down
4 changes: 3 additions & 1 deletion Sources/Sentry/SentryBuildAppStartSpans.m
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
operation:operation
spanDescription:description
origin:SentryTraceOrigin.autoAppStart
sampled:tracer.sampled];
sampled:tracer.sampled
sampleRate:tracer.sampleRate
sampleRand:tracer.sampleRand];

return [[SentrySpan alloc] initWithTracer:tracer context:context framesTracker:nil];
}
Expand Down
Loading

0 comments on commit 541c625

Please sign in to comment.