Skip to content

Commit c2e6ed4

Browse files
committed
fix(observability-sdk): require whitespace after HTTP verb in span filter
The excludeHttpRequests preset matched any word boundary after the HTTP verb, so user spans like 'post-process' or 'delete-account' were silently dropped from export. Require whitespace or end-of-string after the verb instead, matching the OTel HTTP instrumentation shape. Fixes langwatch#7413
1 parent b682b88 commit c2e6ed4

2 files changed

Lines changed: 16 additions & 2 deletions

File tree

sdks/typescript/src/observability-sdk/exporters/__tests__/trace-filters.test.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,19 @@ describe("trace-filters", () => {
282282
expect(isHttpRequestSpan(createMockSpan("GETAWAY", "http"))).toBe(false);
283283
expect(isHttpRequestSpan(createMockSpan("GETTING", "http"))).toBe(false);
284284
});
285+
286+
it("requires whitespace or end-of-string after the verb, not any word boundary", () => {
287+
// Hyphen, dot, slash etc. are word boundaries but not OTel HTTP span shapes.
288+
expect(isHttpRequestSpan(createMockSpan("post-process", "custom"))).toBe(false);
289+
expect(isHttpRequestSpan(createMockSpan("get-user-profile", "custom"))).toBe(false);
290+
expect(isHttpRequestSpan(createMockSpan("delete-account", "custom"))).toBe(false);
291+
expect(isHttpRequestSpan(createMockSpan("patch-config", "custom"))).toBe(false);
292+
expect(isHttpRequestSpan(createMockSpan("head-request-handler", "custom"))).toBe(false);
293+
expect(isHttpRequestSpan(createMockSpan("options-resolver", "custom"))).toBe(false);
294+
expect(isHttpRequestSpan(createMockSpan("put-record.v2", "custom"))).toBe(false);
295+
// Bare verb at end-of-string is still a valid OTel shape.
296+
expect(isHttpRequestSpan(createMockSpan("POST", "http"))).toBe(true);
297+
});
285298
});
286299

287300
describe("applyPreset", () => {
@@ -456,4 +469,3 @@ describe("trace-filters", () => {
456469
});
457470
});
458471
});
459-

sdks/typescript/src/observability-sdk/exporters/trace-filters.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,8 @@ export function isVercelAiSpan(span: ReadableSpan): boolean {
253253
*/
254254
export function isHttpRequestSpan(span: ReadableSpan): boolean {
255255
const name = span.name ?? "";
256-
const verbMatch = /^(GET|POST|PUT|DELETE|PATCH|OPTIONS|HEAD)\b/i.test(name);
256+
const verbMatch = /^(GET|POST|PUT|DELETE|PATCH|OPTIONS|HEAD)(\s|$)/i.test(
257+
name
258+
);
257259
return verbMatch;
258260
}

0 commit comments

Comments
 (0)