Best practices
Production-ready patterns for Amlexia instrumentation.
SDK key hygiene
- Store
AMLEXIA_SDK_KEYin server env or a secrets manager — never in git, never in the browser. - Use separate projects for staging and production so test traffic does not skew alerts.
- Rotate keys from the dashboard if a key is exposed.
Shutdown and deploys
Always flush on process exit so the last batch is not lost:
typescript
process.on('SIGTERM', async () => {
await client.shutdown();
process.exit(0);
});python
import atexit
atexit.register(client.shutdown)On serverless (short-lived workers), call flush() after each invocation if you cannot rely on shutdown().
Route naming
- Prefer middleware so paths are normalized (
/users/:idnot/users/42). - For outbound calls, use a clear endpoint label:
POST openai/chator the real path. - Background jobs:
track()with a stable name likecron/sync-inventory.
Metadata
- Do not log passwords, API keys, full request bodies, or raw emails in
metadata. - Prefer ids and enums:
plan: "pro",feature: "checkout".
Alerts
- Start with error rate and p95 latency on your top 3 routes.
- Add cost alerts if you run heavy LLM traffic.
- Use a staging project to validate thresholds before paging production.
Staging vs production
| Practice | Why |
|---|---|
| Different SDK keys per environment | Clean separation in dashboard |
Set AMLEXIA_ENVIRONMENT | Filter and compare in traces |
Set AMLEXIA_RELEASE to git SHA | Tie incidents to deploys |
Performance
- Default batching (5s / 50 events) is safe for most APIs.
- High-throughput services: lower
flushIntervalMsonly if you need faster Live view — more HTTP calls to ingest. - SDK retries handle transient 429/5xx; fix sustained 429 by reducing volume or contacting support.
