Skip to content

Commit

Permalink
Merge branch '8.0.0' into ref/public-APIs-Swift-friendly
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinrenskers authored Nov 23, 2022
2 parents e69d56f + bbe81cb commit 6ab21e8
Show file tree
Hide file tree
Showing 37 changed files with 312 additions and 203 deletions.
21 changes: 12 additions & 9 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,21 @@ This version adds a dependency on Swift.

### Breaking Changes

- Remove `- [SentryOptions initWithDict:didFailWithError:]` (#2404)
- Rename `- [SentrySDK startWithOptionsObject:]` to `- [SentrySDK startWithOptions:]` (#2404)
- Remove `- [SentryOptions sdkInfo]` (#2404)
- Make `SpanProtocol.data` non nullable (#2409)
- Mark `- [SpanProtocol setExtraValue:forKey:]` as deprecated (#2413)
- Bump minimum supported OS versions to macOS 10.13, iOS 11, tvOS 11, and watchOS 4 (#2414)
- Make public APIs Swift friendly (#2416)
- Rename `SentrySDK.addBreadcrumb(crumb:)` to `SentrySDK.addBreadcrumb(_ crumb:)`
- Rename `SentryScope.add(_ crumb:)` to `SentryScope.addBreadcrumb(_ crumb:)`
- Rename `SentryScope.add(_ attachment:)` to `SentryScope.addAttachment(_ attachment:)`
- Remove public APIs (#2416)
- Remove `SentryScope.apply(to:)`
- remove `SentryScope.apply(to:maxBreadcrumb:)`
- Make public APIs Swift friendly
- Rename `SentrySDK.addBreadcrumb(crumb:)` to `SentrySDK.addBreadcrumb(_ crumb:)` (#2416)
- Rename `SentryScope.add(_ crumb:)` to `SentryScope.addBreadcrumb(_ crumb:)` (#2416)
- Rename `SentryScope.add(_ attachment:)` to `SentryScope.addAttachment(_ attachment:)` (#2416)
- Rename `Client` to `SentryClient` (#2403)
- Rename `User` to `SentryUser` (#2403)
- Remove public APIs
- Remove `SentryScope.apply(to:)` (#2416)
- Remove `SentryScope.apply(to:maxBreadcrumb:)` (#2416)
- Remove `- [SentryOptions initWithDict:didFailWithError:]` (#2404)
- Remove `- [SentryOptions sdkInfo]` (#2404)

## 7.31.2

Expand Down
4 changes: 2 additions & 2 deletions Samples/iOS-Swift/iOS-Swift/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class ViewController: UIViewController {
scope.setTag(value: "swift", key: "language")
scope.setExtra(value: String(describing: self), key: "currentViewController")

let user = Sentry.User(userId: "1")
let user = SentryUser(userId: "1")
user.email = "[email protected]"
scope.setUser(user)

Expand All @@ -33,7 +33,7 @@ class ViewController: UIViewController {
}

// Also works
let user = Sentry.User(userId: "1")
let user = SentryUser(userId: "1")
user.email = "[email protected]"
SentrySDK.setUser(user)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class TraceTestViewController: UIViewController {
return
}

UIAssert.isEqual(child.data?["url"] as? String, "/sentry-logo-black.png", "Could not read url data value")
UIAssert.isEqual(child.data["url"] as? String, "/sentry-logo-black.png", "Could not read url data value")

UIAssert.isEqual(child.tags["http.status_code"], "200", "Could not read status_code tag value")

Expand Down
1 change: 0 additions & 1 deletion Sources/Sentry/Public/SentryClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

NS_ASSUME_NONNULL_BEGIN

NS_SWIFT_NAME(Client)
@interface SentryClient : NSObject
SENTRY_NO_INIT

Expand Down
2 changes: 1 addition & 1 deletion Sources/Sentry/Public/SentrySpanProtocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ NS_SWIFT_NAME(Span)
/**
* An arbitrary mapping of additional metadata of the span.
*/
@property (nullable, readonly) NSDictionary<NSString *, id> *data;
@property (readonly) NSDictionary<NSString *, id> *data;

/**
* key-value pairs holding additional data about the span.
Expand Down
1 change: 0 additions & 1 deletion Sources/Sentry/Public/SentryUser.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

NS_ASSUME_NONNULL_BEGIN

NS_SWIFT_NAME(User)
@interface SentryUser : NSObject <SentrySerializable, NSCopying>

/**
Expand Down
14 changes: 10 additions & 4 deletions Sources/Sentry/SentryFileManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,13 @@ - (nullable instancetype)initWithOptions:(SentryOptions *)options
self.currentFileCounter = 0;
self.maxEnvelopes = options.maxCacheItems;

[dispatchQueueWrapper dispatchAfter:10
block:^{ [self deleteOldEnvelopesFromAllSentryPaths]; }];
SENTRY_LOG_DEBUG(@"Dispatching deletion of old envelopes from %@", self);
[dispatchQueueWrapper
dispatchAfter:10
block:^{
SENTRY_LOG_DEBUG(@"Dispatched deletion of old envelopes from %@", self);
[self deleteOldEnvelopesFromAllSentryPaths];
}];
}
return self;
}
Expand Down Expand Up @@ -196,7 +201,7 @@ - (void)deleteOldEnvelopesFromAllSentryPaths
NSDictionary *dict = [[NSFileManager defaultManager] attributesOfItemAtPath:fullPath
error:nil];
if (!dict || dict[NSFileType] != NSFileTypeDirectory) {
SENTRY_LOG_DEBUG(@"Could not get NSFileTypeDirectory from %@", fullPath);
SENTRY_LOG_WARN(@"Could not get NSFileTypeDirectory from %@", fullPath);
continue;
}

Expand All @@ -214,7 +219,7 @@ - (void)deleteOldEnvelopesFromPath:(NSString *)envelopesPath
NSDictionary *dict = [[NSFileManager defaultManager] attributesOfItemAtPath:fullPath
error:nil];
if (!dict || !dict[NSFileCreationDate]) {
SENTRY_LOG_DEBUG(@"Could not get NSFileCreationDate from %@", fullPath);
SENTRY_LOG_WARN(@"Could not get NSFileCreationDate from %@", fullPath);
continue;
}

Expand Down Expand Up @@ -251,6 +256,7 @@ - (BOOL)removeFileAtPath:(NSString *)path
NSFileManager *fileManager = [NSFileManager defaultManager];
NSError *error = nil;
@synchronized(self) {
SENTRY_LOG_DEBUG(@"Deleting %@", path);
[fileManager removeItemAtPath:path error:&error];

if (nil != error) {
Expand Down
4 changes: 2 additions & 2 deletions Sources/Sentry/SentryOutOfMemoryTracker.m
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ - (void)start
// Set to empty list so no breadcrumbs of the current scope are added
event.breadcrumbs = @[];

// Load the previous breascrumbs from disk, which are already serialized
// Load the previous breadcrumbs from disk, which are already serialized
event.serializedBreadcrumbs = [self.fileManager readPreviousBreadcrumbs];
if (event.serializedBreadcrumbs.count > self.options.maxBreadcrumbs) {
event.serializedBreadcrumbs = [event.serializedBreadcrumbs
Expand All @@ -84,7 +84,7 @@ - (void)start
exception.mechanism = mechanism;
event.exceptions = @[ exception ];

// We don't need to upate the releaseName of the event to the previous app state as we
// We don't need to update the releaseName of the event to the previous app state as we
// assume it's not an OOM when the releaseName changed between app starts.
[SentrySDK captureCrashEvent:event];
}
Expand Down
10 changes: 10 additions & 0 deletions Sources/Sentry/SentryPerformanceTracker.m
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,17 @@ - (SentrySpanId *)startSpanWithName:(NSString *)name
BOOL bindToScope = true;
if (span != nil) {
if ([SentryUIEventTracker isUIEventOperation:span.context.operation]) {
SENTRY_LOG_DEBUG(@"Cancelling previous UI event span %@",
span.context.spanId.sentrySpanIdString);
[span finishWithStatus:kSentrySpanStatusCancelled];
} else {
SENTRY_LOG_DEBUG(@"Current scope span %@ is not tracking a UI event",
span.context.spanId.sentrySpanIdString);
bindToScope = false;
}
}

SENTRY_LOG_DEBUG(@"Creating new transaction bound to scope: %d", bindToScope);
newSpan = [SentrySDK.currentHub startTransactionWithContext:context
bindToScope:bindToScope
waitForChildren:YES
Expand Down Expand Up @@ -117,6 +122,8 @@ - (void)measureSpanWithDescription:(NSString *)description
SentrySpanId *spanId = [self startSpanWithName:description
nameSource:source
operation:operation];
SENTRY_LOG_DEBUG(@"Measuring span %@; description %@; operation: %@", spanId.sentrySpanIdString,
description, operation);
[self pushActiveSpan:spanId];
block();
[self popActiveSpan];
Expand Down Expand Up @@ -170,12 +177,14 @@ - (nullable SentrySpanId *)activeSpanId

- (BOOL)pushActiveSpan:(SentrySpanId *)spanId
{
SENTRY_LOG_DEBUG(@"Pushing active span %@", spanId.sentrySpanIdString);
id<SentrySpan> toActiveSpan;
@synchronized(self.spans) {
toActiveSpan = self.spans[spanId];
}

if (toActiveSpan == nil) {
SENTRY_LOG_DEBUG(@"No span found with ID %@", spanId.sentrySpanIdString);
return NO;
}

Expand All @@ -194,6 +203,7 @@ - (void)popActiveSpan

- (void)finishSpan:(SentrySpanId *)spanId
{
SENTRY_LOG_DEBUG(@"Finishing performance span %@", spanId.sentrySpanIdString);
[self finishSpan:spanId withStatus:kSentrySpanStatusOk];
}

Expand Down
4 changes: 3 additions & 1 deletion Sources/Sentry/SentryProfiler.mm
Original file line number Diff line number Diff line change
Expand Up @@ -329,8 +329,10 @@ + (void)captureEnvelopeIfFinished:(SentryProfiler *)profiler spanID:(SentrySpanI
if (profiler->_spansInFlight.count == 0) {
[profiler captureEnvelope];
[profiler->_transactions removeAllObjects];
SENTRY_LOG_DEBUG(@"Span %@ was last being tracked.", spanID.sentrySpanIdString);
} else {
SENTRY_LOG_DEBUG(@"Profiler %@ is waiting for more spans to complete.", profiler);
SENTRY_LOG_DEBUG(@"Profiler %@ is waiting for more spans to complete: %@.", profiler,
profiler->_spansInFlight);
}
}

Expand Down
10 changes: 7 additions & 3 deletions Sources/Sentry/SentrySpan.m
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ - (void)removeDataForKey:(NSString *)key
}
}

- (nullable NSDictionary<NSString *, id> *)data
- (NSDictionary<NSString *, id> *)data
{
@synchronized(_data) {
return [_data copy];
Expand Down Expand Up @@ -119,6 +119,7 @@ - (BOOL)isFinished

- (void)finish
{
SENTRY_LOG_DEBUG(@"Attempting to finish span with id %@", _context.spanId.sentrySpanIdString);
[self finishWithStatus:kSentrySpanStatusOk];
}

Expand All @@ -131,9 +132,12 @@ - (void)finishWithStatus:(SentrySpanStatus)status
SENTRY_LOG_DEBUG(@"Setting span timestamp: %@ at system time %llu", self.timestamp,
(unsigned long long)getAbsoluteTime());
}
if (self.tracer != nil) {
[self.tracer spanFinished:self];
if (self.tracer == nil) {
SENTRY_LOG_DEBUG(
@"No tracer associated with span with id %@", _context.spanId.sentrySpanIdString);
return;
}
[self.tracer spanFinished:self];
}

- (SentryTraceHeader *)toTraceHeader
Expand Down
5 changes: 5 additions & 0 deletions Sources/Sentry/SentrySpanContext.m
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#import "SentrySpanContext.h"
#import "SentryId.h"
#import "SentryLog.h"
#import "SentrySpanId.h"

NS_ASSUME_NONNULL_BEGIN
Expand Down Expand Up @@ -41,6 +42,10 @@ - (instancetype)initWithTraceId:(SentryId *)traceId
self.operation = operation;
self.status = kSentrySpanStatusUndefined;
_tags = [[NSMutableDictionary alloc] init];
SENTRY_LOG_DEBUG(
@"Created span context with trace ID %@; span ID %@; parent span ID %@; operation %@",
traceId.sentryIdString, spanId.sentrySpanIdString, parentId.sentrySpanIdString,
operation);
}
return self;
}
Expand Down
2 changes: 2 additions & 0 deletions Sources/Sentry/SentrySwizzleWrapper.m
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#import "SentrySwizzleWrapper.h"
#import "SentryLog.h"
#import "SentrySwizzle.h"

NS_ASSUME_NONNULL_BEGIN
Expand Down Expand Up @@ -32,6 +33,7 @@ - (void)swizzleSendAction:(SentrySwizzleSendActionCallback)callback forKey:(NSSt
{
// We need to make a copy of the block to avoid ARC of autoreleasing it.
sentrySwizzleSendActionCallbacks[key] = [callback copy];
SENTRY_LOG_DEBUG(@"Swizzling sendAction for %@", key);

if (sentrySwizzleSendActionCallbacks.count != 1) {
return;
Expand Down
34 changes: 26 additions & 8 deletions Sources/Sentry/SentryTracer.m
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,9 @@ - (instancetype)initWithTransactionContext:(SentryTransactionContext *)transacti
{
if (self = [super init]) {
SENTRY_LOG_DEBUG(
@"Starting transaction at system time %llu", (unsigned long long)getAbsoluteTime());
@"Starting transaction ID %@ and name %@ for span ID %@ at system time %llu",
transactionContext.traceId.sentryIdString, transactionContext.name,
transactionContext.spanId.sentrySpanIdString, (unsigned long long)getAbsoluteTime());
self.rootSpan = [[SentrySpan alloc] initWithTracer:self context:transactionContext];
self.transactionContext = transactionContext;
_children = [[NSMutableArray alloc] init];
Expand Down Expand Up @@ -264,8 +266,9 @@ - (void)cancelIdleTimeout
sampled:_rootSpan.context.sampled];
context.spanDescription = description;

SENTRY_LOG_DEBUG(@"Starting child span under %@", parentId.sentrySpanIdString);
SentrySpan *child = [[SentrySpan alloc] initWithTracer:self context:context];
SENTRY_LOG_DEBUG(@"Started child span %@ under %@", child.context.spanId.sentrySpanIdString,
parentId.sentrySpanIdString);
@synchronized(_children) {
[_children addObject:child];
}
Expand All @@ -275,11 +278,15 @@ - (void)cancelIdleTimeout

- (void)spanFinished:(id<SentrySpan>)finishedSpan
{
SENTRY_LOG_DEBUG(@"Finished span %@", finishedSpan.context.spanId.sentrySpanIdString);
// Calling canBeFinished on the rootSpan would end up in an endless loop because canBeFinished
// calls finish on the rootSpan.
if (finishedSpan != self.rootSpan) {
[self canBeFinished];
if (finishedSpan == self.rootSpan) {
SENTRY_LOG_DEBUG(@"Cannot call finish on root span with id %@",
finishedSpan.context.spanId.sentrySpanIdString);
return;
}
[self canBeFinished];
}

- (SentrySpanContext *)context
Expand Down Expand Up @@ -325,7 +332,7 @@ - (void)setStartTimestamp:(nullable NSDate *)startTimestamp
#endif
}

- (nullable NSDictionary<NSString *, id> *)data
- (NSDictionary<NSString *, id> *)data
{
@synchronized(_data) {
return [_data copy];
Expand Down Expand Up @@ -409,9 +416,9 @@ - (void)finish

- (void)finishWithStatus:(SentrySpanStatus)status
{
SENTRY_LOG_DEBUG(@"Finished trace %@", self.traceContext.traceId.sentryIdString);
self.wasFinishCalled = YES;
_finishStatus = status;

[self cancelIdleTimeout];
[self canBeFinished];
}
Expand All @@ -421,17 +428,26 @@ - (void)canBeFinished
// Transaction already finished and captured.
// Sending another transaction and spans with
// the same SentryId would be an error.
if (self.rootSpan.isFinished)
if (self.rootSpan.isFinished) {
SENTRY_LOG_DEBUG(@"Root span with id %@ is already finished",
self.rootSpan.context.spanId.sentrySpanIdString);
return;
}

BOOL hasUnfinishedChildSpansToWaitFor = [self hasUnfinishedChildSpansToWaitFor];
if (!self.wasFinishCalled && !hasUnfinishedChildSpansToWaitFor && [self hasIdleTimeout]) {
SENTRY_LOG_DEBUG(
@"Root span with id %@ isn't waiting on children and needs idle timeout dispatched.",
self.rootSpan.context.spanId.sentrySpanIdString);
[self dispatchIdleTimeout];
return;
}

if (!self.wasFinishCalled || hasUnfinishedChildSpansToWaitFor)
if (!self.wasFinishCalled || hasUnfinishedChildSpansToWaitFor) {
SENTRY_LOG_DEBUG(@"Root span with id %@ has children but isn't waiting for them right now.",
self.rootSpan.context.spanId.sentrySpanIdString);
return;
}

[self finishInternal];
}
Expand Down Expand Up @@ -475,6 +491,8 @@ - (void)finishInternal

@synchronized(_children) {
if (self.idleTimeout > 0.0 && _children.count == 0) {
SENTRY_LOG_DEBUG(@"Was waiting for timeout for UI event trace but it had no children, "
@"will not keep transaction.");
return;
}

Expand Down
Loading

0 comments on commit 6ab21e8

Please sign in to comment.