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

Expose span baggage API #4207

Merged
merged 28 commits into from
Aug 16, 2024
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
cc7f47b
Expose `SentrySpan` baggage http header
denrase Jul 30, 2024
6638657
Merge branch 'main' into feat/expose-span-baggage
denrase Jul 30, 2024
0b2ec13
Expose `SentryTracer`, `SentryTraceContext` and `SentryBaggage`
denrase Jul 30, 2024
272cf2a
Format code
getsentry-bot Jul 30, 2024
880250c
Expose baggageHttpHeader on span protocol
denrase Jul 30, 2024
d797e84
Merge branch 'feat/expose-span-baggage' of github.com:getsentry/sentr…
denrase Jul 30, 2024
89f782b
Format code
getsentry-bot Jul 30, 2024
2631f8d
Expose `SentrySpanProtocol.traceContext`
denrase Jul 30, 2024
d9a5939
Merge branch 'feat/expose-span-baggage' of github.com:getsentry/sentr…
denrase Jul 30, 2024
7bfd249
Format code
getsentry-bot Jul 30, 2024
5fe3cf3
add cl entry
denrase Jul 30, 2024
8fa465e
Merge branch 'feat/expose-span-baggage' of github.com:getsentry/sentr…
denrase Jul 30, 2024
a58b106
update APIs for new traceContext getter
denrase Jul 30, 2024
bf5b3d8
fix span protocol exposition of trace context
denrase Jul 30, 2024
70abd57
Merge branch 'main' into feat/expose-span-baggage
denrase Aug 5, 2024
6d79486
remove nil check
denrase Aug 5, 2024
3b0018f
Merge branch 'main' into feat/expose-span-baggage
denrase Aug 13, 2024
9f151e9
fix cl
denrase Aug 13, 2024
7e657fc
REVERT ME: remove logging to loig file so we can see ci output directly
denrase Aug 14, 2024
5f7587e
add import in sentry.h and define swift name
denrase Aug 14, 2024
d572eab
generate framework without uikit first
denrase Aug 14, 2024
eb609f2
make trace context public
denrase Aug 14, 2024
902ce41
expose SentryBaggage
denrase Aug 14, 2024
799bec7
revert build scripts
denrase Aug 14, 2024
0697e3b
Merge branch 'main' into feat/expose-span-baggage
denrase Aug 14, 2024
c284f77
remove „Sentry“ prefix in swift files
denrase Aug 14, 2024
25f9740
move baggage and tracecontext to public path
denrase Aug 14, 2024
fe1cd3e
update private headers
denrase Aug 14, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

- Replay for crashes (#4171)
- Redact web view from replay (#4203)
- Expose span baggage API (#4207)

## 8.32.0

Expand Down
14 changes: 12 additions & 2 deletions Sources/Sentry/Public/SentrySpanProtocol.h
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
#import "SentryDefines.h"
#import "SentrySerializable.h"
#import "SentrySpanContext.h"

NS_ASSUME_NONNULL_BEGIN

@class SentrySpanId, SentryId, SentryTraceHeader, SentryMeasurementUnit;
@class SentrySpanId, SentryId, SentryTraceHeader, SentryMeasurementUnit, SentryTraceContext;

NS_SWIFT_NAME(Span)
@protocol SentrySpan <SentrySerializable>
Expand Down Expand Up @@ -80,6 +79,11 @@ NS_SWIFT_NAME(Span)
*/
@property (readonly) BOOL isFinished;

/**
* Retrieves a trace context from this tracer.
*/
@property (nullable, nonatomic, readonly) SentryTraceContext *traceContext;

/**
* Starts a child span.
* @param operation Short code identifying the type of operation the span is measuring.
Expand Down Expand Up @@ -167,6 +171,12 @@ NS_SWIFT_NAME(Span)
*/
- (SentryTraceHeader *)toTraceHeader;

/**
* Returns the baggage http header
* @return NSString.
*/
- (nullable NSString *)baggageHttpHeader;

@end

NS_ASSUME_NONNULL_END
2 changes: 2 additions & 0 deletions Sources/Sentry/Public/SentryWithoutUIKit.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ FOUNDATION_EXPORT const unsigned char SentryVersionString[];

# import <SentryWithoutUIKit/Sentry.h>
# import <SentryWithoutUIKit/SentryAttachment.h>
# import <SentryWithoutUIKit/SentryBaggage.h>
# import <SentryWithoutUIKit/SentryBreadcrumb.h>
# import <SentryWithoutUIKit/SentryClient.h>
# import <SentryWithoutUIKit/SentryCrashExceptionApplication.h>
Expand Down Expand Up @@ -42,6 +43,7 @@ FOUNDATION_EXPORT const unsigned char SentryVersionString[];
# import <SentryWithoutUIKit/SentrySpanStatus.h>
# import <SentryWithoutUIKit/SentryStacktrace.h>
# import <SentryWithoutUIKit/SentryThread.h>
# import <SentryWithoutUIKit/SentryTraceContext.h>
# import <SentryWithoutUIKit/SentryTraceHeader.h>
# import <SentryWithoutUIKit/SentryTransactionContext.h>
# import <SentryWithoutUIKit/SentryUser.h>
Expand Down
19 changes: 19 additions & 0 deletions Sources/Sentry/SentrySpan.m
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#import "SentryBaggage.h"
#import "SentryCrashThread.h"
#import "SentryDependencyContainer.h"
#import "SentryFrame.h"
Expand All @@ -13,6 +14,7 @@
#import "SentrySwift.h"
#import "SentryThreadInspector.h"
#import "SentryTime.h"
#import "SentryTraceContext.h"
#import "SentryTraceHeader.h"
#import "SentryTracer.h"

Expand Down Expand Up @@ -297,6 +299,23 @@
sampled:self.sampled];
}

// Getter for the computed property baggage
- (nullable NSString *)baggageHttpHeader
{
if (nil == self.tracer) {
return nil;

Check warning on line 306 in Sources/Sentry/SentrySpan.m

View check run for this annotation

Codecov / codecov/patch

Sources/Sentry/SentrySpan.m#L306

Added line #L306 was not covered by tests
}
return [[self.tracer.traceContext toBaggage] toHTTPHeaderWithOriginalBaggage:nil];
}

- (nullable SentryTraceContext *)traceContext
{
if (nil == self.tracer) {
return nil;

Check warning on line 314 in Sources/Sentry/SentrySpan.m

View check run for this annotation

Codecov / codecov/patch

Sources/Sentry/SentrySpan.m#L314

Added line #L314 was not covered by tests
}
denrase marked this conversation as resolved.
Show resolved Hide resolved
return self.tracer.traceContext;
}

- (LocalMetricsAggregator *)getLocalMetricsAggregator
{
if (localMetricsAggregator == nil) {
Expand Down
11 changes: 7 additions & 4 deletions Sources/Sentry/SentryTracer.m
Original file line number Diff line number Diff line change
Expand Up @@ -412,14 +412,17 @@ - (void)spanFinished:(id<SentrySpan>)finishedSpan
[self canBeFinished];
}

- (SentryTraceContext *)traceContext
- (nullable SentryTraceContext *)traceContext
{
if (_traceContext == nil) {
@synchronized(self) {
if (_traceContext == nil) {
_traceContext = [[SentryTraceContext alloc] initWithTracer:self
scope:_hub.scope
options:SentrySDK.options];
_traceContext = [[SentryTraceContext alloc]
initWithTracer:self
scope:_hub.scope
options:_hub.client.options
?: SentrySDK.options]; // We should remove static classes and always
// inject dependencies.
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions Sources/Sentry/include/HybridPublic/SentryEnvelope.h
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
#import "PrivatesHeader.h"

#if COCOAPODS
@class SentrySdkInfo, SentryTraceContext;
@class SentrySdkInfo;
#else
# import "SentrySdkInfo.h"
# import "SentryTraceContext.h"

#endif

Expand All @@ -14,6 +13,7 @@
@class SentryUserFeedback;
@class SentryAttachment;
@class SentryEnvelopeItemHeader;
@class SentryTraceContext;

NS_ASSUME_NONNULL_BEGIN

Expand Down
5 changes: 0 additions & 5 deletions Sources/Sentry/include/SentryTracer.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,6 @@ static const NSTimeInterval SENTRY_AUTO_TRANSACTION_MAX_DURATION = 500.0;

@property (nullable, nonatomic, copy) BOOL (^shouldIgnoreWaitForChildrenCallback)(id<SentrySpan>);

/**
* Retrieves a trace context from this tracer.
*/
@property (nonatomic, readonly) SentryTraceContext *traceContext;

/**
* All the spans that where created with this tracer but rootSpan.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ class SentryNetworkTrackerIntegrationTests: XCTestCase {
self.assertNetworkError(error)
let response = String(data: data ?? Data(), encoding: .utf8) ?? ""

let expectedBaggageHeader = transaction.traceContext.toBaggage().toHTTPHeader(withOriginalBaggage: nil)
let expectedBaggageHeader = transaction.traceContext?.toBaggage().toHTTPHeader(withOriginalBaggage: nil)
XCTAssertEqual(expectedBaggageHeader, response)

expect.fulfill()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -665,7 +665,7 @@ class SentryNetworkTrackerTests: XCTestCase {
let transaction = try XCTUnwrap(startTransaction() as? SentryTracer)
sut.urlSessionTaskResume(task)

let expectedBaggageHeader = transaction.traceContext.toBaggage().toHTTPHeader(withOriginalBaggage: nil)
let expectedBaggageHeader = transaction.traceContext?.toBaggage().toHTTPHeader(withOriginalBaggage: nil)
XCTAssertEqual(task.currentRequest?.allHTTPHeaderFields?["baggage"] ?? "", expectedBaggageHeader)
}

Expand Down
4 changes: 2 additions & 2 deletions Tests/SentryTests/SentrySDKTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ class SentrySDKTests: XCTestCase {

XCTAssertEqual(operation, transaction.operation)
let tracer = try XCTUnwrap(transaction as? SentryTracer)
XCTAssertEqual(name, tracer.traceContext.transaction)
XCTAssertEqual(name, tracer.traceContext?.transaction)

XCTAssertNil(SentrySDK.span)
}
Expand All @@ -410,7 +410,7 @@ class SentrySDKTests: XCTestCase {

XCTAssertEqual(fixture.operation, transaction.operation)
let tracer = try XCTUnwrap(transaction as? SentryTracer)
XCTAssertEqual(fixture.transactionName, tracer.traceContext.transaction)
XCTAssertEqual(fixture.transactionName, tracer.traceContext?.transaction)
XCTAssertEqual(.custom, tracer.transactionContext.nameSource)

let newSpan = SentrySDK.span
Expand Down
16 changes: 16 additions & 0 deletions Tests/SentryTests/Transaction/SentrySpanTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -676,6 +676,22 @@ class SentrySpanTests: XCTestCase {
XCTAssertEqual(nameForSentrySpanStatus(.dataLoss), kSentrySpanStatusNameDataLoss)
}

func testTraceContext() {
let client = TestClient(options: fixture.options)!
let sut = fixture.getSut(client: client) as! SentrySpan

let expectedTraceContext = sut.tracer?.traceContext
XCTAssertEqual(expectedTraceContext, sut.traceContext)
}

func testBaggageHttpHeader() {
let client = TestClient(options: fixture.options)!
let sut = fixture.getSut(client: client) as! SentrySpan

let expectedBaggage = sut.tracer?.traceContext?.toBaggage().toHTTPHeader(withOriginalBaggage: nil)
XCTAssertEqual(expectedBaggage, sut.baggageHttpHeader())
}

#if os(iOS) || os(tvOS) || targetEnvironment(macCatalyst)
func testAddSlowFrozenFramesToData() {
let (displayLinkWrapper, framesTracker) = givenFramesTracker()
Expand Down
Loading