Skip to content

Commit 2be9330

Browse files
author
Ignacio Bonafonte
committed
Add changes from code review
1 parent ae520ec commit 2be9330

File tree

6 files changed

+12
-17
lines changed

6 files changed

+12
-17
lines changed

Examples/Network Sample/main.swift

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ func simpleNetworkCall() {
2626

2727
let task = URLSession.shared.dataTask(with: request) { data, _, _ in
2828
if let data = data {
29-
let string = String(data: data, encoding: .utf8)
30-
print(string ?? "")
29+
let string = String(decoding: data, as: UTF8.self)
30+
print(string)
3131
}
3232
semaphore.signal()
3333
}
@@ -40,11 +40,6 @@ func simpleNetworkCall() {
4040
class SessionDelegate: NSObject, URLSessionDataDelegate, URLSessionTaskDelegate {
4141
let semaphore = DispatchSemaphore(value: 0)
4242

43-
// func urlSession(_ session: URLSession, task: URLSessionTask, didFinishCollecting metrics: URLSessionTaskMetrics) {
44-
//
45-
// let a = 0
46-
// }
47-
4843
func urlSession(_ session: URLSession, task: URLSessionTask, didCompleteWithError error: Error?) {
4944
semaphore.signal()
5045
}

Sources/Instrumentation/URLSession/URLSessionInstrumentation.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ public class URLSessionInstrumentation {
2929

3030
var configuration: URLSessionInstrumentationConfiguration
3131

32-
private let queue = DispatchQueue(label: "com.datadoghq.ddnetworkinstrumentation")
32+
private let queue = DispatchQueue(label: "io.opentelemetry.ddnetworkinstrumentation")
3333

34-
static var instrumentedKey = "com.datadoghq.instrumentedCall"
34+
static var instrumentedKey = "io.opentelemetry.instrumentedCall"
3535

3636
public private(set) var tracer: TracerSdk
3737

Sources/Instrumentation/URLSession/URLSessionLogger.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import OpenTelemetrySdk
1919

2020
class URLSessionLogger {
2121
static var runningSpans = [String: Span]()
22-
static var runningSpansQueue = DispatchQueue(label: "org.opentelemetry.URLSessionLogger")
22+
static var runningSpansQueue = DispatchQueue(label: "io.opentelemetry.URLSessionLogger")
2323

2424
/// This methods creates a Span for a request, and optionally injects tracing headers, returns a new request if it was needed to create a new one to add the tracing headers
2525
@discardableResult static func processAndLogRequest(_ request: URLRequest, sessionTaskId: String, instrumentation: URLSessionInstrumentation, shouldInjectHeaders: Bool) -> URLRequest? {

Tests/ExportersTests/DatadogExporter/Helpers/SwiftExtensions.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ extension String {
6666
}
6767

6868
extension Data {
69-
var utf8String: String { String(data: self, encoding: .utf8)! }
69+
var utf8String: String { String(decoding: self, as: UTF8.self) }
7070
}
7171

7272
extension InputStream {

Tests/ExportersTests/Prometheus/PrometheusExporterTests.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@ class PrometheusExporterTests: XCTestCase {
4545
let task = URLSession.shared.dataTask(with: url) { data, response, error in
4646
if error == nil, let data = data, let response = response as? HTTPURLResponse {
4747
XCTAssert(response.statusCode == 200)
48-
let responseText = String(data: data, encoding: .utf8)
49-
print("Response from metric API is: \n\(responseText!)")
50-
self.validateResponse(responseText: responseText!);
48+
let responseText = String(decoding: data, as: UTF8.self)
49+
print("Response from metric API is: \n\(responseText)")
50+
self.validateResponse(responseText: responseText);
5151
// This is your file-variable:
5252
// data
5353
expec.fulfill()

Tests/InstrumentationTests/URLSessionTests/URLSessionInstrumentationTests.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,8 @@ class URLSessionInstrumentationTests: XCTestCase {
151151

152152
let task = URLSession.shared.dataTask(with: request) { data, _, _ in
153153
if let data = data {
154-
let string = String(data: data, encoding: .utf8)
155-
print(string ?? "")
154+
let string = String(decoding: data, as: UTF8.self)
155+
print(string)
156156
}
157157
URLSessionInstrumentationTests.semaphore.signal()
158158
}
@@ -171,7 +171,7 @@ class URLSessionInstrumentationTests: XCTestCase {
171171
let request = URLRequest(url: URL(string: "http://localhost:33333/forbidden")!)
172172
let task = URLSession.shared.dataTask(with: request) { data, _, _ in
173173
if let data = data {
174-
let string = String(data: data, encoding: .utf8)
174+
let string = String(decoding: data, as: UTF8.self)
175175
print(string ?? "")
176176
}
177177
URLSessionInstrumentationTests.semaphore.signal()

0 commit comments

Comments
 (0)