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

fix: SpanProtocol add setData for Swift #1305

Merged
merged 3 commits into from
Sep 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## Unreleased

- fix: SpanProtocol add setData for Swift (#1305)

## 7.2.7

- fix: Remove Trace Headers below iOS 14.0 (#1309)
Expand Down
11 changes: 9 additions & 2 deletions Sources/Sentry/Public/SentrySpanProtocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,17 @@ NS_SWIFT_NAME(Span)
NS_SWIFT_NAME(startChild(operation:description:));

/**
* Sets an extra.
* Sets a value to data.
*/
- (void)setDataValue:(nullable id)value
forKey:(NSString *)key NS_SWIFT_NAME(setExtra(value:key:));
forKey:(NSString *)key NS_SWIFT_NAME(setData(value:key:));

/**
* Use setDataValue instead. This method calls setDataValue, was added by mistake, and will be
* deprecated in a future version.
*/
- (void)setExtraValue:(nullable id)value
forKey:(NSString *)key NS_SWIFT_NAME(setExtra(value:key:));

/**
* Removes a data value.
Expand Down
5 changes: 5 additions & 0 deletions Sources/Sentry/SentrySpan.m
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ - (void)setDataValue:(nullable id)value forKey:(NSString *)key
}
}

- (void)setExtraValue:(nullable id)value forKey:(NSString *)key
{
[self setDataValue:value forKey:key];
}

- (void)removeDataForKey:(NSString *)key
{
@synchronized(_extras) {
Expand Down
5 changes: 5 additions & 0 deletions Sources/Sentry/SentryTracer.m
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,11 @@ - (void)setDataValue:(id)value forKey:(NSString *)key
[self.rootSpan setDataValue:value forKey:key];
}

- (void)setExtraValue:(nullable id)value forKey:(NSString *)key
{
[self setDataValue:value forKey:key];
}

- (void)removeDataForKey:(NSString *)key
{
[self.rootSpan removeDataForKey:key];
Expand Down
7 changes: 7 additions & 0 deletions Tests/SentryTests/Performance/SentryTracerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,13 @@ class SentryTracerTests: XCTestCase {
}
#endif

func testSetExtra_ForwardsToSetData() {
let sut = fixture.getSut()
sut.setExtra(value: 0, key: "key")

XCTAssertEqual(["key": 0], sut.data as! [String: Int])
}

private func getSerializedTransaction() -> [String: Any] {
guard let transaction = fixture.hub.capturedEventsWithScopes.first?.event else {
fatalError("Event must not be nil.")
Expand Down
7 changes: 7 additions & 0 deletions Tests/SentryTests/SentrySpanTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,13 @@ class SentrySpanTests: XCTestCase {
XCTAssertEqual(header.value(), "\(span.context.traceId)-\(span.context.spanId)")
}

func testSetExtra_ForwardsToSetData() {
let sut = SentrySpan(context: SpanContext(operation: "test"))
sut.setExtra(value: 0, key: "key")

XCTAssertEqual(["key": 0], sut.data as! [String: Int])
}

@available(tvOS 10.0, *)
@available(OSX 10.12, *)
@available(iOS 10.0, *)
Expand Down