Add feature flag to force Archon requests to be traced (#5666)

This commit is contained in:
François-Xavier Talbot
2026-03-26 02:34:04 -04:00
committed by GitHub
parent 0731654a1c
commit bf24ed8d12
5 changed files with 30 additions and 0 deletions

View File

@@ -126,6 +126,7 @@ export abstract class AbstractModrinthClient extends AbstractUploadClient {
...options.headers,
},
}
this.attachArchonSentryCaptureHeader(mergedOptions)
const headers = mergedOptions.headers
if (headers && 'Content-Type' in headers && headers['Content-Type'] === '') {
@@ -309,6 +310,21 @@ export abstract class AbstractModrinthClient extends AbstractUploadClient {
return headers
}
protected attachArchonSentryCaptureHeader(options: RequestOptions): void {
if (options.api !== 'archon' || !options.headers || !this.shouldCaptureArchonRequests()) {
return
}
options.headers['modrinth-sentry-capture'] = '1'
}
private shouldCaptureArchonRequests(): boolean {
const archonSentryCapture = this.config.archonSentryCapture
return typeof archonSentryCapture === 'function'
? archonSentryCapture()
: archonSentryCapture === true
}
/**
* Execute the actual HTTP request
*

View File

@@ -46,6 +46,7 @@ export abstract class XHRUploadClient extends AbstractModrinthClient {
...options.headers,
},
}
this.attachArchonSentryCaptureHeader(mergedOptions)
const context = this.buildUploadContext(url, path, mergedOptions)

View File

@@ -55,6 +55,14 @@ export interface ClientConfig {
*/
headers?: Record<string, string>
/**
* Whether to attach `modrinth-sentry-capture: 1` to Archon requests.
* Can be a callback so apps can drive this from runtime feature flags.
*
* @default false
*/
archonSentryCapture?: boolean | (() => boolean)
/**
* Features to enable for this client
* Features are applied in the order they appear in this array