Skip to content

Commit

Permalink
modified InjectHeader to also modify currentRequest (#245)
Browse files Browse the repository at this point in the history
Co-authored-by: Fernando Draghi <fdraghi@FDraghi-Embrace-MBP.local>
  • Loading branch information
ferdraghi and Fernando Draghi committed May 14, 2024
1 parent 646b536 commit b8ef540
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
6 changes: 5 additions & 1 deletion Sources/EmbraceObjCUtils/source/NSURLSessionTask+Embrace.m
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,17 @@ - (BOOL)injectHeaderWithKey:(NSString *)key value:(NSString *)value {
return NO;
}

if (![self.originalRequest isKindOfClass:[NSMutableURLRequest class]]) {
if (![self.originalRequest isKindOfClass:[NSMutableURLRequest class]] ||
![self.currentRequest isKindOfClass:[NSMutableURLRequest class]]) {
return NO;
}

NSMutableURLRequest *request = (NSMutableURLRequest *)self.originalRequest;
[request setValue:value forHTTPHeaderField:key];

NSMutableURLRequest *currentRequest = (NSMutableURLRequest *)self.currentRequest;
[currentRequest setValue:value forHTTPHeaderField:key];

return YES;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,12 @@ private extension DefaultURLSessionTaskHandlerTests {
let tracingHeader = headers!["traceparent"]
XCTAssertNotNil(tracingHeader)

let currentHeaders = task.currentRequest?.allHTTPHeaderFields
XCTAssertNotNil(currentHeaders)

let currentTracingHeader = currentHeaders!["traceparent"]
XCTAssertNotNil(currentTracingHeader)

let span = try XCTUnwrap(otel.spanProcessor.startedSpans.first)
validateTracingHeaderForSpan(tracingHeader: tracingHeader!, span: span)
} catch let exception {
Expand Down

0 comments on commit b8ef540

Please sign in to comment.