Skip to content

Commit

Permalink
Include response length by default in the network spans
Browse files Browse the repository at this point in the history
  • Loading branch information
Ignacio Bonafonte committed Sep 28, 2023
1 parent 8d6fa74 commit 4798a27
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion Sources/Instrumentation/URLSession/URLSessionLogger.swift
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,16 @@ class URLSessionLogger {
}

let statusCode = httpResponse.statusCode
span.setAttribute(key: SemanticAttributes.httpStatusCode.rawValue, value: AttributeValue.int(statusCode))
span.setAttribute(key: SemanticAttributes.httpStatusCode.rawValue,
value: AttributeValue.int(statusCode))
span.status = statusForStatusCode(code: statusCode)

if let contentLengthHeader = httpResponse.value(forHTTPHeaderField: "Content-Length"),
let contentLength = Int(contentLengthHeader) {
span.setAttribute(key: SemanticAttributes.httpResponseContentLength.rawValue,
value: AttributeValue.int(contentLength))
}

instrumentation.configuration.receivedResponse?(response, dataOrFile, span)
span.end()
}
Expand Down

0 comments on commit 4798a27

Please sign in to comment.