Skip to content
Draft
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
2 changes: 2 additions & 0 deletions Agent/Analytics/Constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ extern NSString *const kNRMA_Attrib_networkErrorCode;
extern NSString *const kNRMA_Attrib_networkError;
extern NSString *const kNRMA_Attrib_errorType;
extern NSString *const kNRMA_Attrib_contentType;
extern NSString *const kNRMA_Attrib_resourceFetchType;
extern NSString *const kNRMA_Attrib_wireStatusCode;
extern NSString *const kNRMA_Attrib_dtGuid;
extern NSString *const kNRMA_Attrib_dtId;
extern NSString *const kNRMA_Attrib_dtTraceId;
Expand Down
2 changes: 2 additions & 0 deletions Agent/Analytics/Constants.m
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@
NSString * const kNRMA_Attrib_networkError = @"networkError";
NSString * const kNRMA_Attrib_errorType = @"errorType";
NSString * const kNRMA_Attrib_contentType = @"contentType";
NSString * const kNRMA_Attrib_resourceFetchType = @"resourceFetchType";
NSString * const kNRMA_Attrib_wireStatusCode = @"wireStatusCode";
NSString * const kNRMA_Attrib_dtGuid = @"guid";
NSString * const kNRMA_Attrib_dtId = @"id";
NSString * const kNRMA_Attrib_dtTraceId = @"trace.id";
Expand Down
24 changes: 20 additions & 4 deletions Agent/Analytics/NRMAAnalytics.mm
Original file line number Diff line number Diff line change
Expand Up @@ -332,13 +332,21 @@ - (BOOL)addRequestEvent:(NRMANetworkRequestData *)requestData
if (contentType.length > 0) {
[event addAttribute:kNRMA_Attrib_contentType value:contentType];
}


if (responseData.resourceFetchType.length > 0) {
[event addAttribute:kNRMA_Attrib_resourceFetchType value:responseData.resourceFetchType];
}

if (responseData.wireStatusCode != 0) {
[event addAttribute:kNRMA_Attrib_wireStatusCode value:@(responseData.wireStatusCode)];
}

if (requestData.trackedHeaders.count > 0) {
for(NSString* key in requestData.trackedHeaders.allKeys) {
[event addAttribute:key value:requestData.trackedHeaders[key]];
}
}

return [_eventManager addEvent:[event autorelease]];
} @catch (NSException *exception) {
NRLOG_AGENT_ERROR(@"Failed to add Network Event.: %@", exception.reason);
Expand Down Expand Up @@ -468,13 +476,21 @@ - (BOOL) addHTTPErrorEvent:(NRMANetworkRequestData *)requestData
if (contentType.length > 0) {
[event addAttribute:kNRMA_Attrib_contentType value:contentType];
}


if (responseData.resourceFetchType.length > 0) {
[event addAttribute:kNRMA_Attrib_resourceFetchType value:responseData.resourceFetchType];
}

if (responseData.wireStatusCode != 0) {
[event addAttribute:kNRMA_Attrib_wireStatusCode value:@(responseData.wireStatusCode)];
}

if (requestData.trackedHeaders.count > 0) {
for(NSString* key in requestData.trackedHeaders.allKeys) {
[event addAttribute:key value:requestData.trackedHeaders[key]];
}
}

return event;
} @catch (NSException *exception) {
NRLOG_AGENT_ERROR(@"Failed to add Network Event.: %@", exception.reason);
Expand Down
9 changes: 9 additions & 0 deletions Agent/Analytics/NRMANetworkResponseData.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,15 @@
@property (nonatomic, retain) NSString* encodedResponseBody;
@property (nonatomic) NSInteger networkErrorCode;

/// Apple's NSURLSessionTaskMetricsResourceFetchType for the final transaction.
/// Values: @"unknown", @"networkLoad", @"serverPush", @"localCache". nil when not captured.
@property (nonatomic, retain) NSString* resourceFetchType;

/// Underlying wire status code from the final NSURLSessionTaskTransactionMetrics.
/// Useful when Apple's URLCache rewrites a 304 to 200 in the user-visible response.
/// 0 means not captured.
@property (nonatomic) NSInteger wireStatusCode;

@property double timeInSeconds;

-(id) initWithSuccessfulResponse:(NSInteger)statusCode
Expand Down
2 changes: 2 additions & 0 deletions Agent/FeatureFlags/NRMAFlags.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@

+ (BOOL) shouldEnableAutoCollectLogs;

+ (BOOL) shouldEnableURLSessionDelegateInjection;

+ (NSArray<NSString*>*) namesForFlags:(NRMAFeatureFlags)flags;

// Private Setting
Expand Down
9 changes: 8 additions & 1 deletion Agent/FeatureFlags/NRMAFlags.m
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,10 @@ + (BOOL) shouldEnableAutoCollectLogs {
return ([NRMAFlags featureFlags] & NRFeatureFlag_AutoCollectLogs) != 0;
}

+ (BOOL) shouldEnableURLSessionDelegateInjection {
return ([NRMAFlags featureFlags] & NRFeatureFlag_URLSessionDelegateInjection) != 0;
}

+ (NSArray<NSString*>*) namesForFlags:(NRMAFeatureFlags)flags {
NSMutableArray *retArray = [NSMutableArray array];
if ((flags & NRFeatureFlag_InteractionTracing) == NRFeatureFlag_InteractionTracing) {
Expand Down Expand Up @@ -251,7 +255,10 @@ + (BOOL) shouldEnableAutoCollectLogs {
if ((flags & NRFeatureFlag_AutoCollectLogs) == NRFeatureFlag_AutoCollectLogs) {
[retArray addObject:@"AutoCollectLogs"];
}

if ((flags & NRFeatureFlag_URLSessionDelegateInjection) == NRFeatureFlag_URLSessionDelegateInjection) {
[retArray addObject:@"URLSessionDelegateInjection"];
}

return retArray;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,25 @@ andBody:(NSData *)body
bytesSent:(NSUInteger)sent
bytesReceived:(NSUInteger)received;

+ (void)noticeResponse:(NSURLResponse *)response
forRequest:(NSURLRequest *)request
withTimer:(NRTimer *)timer
andBody:(NSData *)body
bytesSent:(NSUInteger)sent
bytesReceived:(NSUInteger)received
resourceFetchType:(NSString *)resourceFetchType
wireStatusCode:(NSInteger)wireStatusCode;

+ (void)noticeResponse:(NSURLResponse *)response
forRequest:(NSURLRequest *)request
withTimer:(NRTimer *)timer
andBody:(NSData *)body
bytesSent:(NSUInteger)sent
bytesReceived:(NSUInteger)received
resourceFetchType:(NSString *)resourceFetchType
wireStatusCode:(NSInteger)wireStatusCode
wireBytesReceived:(int64_t)wireBytesReceived;

+ (void)noticeError:(NSError*)error
forRequest:(NSURLRequest *)request
withTimer:(NRTimer *)timer;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,46 @@ + (void)noticeResponse:(NSURLResponse *)response
andBody:(NSData *)body
bytesSent:(NSUInteger)sent
bytesReceived:(NSUInteger)received
{
[self noticeResponse:response
forRequest:request
withTimer:timer
andBody:body
bytesSent:sent
bytesReceived:received
resourceFetchType:nil
wireStatusCode:0];
}

+ (void)noticeResponse:(NSURLResponse *)response
forRequest:(NSURLRequest *)request
withTimer:(NRTimer *)timer
andBody:(NSData *)body
bytesSent:(NSUInteger)sent
bytesReceived:(NSUInteger)received
resourceFetchType:(NSString *)resourceFetchType
wireStatusCode:(NSInteger)wireStatusCode
{
[self noticeResponse:response
forRequest:request
withTimer:timer
andBody:body
bytesSent:sent
bytesReceived:received
resourceFetchType:resourceFetchType
wireStatusCode:wireStatusCode
wireBytesReceived:0];
}

+ (void)noticeResponse:(NSURLResponse *)response
forRequest:(NSURLRequest *)request
withTimer:(NRTimer *)timer
andBody:(NSData *)body
bytesSent:(NSUInteger)sent
bytesReceived:(NSUInteger)received
resourceFetchType:(NSString *)resourceFetchType
wireStatusCode:(NSInteger)wireStatusCode
wireBytesReceived:(int64_t)wireBytesReceived
{
// ignore self-instrumentation here, the agent records this stuff into Supportability metrics elsewhere
if ([NRMANSURLConnectionSupport isNewRelicServiceRequest:request]) {
Expand All @@ -335,7 +375,10 @@ + (void)noticeResponse:(NSURLResponse *)response
bytesReceived:received
responseData:body
traceHeaders:nil
params:nil];
params:nil
resourceFetchType:resourceFetchType
wireStatusCode:wireStatusCode
wireBytesReceived:wireBytesReceived];
}

+ (NRMANSURLConnectionDelegate*) generateProxyFromDelegate:(id<NSURLConnectionDelegate>)realDelegate
Expand Down
12 changes: 12 additions & 0 deletions Agent/Instrumentation/NSURLSession/NRMAURLSessionOverride.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,14 @@

#define kNRTimerAssociatedObject @"com.NewRelic.NRSessionTask.Timer"
#define kNRSessionDataAssociatedObject @"com.NewRelic.NRSessionTask.Data"
#define kNRFetchTypeAssociatedObject @"com.NewRelic.NRSessionTask.FetchType"
#define kNRWireStatusAssociatedObject @"com.NewRelic.NRSessionTask.WireStatus"
#define kNRWireBytesAssociatedObject @"com.NewRelic.NRSessionTask.WireBytes"


NSURLSession* NRMAOverride__sessionWithConfiguration_delegate_delegateQueue(id self,SEL _cmd,NSURLSessionConfiguration* configuration,id<NSURLSessionDelegate>delegate,NSOperationQueue* queue);
NSURLSession* NRMAOverride__sessionWithConfiguration(id self, SEL _cmd, NSURLSessionConfiguration* configuration);
NSURLSession* NRMAOverride__sharedSession(id self, SEL _cmd);

NSURLSessionTask* NRMAOverride__dataTaskWithRequest(id self, SEL _cmd, NSURLRequest* request);
NSURLSessionTask* NRMAOverride__dataTaskWithURL(id self, SEL _cmd, NSURL* url);
Expand All @@ -33,6 +38,13 @@ NSData* NRMA__getDataForSessionTask(NSURLSessionTask* task);
void NRMA__setDataForSessionTask(NSURLSessionTask* task, NSData* data);
void NRMA__setTimerForSessionTask(NSURLSessionTask* task, NRTimer* timer);

NSString* NRMA__getFetchTypeForSessionTask(NSURLSessionTask* task);
void NRMA__setFetchTypeForSessionTask(NSURLSessionTask* task, NSString* fetchType);
NSInteger NRMA__getWireStatusForSessionTask(NSURLSessionTask* task);
void NRMA__setWireStatusForSessionTask(NSURLSessionTask* task, NSInteger wireStatus);
int64_t NRMA__getWireBytesForSessionTask(NSURLSessionTask* task);
void NRMA__setWireBytesForSessionTask(NSURLSessionTask* task, int64_t wireBytes);

@interface NRMAURLSessionOverride : NSObject
+ (void) beginInstrumentation;
+ (void) deinstrument;
Expand Down
Loading
Loading