chore(docs): add logflare logging (#37310)
This commit is contained in:
3
.github/workflows/docs-tests.yml
vendored
3
.github/workflows/docs-tests.yml
vendored
@@ -14,6 +14,9 @@ concurrency:
|
||||
permissions:
|
||||
contents: read
|
||||
|
||||
env:
|
||||
CI: true
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
@@ -5,6 +5,7 @@ import { NextResponse } from 'next/server'
|
||||
import { z } from 'zod'
|
||||
import { ApiError, convertZodToInvalidRequestError, InvalidRequestError } from '~/app/api/utils'
|
||||
import { BASE_PATH, IS_DEV } from '~/lib/constants'
|
||||
import { sendToLogflare, LOGGING_CODES } from '~/lib/logger'
|
||||
import { rootGraphQLSchema } from '~/resources/rootSchema'
|
||||
import { createQueryDepthLimiter } from './validators'
|
||||
|
||||
@@ -154,6 +155,13 @@ export async function OPTIONS(request: Request): Promise<NextResponse> {
|
||||
|
||||
export async function POST(request: Request): Promise<NextResponse> {
|
||||
try {
|
||||
const vercelId = request.headers.get('x-vercel-id')
|
||||
sendToLogflare(LOGGING_CODES.CONTENT_API_REQUEST_RECEIVED, {
|
||||
vercelId,
|
||||
origin: request.headers.get('Origin'),
|
||||
userAgent: request.headers.get('User-Agent'),
|
||||
})
|
||||
|
||||
const result = await handleGraphQLRequest(request)
|
||||
// Do not let Vercel close the process until Sentry has flushed
|
||||
// https://github.com/getsentry/sentry-javascript/issues/9626
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -4,8 +4,11 @@ export const API_URL = (
|
||||
: process.env.NEXT_PUBLIC_API_URL!
|
||||
)?.replace(/\/platform$/, '')
|
||||
export const BASE_PATH = process.env.NEXT_PUBLIC_BASE_PATH || '/docs'
|
||||
export const IS_CI = process.env.CI === 'true'
|
||||
export const IS_DEV = process.env.NODE_ENV === 'development'
|
||||
export const IS_PLATFORM = process.env.NEXT_PUBLIC_IS_PLATFORM === 'true'
|
||||
export const IS_PRODUCTION = process.env.NEXT_PUBLIC_VERCEL_ENV === 'production'
|
||||
export const LOGFLARE_INGESTION_API_KEY = process.env.LOGFLARE_INGESTION_API_KEY
|
||||
export const LOGFLARE_SOURCE_TOKEN = process.env.LOGFLARE_SOURCE_TOKEN
|
||||
export const MISC_URL = process.env.NEXT_PUBLIC_MISC_URL ?? ''
|
||||
export const PROD_URL = `https://supabase.com${BASE_PATH}`
|
||||
|
||||
34
apps/docs/lib/logger.ts
Normal file
34
apps/docs/lib/logger.ts
Normal file
@@ -0,0 +1,34 @@
|
||||
import { IS_CI, IS_DEV, LOGFLARE_INGESTION_API_KEY, LOGFLARE_SOURCE_TOKEN } from './constants'
|
||||
|
||||
export const LOGGING_CODES = {
|
||||
CONTENT_API_REQUEST_RECEIVED: 'content_api_request_received',
|
||||
} as const
|
||||
|
||||
const LOGFLARE_ENDPOINT = `https://api.logflare.app/api/logs?source=${LOGFLARE_SOURCE_TOKEN}`
|
||||
|
||||
interface LogflareMessage {
|
||||
message: string
|
||||
metadata?: Record<string, unknown>
|
||||
}
|
||||
|
||||
export function sendToLogflare(message: string, metadata?: Record<string, unknown>) {
|
||||
// Skip logging in CI and development environments
|
||||
if (IS_CI || IS_DEV) return
|
||||
|
||||
const logMessage: LogflareMessage = {
|
||||
message,
|
||||
}
|
||||
|
||||
if (metadata) {
|
||||
logMessage.metadata = metadata
|
||||
}
|
||||
|
||||
fetch(LOGFLARE_ENDPOINT, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
Authorization: `Bearer ${LOGFLARE_INGESTION_API_KEY}`,
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify(logMessage),
|
||||
})
|
||||
}
|
||||
@@ -40,12 +40,16 @@
|
||||
"ASSET_CDN_S3_ENDPOINT",
|
||||
"AWS_ACCESS_KEY_ID",
|
||||
"AWS_SECRET_ACCESS_KEY",
|
||||
"CI",
|
||||
"DOCS_GITHUB_APP_ID",
|
||||
"DOCS_GITHUB_APP_INSTALLATION_ID",
|
||||
"DOCS_GITHUB_APP_PRIVATE_KEY",
|
||||
"DOCS_REVALIDATION_KEYS",
|
||||
"DOCS_REVALIDATION_OVERRIDE_KEYS",
|
||||
"GITHUB_ACTIONS",
|
||||
"FORCE_ASSET_CDN",
|
||||
"LOGFLARE_INGESTION_API_KEY",
|
||||
"LOGFLARE_SOURCE_TOKEN",
|
||||
"OPENAI_API_KEY",
|
||||
"SITE_NAME",
|
||||
"SUPABASE_SECRET_KEY"
|
||||
|
||||
Reference in New Issue
Block a user