@@ -3,7 +3,6 @@ import { flushMetrics } from "@lib/metrics";
33import { proxyV1 , SpanLogger , LogHistogramFn } from "@lib/proxy" ;
44import { isEmpty } from "@lib/util" ;
55import { MeterProvider } from "@opentelemetry/sdk-metrics" ;
6- import { Meter } from "@opentelemetry/api" ;
76
87import { APISecret , getModelEndpointTypes } from "@schema" ;
98import { verifyTempCredentials , isTempCredential } from "utils" ;
@@ -37,6 +36,8 @@ export interface ProxyOpts {
3736 logHistogram ?: LogHistogramFn ;
3837 whitelist ?: ( string | RegExp ) [ ] ;
3938 spanLogger ?: SpanLogger ;
39+ spanId ?: string ;
40+ spanExport ?: string ;
4041}
4142
4243const defaultWhitelist : ( string | RegExp ) [ ] = [
@@ -177,7 +178,7 @@ export function makeFetchApiSecrets({
177178 let lookupFailed = false ;
178179 // Only cache API keys for 60 seconds. This reduces the load on the database but ensures
179180 // that changes roll out quickly enough too.
180- let ttl = 60 ;
181+ const ttl = 60 ;
181182 try {
182183 const response = await fetch (
183184 `${ opts . braintrustApiUrl || DEFAULT_BRAINTRUST_APP_URL } /api/secret` ,
@@ -258,11 +259,11 @@ export function EdgeProxyV1(opts: ProxyOpts) {
258259
259260 // Create an identity TransformStream (a.k.a. a pipe).
260261 // The readable side will become our new response body.
261- let { readable, writable } = new TransformStream ( ) ;
262+ const { readable, writable } = new TransformStream ( ) ;
262263
263264 let status = 200 ;
264265
265- let headers : Record < string , string > = opts . cors ? corsHeaders : { } ;
266+ const headers : Record < string , string > = opts . cors ? corsHeaders : { } ;
266267
267268 const setStatus = ( code : number ) => {
268269 status = code ;
@@ -289,6 +290,14 @@ export function EdgeProxyV1(opts: ProxyOpts) {
289290
290291 const fetchApiSecrets = makeFetchApiSecrets ( { ctx, opts } ) ;
291292
293+ // Set span headers if available
294+ if ( opts . spanId ) {
295+ setHeader ( "x-bt-span-id" , opts . spanId ) ;
296+ }
297+ if ( opts . spanExport ) {
298+ setHeader ( "x-bt-span-export" , opts . spanExport ) ;
299+ }
300+
292301 const cachePut = async (
293302 encryptionKey : string ,
294303 key : string ,
0 commit comments