Skip to content

Commit 4f33acb

Browse files
Waheibabryce-b
andauthored
fix: OtlpHttpTraceExporter request headers (#894)
Co-authored-by: Bryce Buchanan <[email protected]>
1 parent c7e5fcf commit 4f33acb

File tree

2 files changed

+7
-12
lines changed

2 files changed

+7
-12
lines changed

Sources/Exporters/OpenTelemetryProtocolHttp/logs/OtlpHttpLogExporter.swift

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -69,16 +69,6 @@ public class OtlpHttpLogExporter: OtlpHttpExporterBase, LogRecordExporter {
6969
}
7070

7171
var request = createRequest(body: body, endpoint: endpoint)
72-
if let headers = envVarHeaders {
73-
headers.forEach { key, value in
74-
request.addValue(value, forHTTPHeaderField: key)
75-
}
76-
77-
} else if let headers = config.headers {
78-
headers.forEach { key, value in
79-
request.addValue(value, forHTTPHeaderField: key)
80-
}
81-
}
8272
exporterMetrics?.addSeen(value: sendingLogRecords.count)
8373
request.timeoutInterval = min(explicitTimeout ?? TimeInterval.greatestFiniteMagnitude, config.timeout)
8474
httpClient.send(request: request) { [weak self] result in
@@ -143,4 +133,4 @@ public class OtlpHttpLogExporter: OtlpHttpExporterBase, LogRecordExporter {
143133

144134
return exporterResult
145135
}
146-
}
136+
}

Tests/ExportersTests/OpenTelemetryProtocol/OtlpHttpLogRecordExporterTests.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ class OtlpHttpLogRecordExporterTests: XCTestCase {
3434
}
3535

3636
func testExport() {
37+
let testHeader = ("testHeader", "testValue")
3738
let testBody = AttributeValue.string("Helloworld" + String(Int.random(in: 1 ... 100)))
3839
let logRecord = ReadableLogRecord(resource: Resource(),
3940
instrumentationScopeInfo: InstrumentationScopeInfo(name: "scope"),
@@ -45,13 +46,17 @@ class OtlpHttpLogRecordExporterTests: XCTestCase {
4546
attributes: ["event.name": AttributeValue.string("name"), "event.domain": AttributeValue.string("domain")])
4647

4748
let endpoint = URL(string: "http://localhost:\(testServer.serverPort)")!
48-
let exporter = OtlpHttpLogExporter(endpoint: endpoint, config: .init(compression: .none))
49+
let config = OtlpConfiguration(compression: .none, headers: [testHeader])
50+
let exporter = OtlpHttpLogExporter(endpoint: endpoint, config: config)
4951
let _ = exporter.export(logRecords: [logRecord])
5052

5153
// TODO: Use protobuf to verify that we have received the correct Log records
5254
XCTAssertNoThrow(try testServer.receiveHeadAndVerify { head in
5355
let otelVersion = Headers.getUserAgentHeader()
5456
XCTAssertTrue(head.headers.contains(name: Constants.HTTP.userAgent))
57+
XCTAssertTrue(head.headers.contains { header in
58+
header.name.lowercased() == testHeader.0.lowercased() && header.value == testHeader.1
59+
})
5560
XCTAssertEqual(otelVersion, head.headers.first(name: Constants.HTTP.userAgent))
5661
})
5762
XCTAssertNoThrow(try testServer.receiveBodyAndVerify { body in

0 commit comments

Comments
 (0)