Skip to content

Commit a8b4d3f

Browse files
Backport NR-234826
1 parent 71c95be commit a8b4d3f

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

Agent/Instrumentation/NSURLSession/NRMAURLSessionTaskOverride.m

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,13 +119,28 @@ void NRMAOverride__urlSessionTask_SetState(NSURLSessionTask* task, SEL _cmd, NSU
119119
if ([NRMAURLSessionTaskOverride isSupportedTaskType: task]) {
120120
// Checking for NEW_RELIC_CROSS_PROCESS_ID_HEADER_KEY in the headers here. The data usually isn't link to the task yet here so, if that header exists we are handling the task elsewhere and have a better chance of getting the data so we don't need to record it here.
121121
NSURLRequest *currentRequest = task.currentRequest;
122-
if(currentRequest != nil && [currentRequest valueForHTTPHeaderField:NEW_RELIC_CROSS_PROCESS_ID_HEADER_KEY] != nil) {
122+
123+
if (currentRequest == nil) {
123124
return;
124125
}
125-
126+
127+
if ([currentRequest valueForHTTPHeaderField:NEW_RELIC_CROSS_PROCESS_ID_HEADER_KEY] != nil) {
128+
return;
129+
}
130+
126131
NSURL *url = [currentRequest URL];
127132
if (url != nil &&
128133
newState != NSURLSessionTaskStateRunning && task.state == NSURLSessionTaskStateRunning) {
134+
135+
// Added this section to add Distributed Tracing traceId\trace.id, guid,id and payload.
136+
//1
137+
NSMutableURLRequest* mutableRequest = [NRMAHTTPUtilities addCrossProcessIdentifier:currentRequest];
138+
mutableRequest = [NRMAHTTPUtilities addConnectivityHeaderAndPayload:mutableRequest];
139+
140+
NRMAPayloadContainer* payload = [NRMAHTTPUtilities addConnectivityHeader:mutableRequest];
141+
[NRMAHTTPUtilities attachPayload:payload
142+
to:task.originalRequest];
143+
129144
// get response code
130145
NSUInteger responseCode = [NRMAURLSessionTaskOverride statusCode:task.response];
131146
if (responseCode != -1) {

0 commit comments

Comments
 (0)