Skip to content

Commit 7fcaa1a

Browse files
author
Ignacio Bonafonte
committed
Renamed URLSessionConfiguration to URLSessionInstrumentationConfiguration, since URLSessionConfiguration is an already existing class in Foundation
1 parent 813f2c7 commit 7fcaa1a

File tree

5 files changed

+37
-38
lines changed

5 files changed

+37
-38
lines changed

Examples/Network Sample/main.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ func simpleNetworkCallWithDelegate() {
6868
let spanProcessor = SimpleSpanProcessor(spanExporter: StdoutExporter(isDebug: true))
6969
OpenTelemetrySDK.instance.tracerProvider.addSpanProcessor(spanProcessor)
7070

71-
let networkInstrumentation = URLSessionInstrumentation(configuration: URLSessionConfiguration())
71+
let networkInstrumentation = URLSessionInstrumentation(configuration: URLSessionInstrumentationConfiguration())
7272

7373
simpleNetworkCall()
7474
simpleNetworkCallWithDelegate()

Sources/Instrumentation/URLSession/URLSessionInstrumentation.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ private var idKey: Void?
2727
public class URLSessionInstrumentation {
2828
private var requestMap = [String: NetworkRequestState]()
2929

30-
var configuration: URLSessionConfiguration
30+
var configuration: URLSessionInstrumentationConfiguration
3131

3232
private let queue = DispatchQueue(label: "com.datadoghq.ddnetworkinstrumentation")
3333

@@ -43,7 +43,7 @@ public class URLSessionInstrumentation {
4343
return spans
4444
}
4545

46-
public init(configuration: URLSessionConfiguration) {
46+
public init(configuration: URLSessionInstrumentationConfiguration) {
4747
self.configuration = configuration
4848
tracer = OpenTelemetrySDK.instance.tracerProvider.get(instrumentationName: "NSURLSession", instrumentationVersion: "0.0.1") as! TracerSdk
4949
self.injectInNSURLClasses()

Sources/Instrumentation/URLSession/URLSessionConfiguration.swift renamed to Sources/Instrumentation/URLSession/URLSessionInstrumentationConfiguration.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public typealias DataOrFile = Any
2121
public typealias SessionTaskId = String
2222
public typealias HTTPStatus = Int
2323

24-
public struct URLSessionConfiguration {
24+
public struct URLSessionInstrumentationConfiguration {
2525
public init(shouldRecordPayload: ((URLSession) -> (Bool)?)? = nil,
2626
shouldInstrument: ((URLRequest) -> (Bool)?)? = nil,
2727
nameSpan: ((URLRequest) -> (String)?)? = nil,

Sources/OpenTelemetryApi/Trace/SpanBuilder.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
import Foundation
1717

18-
public protocol SpanBuilder: class {
18+
public protocol SpanBuilder: AnyObject {
1919
/// Sets the parent Span to use. If not set, the value of OpenTelemetryContext.activeSpan
2020
/// at startSpan() time will be used as parent.
2121
///

Tests/InstrumentationTests/URLSessionTests/URLSessionInstrumentationTests.swift

Lines changed: 32 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -48,38 +48,38 @@ class URLSessionInstrumentationTests: XCTestCase {
4848
static var requestCopy: URLRequest!
4949
static var responseCopy: HTTPURLResponse!
5050

51-
static var config = URLSessionConfiguration(shouldRecordPayload: nil,
52-
shouldInstrument: { req in
53-
checker.shouldInstrumentCalled = true
54-
if req.url?.host?.contains("dontinstrument") ?? false {
55-
return false
56-
}
57-
return true
58-
59-
},
60-
nameSpan: { req in
61-
checker.nameSpanCalled = true
62-
if req.url?.host?.contains("defaultName") ?? false {
63-
return nil
64-
}
65-
return "new name"
66-
},
67-
shouldInjectTracingHeaders: { _ in
68-
checker.shouldInjectTracingHeadersCalled = true
69-
return true
70-
71-
},
72-
createdRequest: { request, _ in
73-
requestCopy = request
74-
checker.createdRequestCalled = true
75-
},
76-
receivedResponse: { response, _, _ in
77-
responseCopy = response as? HTTPURLResponse
78-
checker.receivedResponseCalled = true
79-
},
80-
receivedError: { _, _, _, _ in
81-
URLSessionInstrumentationTests.checker.receivedErrorCalled = true
82-
})
51+
static var config = URLSessionInstrumentationConfiguration(shouldRecordPayload: nil,
52+
shouldInstrument: { req in
53+
checker.shouldInstrumentCalled = true
54+
if req.url?.host?.contains("dontinstrument") ?? false {
55+
return false
56+
}
57+
return true
58+
59+
},
60+
nameSpan: { req in
61+
checker.nameSpanCalled = true
62+
if req.url?.host?.contains("defaultName") ?? false {
63+
return nil
64+
}
65+
return "new name"
66+
},
67+
shouldInjectTracingHeaders: { _ in
68+
checker.shouldInjectTracingHeadersCalled = true
69+
return true
70+
71+
},
72+
createdRequest: { request, _ in
73+
requestCopy = request
74+
checker.createdRequestCalled = true
75+
},
76+
receivedResponse: { response, _, _ in
77+
responseCopy = response as? HTTPURLResponse
78+
checker.receivedResponseCalled = true
79+
},
80+
receivedError: { _, _, _, _ in
81+
URLSessionInstrumentationTests.checker.receivedErrorCalled = true
82+
})
8383

8484
static var checker = Check()
8585
static var semaphore: DispatchSemaphore!
@@ -355,5 +355,4 @@ class URLSessionInstrumentationTests: XCTestCase {
355355
XCTAssertTrue(URLSessionInstrumentationTests.checker.createdRequestCalled)
356356
XCTAssertNotNil(URLSessionInstrumentationTests.requestCopy?.allHTTPHeaderFields?[W3CTraceContextPropagator.traceparent])
357357
}
358-
359358
}

0 commit comments

Comments
 (0)