From b68191c1fb87f0e6c5b555276b20dcc511fb356d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Halber?= Date: Fri, 31 Jul 2026 01:22:41 +0000 Subject: [PATCH] Send identifying User-Agent from the TS SDK Set User-Agent: braintrust-ts/ on HTTPConnection requests so the Braintrust backend can attribute object creation (projects, experiments, datasets, prompts, playgrounds) to the TS SDK vs other clients. Export SDK_VERSION from span-origin for reuse. Ignored by browsers (User-Agent is a forbidden header there), which is acceptable since the SDK is primarily used server-side. Co-Authored-By: Claude Opus 4.8 --- js/src/logger.ts | 6 ++++++ js/src/span-origin.ts | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/js/src/logger.ts b/js/src/logger.ts index 8bdb8a67b..be2f9f39a 100644 --- a/js/src/logger.ts +++ b/js/src/logger.ts @@ -185,6 +185,7 @@ import { getSpanInstrumentationName, INSTRUMENTATION_NAMES, mergeSpanOriginContext, + SDK_VERSION, type SpanOriginEnvironment, } from "./span-origin"; @@ -1315,6 +1316,11 @@ class HTTPConnection { // As far as I can tell, you cannot set the retry/backoff factor here _reset() { this.headers = {}; + // Identifies SDK-originated traffic so the backend can attribute object + // creation to the TS SDK. Ignored by browsers (User-Agent is a forbidden + // header there), which is acceptable since the SDK is primarily used + // server-side. + this.headers["User-Agent"] = `braintrust-ts/${SDK_VERSION}`; if (this.token) { this.headers["Authorization"] = `Bearer ${this.token}`; } diff --git a/js/src/span-origin.ts b/js/src/span-origin.ts index 0fd2f5fc8..5bd7b7878 100644 --- a/js/src/span-origin.ts +++ b/js/src/span-origin.ts @@ -56,7 +56,7 @@ type InternalSpanInstrumentationName = { [INTERNAL_SPAN_INSTRUMENTATION_NAME]?: SpanInstrumentationName; }; -const SDK_VERSION = +export const SDK_VERSION = typeof __BRAINTRUST_SDK_VERSION__ !== "undefined" ? __BRAINTRUST_SDK_VERSION__ : "0.0.0";