Add feature flag to force Archon requests to be traced (#5666)
This commit is contained in:
committed by
GitHub
parent
0731654a1c
commit
bf24ed8d12
@@ -38,6 +38,7 @@ export const DEFAULT_FEATURE_FLAGS = validateValues({
|
|||||||
showProjectPageQuickServerButton: false,
|
showProjectPageQuickServerButton: false,
|
||||||
newProjectGeneralSettings: false,
|
newProjectGeneralSettings: false,
|
||||||
newProjectEnvironmentSettings: true,
|
newProjectEnvironmentSettings: true,
|
||||||
|
archonSentryCapture: false,
|
||||||
hideRussiaCensorshipBanner: false,
|
hideRussiaCensorshipBanner: false,
|
||||||
disablePrettyProjectUrlRedirects: false,
|
disablePrettyProjectUrlRedirects: false,
|
||||||
hidePreviewBanner: false,
|
hidePreviewBanner: false,
|
||||||
|
|||||||
@@ -13,6 +13,8 @@ import {
|
|||||||
} from '@modrinth/api-client'
|
} from '@modrinth/api-client'
|
||||||
import type { Ref } from 'vue'
|
import type { Ref } from 'vue'
|
||||||
|
|
||||||
|
import { useFeatureFlags } from '~/composables/featureFlags.ts'
|
||||||
|
|
||||||
async function getRateLimitKeyFromSecretsStore(): Promise<string | undefined> {
|
async function getRateLimitKeyFromSecretsStore(): Promise<string | undefined> {
|
||||||
try {
|
try {
|
||||||
const mod = 'cloudflare:workers'
|
const mod = 'cloudflare:workers'
|
||||||
@@ -28,6 +30,7 @@ export function createModrinthClient(
|
|||||||
auth: Ref<{ token: string | undefined }>,
|
auth: Ref<{ token: string | undefined }>,
|
||||||
config: { apiBaseUrl: string; archonBaseUrl: string; rateLimitKey?: string },
|
config: { apiBaseUrl: string; archonBaseUrl: string; rateLimitKey?: string },
|
||||||
): NuxtModrinthClient {
|
): NuxtModrinthClient {
|
||||||
|
const flags = useFeatureFlags()
|
||||||
const optionalFeatures = [
|
const optionalFeatures = [
|
||||||
import.meta.dev ? (new VerboseLoggingFeature() as AbstractFeature) : undefined,
|
import.meta.dev ? (new VerboseLoggingFeature() as AbstractFeature) : undefined,
|
||||||
].filter(Boolean) as AbstractFeature[]
|
].filter(Boolean) as AbstractFeature[]
|
||||||
@@ -35,6 +38,7 @@ export function createModrinthClient(
|
|||||||
const clientConfig: NuxtClientConfig = {
|
const clientConfig: NuxtClientConfig = {
|
||||||
labrinthBaseUrl: config.apiBaseUrl,
|
labrinthBaseUrl: config.apiBaseUrl,
|
||||||
archonBaseUrl: config.archonBaseUrl,
|
archonBaseUrl: config.archonBaseUrl,
|
||||||
|
archonSentryCapture: () => flags.value.archonSentryCapture,
|
||||||
rateLimitKey: config.rateLimitKey || getRateLimitKeyFromSecretsStore,
|
rateLimitKey: config.rateLimitKey || getRateLimitKeyFromSecretsStore,
|
||||||
features: [
|
features: [
|
||||||
// for modrinth hosting
|
// for modrinth hosting
|
||||||
|
|||||||
@@ -126,6 +126,7 @@ export abstract class AbstractModrinthClient extends AbstractUploadClient {
|
|||||||
...options.headers,
|
...options.headers,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
this.attachArchonSentryCaptureHeader(mergedOptions)
|
||||||
|
|
||||||
const headers = mergedOptions.headers
|
const headers = mergedOptions.headers
|
||||||
if (headers && 'Content-Type' in headers && headers['Content-Type'] === '') {
|
if (headers && 'Content-Type' in headers && headers['Content-Type'] === '') {
|
||||||
@@ -309,6 +310,21 @@ export abstract class AbstractModrinthClient extends AbstractUploadClient {
|
|||||||
return headers
|
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
|
* Execute the actual HTTP request
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -46,6 +46,7 @@ export abstract class XHRUploadClient extends AbstractModrinthClient {
|
|||||||
...options.headers,
|
...options.headers,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
this.attachArchonSentryCaptureHeader(mergedOptions)
|
||||||
|
|
||||||
const context = this.buildUploadContext(url, path, mergedOptions)
|
const context = this.buildUploadContext(url, path, mergedOptions)
|
||||||
|
|
||||||
|
|||||||
@@ -55,6 +55,14 @@ export interface ClientConfig {
|
|||||||
*/
|
*/
|
||||||
headers?: Record<string, string>
|
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 to enable for this client
|
||||||
* Features are applied in the order they appear in this array
|
* Features are applied in the order they appear in this array
|
||||||
|
|||||||
Reference in New Issue
Block a user