Vercel log drain endpoint to ingest logs into Google Cloud Logging
A publicly accessible HTTP endpoint, deployed to Google Cloud Functions, to serve as a Vercel log drain to ingest logs into Google Cloud Logging. This only converts some fields from the Vercel log to their Cloud Logging counterparts.
(1) Generate a secret key of length 32 (minimum length allowed by Vercel):
python -c 'import secrets; print(secrets.token_hex(16))'
(2) Create file env-vars.yaml based on env-vars.yaml.example and set all variables except VERCEL_VERIFICATION_KEY.
(3) Deploy to google cloud so that you can obtain the public URL:
gcloud functions deploy vercel-log-drain \
--gen2 \
--runtime=python312 \
--region=us-east4 \
--trigger-http \
--max-instances 10 \
--concurrency=10 \
--cpu=1 \
--memory="256MB" \
--allow-unauthenticated \
--env-vars-file=env-vars.yaml \
--source=. \
--entry-point=on_log
… wait for command to complete and copy the Cloud Function URL.
(4) Create a log drain in Vercel with the following options:
When you enter the Endpoint URL, Vercel will ask you to verify that you own the URL. Set VERCEL_VERIFICATION_KEY in env-vars.yaml and redeploy (step 3). Wait for the deployment to finish then click Verify in Vercel.
(5) Redeploy (step 3)
Local testing:
GCP_PROJECT="TODO" SECRET_KEY="TODO" functions-framework-python --target=on_logcurl localhost:8080Run tests:
python -m tests.test_transform
Useful documentation: