diff --git a/api/src/routes/traces.ts b/api/src/routes/traces.ts index e65a12e36..6166a1ba6 100644 --- a/api/src/routes/traces.ts +++ b/api/src/routes/traces.ts @@ -75,8 +75,15 @@ app.get("/v1/traces/:traceId/spans", async (ctx) => { const fpxWorker = await getSetting(db, "fpxWorkerProxy"); if (fpxWorker?.enabled && fpxWorker.baseUrl) { + const headers: Record = fpxWorker.bearerToken + ? { Authorization: `Bearer ${fpxWorker.bearerToken}` } + : {}; + const response = await fetch( `${fpxWorker.baseUrl}/v1/traces/${traceId}/spans`, + { + headers, + }, ); const json = await response.json(); return ctx.json(json as JSON); @@ -114,9 +121,14 @@ app.post("/v1/traces", async (ctx) => { const fpxWorker = await getSetting(db, "fpxWorkerProxy"); if (fpxWorker?.enabled && fpxWorker.baseUrl) { + const headers: Record = fpxWorker.bearerToken + ? { Authorization: `Bearer ${fpxWorker.bearerToken}` } + : {}; + const response = await fetch(`${fpxWorker.baseUrl}/v1/traces`, { headers: { "Content-Type": "application/json", + ...headers, }, method: "POST", body: JSON.stringify(body), diff --git a/packages/types/src/settings.ts b/packages/types/src/settings.ts index fae1eadc3..75b08f3d0 100644 --- a/packages/types/src/settings.ts +++ b/packages/types/src/settings.ts @@ -124,6 +124,7 @@ export const SettingsSchema = z.object({ // Fix from: // https://github.com/colinhacks/zod/discussions/1254#discussioncomment-3123225 baseUrl: z.union([z.literal(""), z.string().trim().url()]).optional(), + bearerToken: z.string().optional(), }) .optional(), openApiSpecUrl: z.string().optional(), diff --git a/studio/src/pages/SettingsPage/FpxWorkerProxySettingsForm.tsx b/studio/src/pages/SettingsPage/FpxWorkerProxySettingsForm.tsx index df9e8d2d4..341f7e8dc 100644 --- a/studio/src/pages/SettingsPage/FpxWorkerProxySettingsForm.tsx +++ b/studio/src/pages/SettingsPage/FpxWorkerProxySettingsForm.tsx @@ -19,7 +19,8 @@ export function FpxWorkerProxySettingsForm({ const { form, onSubmit } = useSettingsForm(settings); const isDirty = (form.formState.dirtyFields.fpxWorkerProxy?.enabled || - form.formState.dirtyFields.fpxWorkerProxy?.baseUrl) ?? + form.formState.dirtyFields.fpxWorkerProxy?.baseUrl || + form.formState.dirtyFields.fpxWorkerProxy?.bearerToken) ?? false; return ( @@ -86,6 +87,31 @@ export function FpxWorkerProxySettingsForm({ )} /> )} + {field.value && ( + ( +
+ + Bearer token + + + Configure the authorization token that will be used + in the Authorization header when making requests to + the Cloudflare Worker Trace Ingestion service. + + + + +
+ )} + /> + )} )} />