Skip to content

Commit b1edad5

Browse files
committed
test(pipeline): strengthen OTLP coverage and document header pairing
Address review-until-green feedback on the OTLP binding: - Pin the default wire protocol: the endpoint-only OTLP test now asserts the request content-type is JSON (the http/json default) instead of accepting either json or protobuf. - Cover multi-header export and the odd-length trailing-drop in one test (two header pairs plus a stray unpaired element; assert both pairs arrive). - Document that setOtlpHeaders ignores a trailing unpaired element, replaces prior headers, and that setOtlpEndpoint takes precedence over setUseV05.
1 parent 1d566bc commit b1edad5

2 files changed

Lines changed: 14 additions & 4 deletions

File tree

crates/pipeline/src/lib.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,7 @@ impl WasmSpanState {
302302

303303
/// Route trace export through libdatadog's OTLP HTTP exporter to `url`
304304
/// instead of the Datadog agent. Must be called before the first send.
305+
/// Takes precedence over `setUseV05` (OTLP bypasses the agent entirely).
305306
#[wasm_bindgen(js_name = "setOtlpEndpoint")]
306307
pub fn set_otlp_endpoint(&self, url: String) {
307308
*self.otlp_endpoint.borrow_mut() = Some(url);
@@ -320,9 +321,13 @@ impl WasmSpanState {
320321
}
321322

322323
/// Set extra HTTP headers for OTLP export as a flat `[key, value, ...]`
323-
/// array. Only takes effect with an OTLP endpoint set, before the first send.
324+
/// array (the host flattens its key/value map). Only takes effect with an
325+
/// OTLP endpoint set, before the first send. A trailing unpaired element on
326+
/// an odd-length array is ignored. Each call replaces any previously set headers.
324327
#[wasm_bindgen(js_name = "setOtlpHeaders")]
325328
pub fn set_otlp_headers(&self, kv: Vec<String>) {
329+
// chunks_exact drops a trailing unpaired element; the host always passes
330+
// complete [key, value] pairs.
326331
let headers = kv
327332
.chunks_exact(2)
328333
.map(|pair| (pair[0].clone(), pair[1].clone()))

test/pipeline.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -863,7 +863,8 @@ describe('pipeline', () => {
863863
const req = seen.find(r => r.method === 'POST')
864864
assert.ok(req, 'OTLP endpoint received a POST')
865865
assert.strictEqual(req.url, '/v1/traces')
866-
assert.match(req.ct || '', /json|protobuf/)
866+
// No setOtlpProtocol call — pins the default wire protocol (http/json).
867+
assert.match(req.ct || '', /json/)
867868
assert.ok(req.len > 0, 'OTLP body is non-empty')
868869
} finally {
869870
server.closeAllConnections?.()
@@ -880,7 +881,8 @@ describe('pipeline', () => {
880881
if (req.method === 'POST') {
881882
captured = {
882883
ct: req.headers['content-type'],
883-
auth: req.headers.authorization
884+
auth: req.headers.authorization,
885+
custom: req.headers['x-custom']
884886
}
885887
}
886888
res.writeHead(200, { 'content-type': 'application/json' })
@@ -892,7 +894,9 @@ describe('pipeline', () => {
892894
const ns = new NativeSpansInterface({ agentUrl: `http://127.0.0.1:${port}` })
893895
ns.state.setOtlpEndpoint(`http://127.0.0.1:${port}/v1/traces`)
894896
ns.state.setOtlpProtocol('http/protobuf')
895-
ns.state.setOtlpHeaders(['authorization', 'Bearer test-token'])
897+
// Two header pairs plus a trailing unpaired element (odd length): both
898+
// pairs are applied and the stray 'ignored-no-pair' is dropped.
899+
ns.state.setOtlpHeaders(['authorization', 'Bearer test-token', 'x-custom', 'cval', 'ignored-no-pair'])
896900
const span = ns.createSpan()
897901
span.name = 'otlp-span'
898902
span.service = 'test-service'
@@ -904,6 +908,7 @@ describe('pipeline', () => {
904908
assert.ok(captured, 'OTLP endpoint received a POST')
905909
assert.match(captured.ct || '', /protobuf/)
906910
assert.strictEqual(captured.auth, 'Bearer test-token')
911+
assert.strictEqual(captured.custom, 'cval')
907912
} finally {
908913
server.closeAllConnections?.()
909914
server.close()

0 commit comments

Comments
 (0)