* add staging ios app build script * feat(api): add OpenTelemetry LGTM stack for local observability Wire OTel traces, metrics, and logs through a collector to Tempo, Prometheus, and Loki, with custom LLM instrumentation, dev compose overlay, Grafana provisioning, env templates, and development.sh auto-start. * feat: expand observability, harden dev tooling, and fix expo staging UX Add business and LLM Prometheus metrics with Grafana dashboards, alerting, and a metrics verification script. Wire telemetry through adapters and core LLM paths, and document the local LGTM workflow. Fix development.sh for macOS bash 3.2, open Grafana and eval-web in Chrome, and repair eval-web auto-open (unbound EVAL_WEB_BROWSER_SCHEDULED). Merge internal-eval into the main dev script with improved compose handling. Require EXPO_PUBLIC_* at build time, improve iOS HTTP ATS for staging IPs, show memoir empty state instead of load errors when no chapters exist, and add jest env setup plus chapter list response normalization. * chore: enable Grafana Assistant Cursor plugin * fix: memoir empty state and repair withdrawn 0020_chapters_book_id stamp Show empty memoir UI when the chapter list succeeds with no items; treat auth/404 as non-fatal. Extend alembic revision repair so local dev DBs stamped with the removed 0020_chapters_book_id migration can roll back and upgrade to 0019. --------- Co-authored-by: Kevin <kevin@brighteng.org> Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -4,6 +4,57 @@ function trimTrailingSlashes(value: string): string {
|
||||
|
||||
export type AppVariant = 'development' | 'staging' | 'production';
|
||||
|
||||
const MISSING_ENV_HINT =
|
||||
'Run `npm run use-env -- <development|staging|production>` in app-expo, ' +
|
||||
'then restart Metro or re-run `expo prebuild` before building.';
|
||||
|
||||
/**
|
||||
* EXPO_PUBLIC_* must be set at bundle time (Metro / EAS / Xcode Archive).
|
||||
* Refuses silent fallbacks to a hard-coded LAN IP.
|
||||
*/
|
||||
export function requirePublicEnv(name: string): string {
|
||||
const value = process.env[name]?.trim();
|
||||
if (!value) {
|
||||
throw new Error(`[config] Missing ${name}. ${MISSING_ENV_HINT}`);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
function parseBackendUrl(raw: string, envName: string): URL {
|
||||
let parsed: URL;
|
||||
try {
|
||||
parsed = new URL(raw);
|
||||
} catch {
|
||||
throw new Error(`[config] Invalid ${envName}: ${raw}`);
|
||||
}
|
||||
if (!parsed.protocol || parsed.protocol === ':') {
|
||||
throw new Error(`[config] ${envName} must include a scheme (http/https or ws/wss): ${raw}`);
|
||||
}
|
||||
return parsed;
|
||||
}
|
||||
|
||||
function resolveApiBaseUrl(): string {
|
||||
const raw = requirePublicEnv('EXPO_PUBLIC_API_URL');
|
||||
const parsed = parseBackendUrl(raw, 'EXPO_PUBLIC_API_URL');
|
||||
if (parsed.protocol !== 'http:' && parsed.protocol !== 'https:') {
|
||||
throw new Error(
|
||||
`[config] EXPO_PUBLIC_API_URL must use http:// or https:// (got ${parsed.protocol})`,
|
||||
);
|
||||
}
|
||||
return trimTrailingSlashes(raw);
|
||||
}
|
||||
|
||||
function resolveWsBaseUrl(): string {
|
||||
const raw = requirePublicEnv('EXPO_PUBLIC_WS_URL');
|
||||
const parsed = parseBackendUrl(raw, 'EXPO_PUBLIC_WS_URL');
|
||||
if (parsed.protocol !== 'ws:' && parsed.protocol !== 'wss:') {
|
||||
throw new Error(
|
||||
`[config] EXPO_PUBLIC_WS_URL must use ws:// or wss:// (got ${parsed.protocol})`,
|
||||
);
|
||||
}
|
||||
return trimTrailingSlashes(raw);
|
||||
}
|
||||
|
||||
function resolveAppVariant(): AppVariant {
|
||||
const raw = process.env.EXPO_PUBLIC_APP_VARIANT;
|
||||
if (raw === 'development' || raw === 'staging' || raw === 'production') {
|
||||
@@ -33,12 +84,8 @@ export function shouldShowAboutBackendUrl(variant: AppVariant = appVariant): boo
|
||||
export const appVariant = resolveAppVariant();
|
||||
|
||||
export const config = {
|
||||
apiBaseUrl: trimTrailingSlashes(
|
||||
process.env.EXPO_PUBLIC_API_URL ?? 'http://192.168.10.151:8000',
|
||||
),
|
||||
wsBaseUrl: trimTrailingSlashes(
|
||||
process.env.EXPO_PUBLIC_WS_URL ?? 'ws://192.168.10.151:8000',
|
||||
),
|
||||
apiBaseUrl: resolveApiBaseUrl(),
|
||||
wsBaseUrl: resolveWsBaseUrl(),
|
||||
isDebugMode: __DEV__,
|
||||
appVariant,
|
||||
showAboutBackendUrl: shouldShowAboutBackendUrl(),
|
||||
|
||||
Reference in New Issue
Block a user