Gate Axiom metrics export behind dataset env

This commit is contained in:
Owen Greenhalgh
2026-05-07 20:24:49 +01:00
parent f3639001fc
commit 3a3a999732
2 changed files with 33 additions and 14 deletions

View File

@@ -16,6 +16,9 @@ on:
env:
AWS_REGION: us-west-2
# Branches allowed to deploy to staging via workflow_dispatch with tag=deploy-staging.
# Add short-lived PR branches here when you need staging without merging to dev.
STAGING_DEPLOY_BRANCH_ALLOWLIST: axiom-ingest-cuts
jobs:
checks:
@@ -66,14 +69,29 @@ jobs:
- name: Extract metadata for Docker
id: meta
env:
DEPLOY_STAGING_OVERRIDE: ${{ github.event_name == 'workflow_dispatch' && github.ref == 'refs/heads/axiom-ingest-cuts' && github.event.inputs.tag == 'deploy-staging' }}
REQUESTED_STAGING_DEPLOY: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.tag == 'deploy-staging' }}
run: |
BRANCH_NAME=${GITHUB_REF#refs/heads/}
COMMIT_SHA=${GITHUB_SHA::8}
DEPLOY_STAGING_OVERRIDE="false"
# Sanitize branch name for Docker tag (replace / with -)
SAFE_BRANCH=$(echo $BRANCH_NAME | sed 's/\//-/g')
if [ "$REQUESTED_STAGING_DEPLOY" = "true" ] && [ "$BRANCH_NAME" != "dev" ]; then
for ALLOWED_BRANCH in $STAGING_DEPLOY_BRANCH_ALLOWLIST; do
if [ "$BRANCH_NAME" = "$ALLOWED_BRANCH" ]; then
DEPLOY_STAGING_OVERRIDE="true"
break
fi
done
if [ "$DEPLOY_STAGING_OVERRIDE" != "true" ]; then
echo "::error::Branch '$BRANCH_NAME' is not allowed to deploy to staging. Add it to STAGING_DEPLOY_BRANCH_ALLOWLIST in .github/workflows/build.yml."
exit 1
fi
fi
if [ "$DEPLOY_STAGING_OVERRIDE" = "true" ]; then
# deployStaging expects the staging ECR image tag to be dev-<sha>.
IMAGE_BRANCH="dev"
@@ -83,6 +101,7 @@ jobs:
echo "branch=$IMAGE_BRANCH" >> $GITHUB_OUTPUT
echo "sha=$COMMIT_SHA" >> $GITHUB_OUTPUT
echo "deploy_staging_override=$DEPLOY_STAGING_OVERRIDE" >> $GITHUB_OUTPUT
# Select ECR repository based on branch
if [ "$BRANCH_NAME" = "dev" ] || [ "$DEPLOY_STAGING_OVERRIDE" = "true" ]; then
@@ -161,7 +180,7 @@ jobs:
fi
- name: Auto-deploy staging
if: github.ref == 'refs/heads/dev' || (github.event_name == 'workflow_dispatch' && github.ref == 'refs/heads/axiom-ingest-cuts' && github.event.inputs.tag == 'deploy-staging')
if: github.ref == 'refs/heads/dev' || steps.meta.outputs.deploy_staging_override == 'true'
env:
DEPLOY_URL: ${{ secrets.DEPLOY_URL }}
DEPLOY_SECRET: ${{ secrets.DEPLOY_SECRET }}

View File

@@ -35,18 +35,18 @@ if (process.env.AXIOM_TOKEN) {
scheduledDelayMillis: isDev ? 1000 : 5000,
});
const filteredExportProcessor = new FilteringSpanProcessor(exportProcessor);
const metricExporter = new OTLPMetricExporter({
url: "https://api.axiom.co/v1/metrics",
headers: {
Authorization: `Bearer ${process.env.AXIOM_TOKEN}`,
"x-axiom-metrics-dataset":
process.env.AXIOM_METRICS_DATASET ?? "metrics-v2",
},
});
const metricReader = new PeriodicExportingMetricReader({
exporter: metricExporter,
exportIntervalMillis: 60_000,
});
const metricReader = process.env.AXIOM_METRICS_DATASET
? new PeriodicExportingMetricReader({
exporter: new OTLPMetricExporter({
url: "https://api.axiom.co/v1/metrics",
headers: {
Authorization: `Bearer ${process.env.AXIOM_TOKEN}`,
"x-axiom-metrics-dataset": process.env.AXIOM_METRICS_DATASET,
},
}),
exportIntervalMillis: 60_000,
})
: undefined;
// No auto-instrumentations — Bun doesn't support require-in-the-middle.
// Stripe, Drizzle, and Redis are instrumented via manual patchers in utils/otel/.