这是indexloc提供的服务,不要输入任何密码
Skip to content
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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## Unreleased

### Fixes

- Remove Sentry keys from cached HTTP request headers (#1975)

## 7.21.0

### Features
Expand Down
6 changes: 5 additions & 1 deletion Sources/Sentry/SentryNetworkTracker.m
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,11 @@ - (nullable NSDictionary *)addTraceHeader:(nullable NSDictionary *)headers

id<SentrySpan> span = SentrySDK.currentHub.scope.span;
if (span == nil) {
return headers;
// Remove the Sentry keys from the cached headers (cached by NSURLSession itself),
// because it could contain a completely unrelated trace id from a previous request.
NSMutableDictionary *existingHeaders = headers.mutableCopy;
[existingHeaders removeObjectsForKeys:@[ SENTRY_TRACE_HEADER, SENTRY_BAGGAGE_HEADER ]];
return [existingHeaders copy];
Comment on lines +289 to +291
Copy link
Contributor

Choose a reason for hiding this comment

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

Please just add a comment here why we removing the header.
Because NSURLSession itself caches its, and were good to go.

}

NSMutableDictionary *result = [[NSMutableDictionary alloc] initWithDictionary:headers];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,14 @@ class SentryNetworkTrackerTests: XCTestCase {
XCTAssertNotNil(headers?["baggage"])
XCTAssertNotNil(headers?["sentry-trace"])
}

func test_RemoveExistingTraceHeader_WhenNoSpan() {
let sut = fixture.getSut()
let headers = sut.addTraceHeader(["a": "a", "baggage": "baggage", "sentry-trace": "sentry-trace"])
XCTAssertEqual(headers?.count, 1)
XCTAssertNil(headers?["baggage"])
XCTAssertNil(headers?["sentry-trace"])
}

func test_AddTraceHeader_NoTransaction() {
let sut = fixture.getSut()
Expand Down