Skip to content

Commit 29672d1

Browse files
fenosCopilotferhatelmas
authored
fix: metrics, add dynamic service name (#1112)
* fix: metrics, add dynamic service name * fix: apply serviceName to tracing, prometheus prefix, and document in env samples Agent-Logs-Url: https://github.com/supabase/storage/sessions/cacef517-4708-4b90-ba6c-6e85f0356a21 Co-authored-by: ferhatelmas <648018+ferhatelmas@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: ferhatelmas <648018+ferhatelmas@users.noreply.github.com>
1 parent e58e4ab commit 29672d1

5 files changed

Lines changed: 10 additions & 4 deletions

File tree

.env.sample

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ WEBHOOK_API_KEY=
156156
# Monitoring
157157
#######################################
158158
LOG_LEVEL=info
159+
SERVICE_NAME=storage_api
159160
OTEL_EXPORTER_OTLP_TRACES_ENDPOINT=http://localhost:4317
160161
OTEL_EXPORTER_OTLP_METRICS_ENDPOINT=http://localhost:4317
161162
OTEL_METRICS_EXPORT_INTERVAL_MS=5000

.env.test.sample

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,4 @@ ICEBERG_BUCKET_DETECTION_MODE="BUCKET"
3737

3838
OTEL_METRICS_ENABLED=false
3939
PROMETHEUS_METRICS_ENABLED=false
40+
SERVICE_NAME=storage_api

src/config.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ export interface JwksConfig {
5151
}
5252

5353
type StorageConfigType = {
54+
serviceName: string
5455
isProduction: boolean
5556
version: string
5657
numWorkers: number
@@ -264,6 +265,7 @@ export function getConfig(options?: { reload?: boolean }): StorageConfigType {
264265
const isMultitenant = getOptionalConfigFromEnv('MULTI_TENANT', 'IS_MULTITENANT') === 'true'
265266

266267
config = {
268+
serviceName: getOptionalConfigFromEnv('SERVICE_NAME') || 'storage_api',
267269
numWorkers: envNumber(getOptionalConfigFromEnv('WORKERS_NUM'), 1),
268270
isProduction: process.env.NODE_ENV === 'production',
269271
exposeDocs: getOptionalConfigFromEnv('EXPOSE_DOCS') !== 'false',

src/internal/monitoring/otel-metrics.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ const {
2727
otelMetricsTemporality,
2828
prometheusMetricsEnabled,
2929
region,
30+
serviceName,
3031
} = getConfig()
3132

3233
let prometheusExporter: PrometheusExporter | undefined
@@ -79,7 +80,7 @@ Object.keys(exporterHeaders).forEach((key) => {
7980
})
8081

8182
const resource = resourceFromAttributes({
82-
[ATTR_SERVICE_NAME]: 'storage_api',
83+
[ATTR_SERVICE_NAME]: serviceName,
8384
[ATTR_SERVICE_VERSION]: version,
8485
'metric.version': '1',
8586
region,
@@ -237,9 +238,9 @@ if (otelMetricsEnabled) {
237238

238239
if (prometheusMetricsEnabled) {
239240
prometheusExporter = new PrometheusExporter({
240-
prefix: 'storage_api',
241+
prefix: serviceName,
241242
preventServerStart: true,
242-
withResourceConstantLabels: /^(region|instance|metric\.version)$/,
243+
withResourceConstantLabels: /^(region|instance|metric\.version|service\.name)$/,
243244
})
244245
readers.push(prometheusExporter)
245246
}

src/internal/monitoring/otel-tracing.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ const {
77
requestXForwardedHostRegExp,
88
tenantId: defaultTenantId,
99
region,
10+
serviceName,
1011
storageS3InternalTracesEnabled,
1112
} = getConfig()
1213

@@ -114,7 +115,7 @@ if (tracingEnabled && traceExporter && spanProcessors.length > 0) {
114115
// Configure the OpenTelemetry Node SDK
115116
tracingSdk = new NodeSDK({
116117
resource: resourceFromAttributes({
117-
[ATTR_SERVICE_NAME]: 'storage',
118+
[ATTR_SERVICE_NAME]: serviceName,
118119
[ATTR_SERVICE_VERSION]: version,
119120
}),
120121
spanProcessors,

0 commit comments

Comments
 (0)