Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -71,5 +71,14 @@ func httpClientResult(for taskResult: (Data?, URLResponse?, Error?)) -> Result<H
)
}

let statusCode = httpResponse.statusCode
guard (200..<300).contains(statusCode) else {
return .failure(
HTTPClientError(
description: "HTTP request failed with status code: \(statusCode)"
)
)
}

return .success(httpResponse)
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public class OtlpHttpTraceExporter: OtlpHttpExporterBase, SpanExporter {

public func export(spans: [SpanData], explicitTimeout: TimeInterval? = nil)
-> SpanExporterResultCode {
var resultValue: SpanExporterResultCode = .success
var sendingSpans: [SpanData] = []
exporterLock.withLockVoid {
pendingSpans.append(contentsOf: spans)
Expand All @@ -68,7 +69,17 @@ public class OtlpHttpTraceExporter: OtlpHttpExporterBase, SpanExporter {
$0.resourceSpans = SpanAdapter.toProtoResourceSpans(
spanDataList: sendingSpans)
}
let request = createRequest(body: body, endpoint: endpoint)
let semaphore = DispatchSemaphore(value: 0)
var request = createRequest(body: body, endpoint: endpoint)
if let headers = envVarHeaders {
headers.forEach { key, value in
request.addValue(value, forHTTPHeaderField: key)
}
} else if let headers = config.headers {
headers.forEach { key, value in
request.addValue(value, forHTTPHeaderField: key)
}
}
exporterMetrics?.addSeen(value: sendingSpans.count)
httpClient.send(request: request) { [weak self] result in
switch result {
Expand All @@ -80,9 +91,12 @@ public class OtlpHttpTraceExporter: OtlpHttpExporterBase, SpanExporter {
self?.pendingSpans.append(contentsOf: sendingSpans)
}
print(error)
resultValue = .failure
}
semaphore.signal()
}
return .success
semaphore.wait()
return resultValue
}

public func flush(explicitTimeout: TimeInterval? = nil)
Expand Down
Loading