-
Notifications
You must be signed in to change notification settings - Fork 134
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
RUM-717 feat!: Add network instrumentation for async/await URLSession…
… APIs
- Loading branch information
Showing
42 changed files
with
1,953 additions
and
745 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
DatadogCore/Tests/DatadogObjc/DDURLSessionInstrumentationConfigurationTests.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* | ||
* Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0. | ||
* This product includes software developed at Datadog (https://www.datadoghq.com/). | ||
* Copyright 2019-Present Datadog, Inc. | ||
*/ | ||
|
||
import XCTest | ||
import TestUtilities | ||
import DatadogInternal | ||
@testable import DatadogObjc | ||
|
||
final class DDURLSessionInstrumentationConfigurationTests: XCTestCase { | ||
private var objc = DDURLSessionInstrumentationConfiguration(delegateClass: MockDelegate.self) | ||
private var swift: URLSessionInstrumentation.Configuration { objc.swiftConfig } | ||
|
||
func testDelegateClass() { | ||
XCTAssertTrue(objc.delegateClass === MockDelegate.self) | ||
} | ||
|
||
func testFirstPartyHostsTracing() { | ||
objc.setFirstPartyHostsTracing(.init(hosts: ["example.com", "example.org"])) | ||
DDAssertReflectionEqual(swift.firstPartyHostsTracing, .trace(hosts: ["example.com", "example.org"])) | ||
|
||
objc.setFirstPartyHostsTracing(.init(hostsWithHeaderTypes: ["example.com": [.b3, .datadog]])) | ||
DDAssertReflectionEqual(swift.firstPartyHostsTracing, .traceWithHeaders(hostsWithHeaders: ["example.com": [.b3, .datadog]])) | ||
} | ||
|
||
class MockDelegate: NSObject, URLSessionDataDelegate { | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
DatadogCore/Tests/DatadogObjc/ObjcAPITests/DDURLSessionInstrumentationTests+apiTests.m
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/* | ||
* Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0. | ||
* This product includes software developed at Datadog (https://www.datadoghq.com/). | ||
* Copyright 2019-Present Datadog, Inc. | ||
*/ | ||
|
||
#import <XCTest/XCTest.h> | ||
#include <sys/wait.h> | ||
@import DatadogObjc; | ||
@import DatadogTrace; | ||
|
||
#import <Foundation/Foundation.h> | ||
|
||
@interface MockDelegate : NSObject <NSURLSessionDataDelegate> | ||
@end | ||
|
||
@implementation MockDelegate | ||
@end | ||
|
||
@interface DDURLSessionInstrumentationTests_apiTests : XCTestCase | ||
@end | ||
|
||
@implementation DDURLSessionInstrumentationTests_apiTests | ||
|
||
#pragma clang diagnostic push | ||
#pragma clang diagnostic ignored "-Wunused-value" | ||
|
||
- (void)setUp { | ||
[super setUp]; | ||
|
||
DDConfiguration *configuration = [[DDConfiguration alloc] initWithClientToken:@"abc" env:@"def"]; | ||
[DDDatadog initializeWithConfiguration:configuration trackingConsent:[DDTrackingConsent notGranted]]; | ||
|
||
DDTraceConfiguration *config = [[DDTraceConfiguration alloc] init]; | ||
DDTraceFirstPartyHostsTracing *tracing = [[DDTraceFirstPartyHostsTracing alloc] initWithHosts:[NSSet new] sampleRate:20]; | ||
DDTraceURLSessionTracking *urlSessionTracking = [[DDTraceURLSessionTracking alloc] initWithFirstPartyHostsTracing:tracing]; | ||
[config setURLSessionTracking:urlSessionTracking]; | ||
[DDTrace enableWith:config]; | ||
} | ||
|
||
- (void)tearDown { | ||
[super tearDown]; | ||
|
||
[DDDatadog clearAllData]; | ||
[DDDatadog flushAndDeinitialize]; | ||
} | ||
|
||
- (void)testWorkflow { | ||
XCTestExpectation *expectation = [self expectationWithDescription:@"task completed"]; | ||
DDURLSessionInstrumentationConfiguration *config = [[DDURLSessionInstrumentationConfiguration alloc] initWithDelegateClass:[MockDelegate class]]; | ||
[DDURLSessionInstrumentation enableWithConfiguration:config]; | ||
|
||
NSURLSession *session = [NSURLSession sessionWithConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration] | ||
delegate:[MockDelegate new] delegateQueue:nil]; | ||
NSURLSessionTask *task = [session dataTaskWithURL:[NSURL URLWithString:@"https://status.datadoghq.com"] | ||
completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) { | ||
[expectation fulfill]; | ||
}]; | ||
[task resume]; | ||
|
||
[self waitForExpectationsWithTimeout:10 handler:nil]; | ||
|
||
[DDURLSessionInstrumentation disableWithDelegateClass:[MockDelegate class]]; | ||
} | ||
|
||
#pragma clang diagnostic pop | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.