openrouter-compliance-review
Review OpenRouter integration for regulatory compliance (SOC2, GDPR,
maintainx-observability
Implement comprehensive observability for MaintainX integrations.
Full skill instructions
Implement metrics, structured logging, and alerting for MaintainX integrations to ensure reliability and rapid issue detection.
// src/observability/metrics.ts
import { Counter, Histogram, Gauge, Registry } from 'prom-client';
const register = new Registry();
export const metrics = {
apiRequests: new Counter({
name: 'maintainx_api_requests_total',
help: 'Total MaintainX API requests',
labelNames: ['method', 'endpoint', 'status'],
registers: [register],
}),
apiLatency: new Histogram({
name: 'maintainx_api_latency_seconds',
help: 'MaintainX API request latency',
labelNames: ['method', 'endpoint'],
buckets: [0.1, 0.25, 0.5, 1, 2.5, 5, 10],
registers: [register],
}),
rateLimitHits: new Counter({
name: 'maintainx_rate_limit_hits_total',
help: 'Times rate limited by MaintainX API',
registers: [register],
}),
workOrdersProcessed: new Counter({
name: 'maintainx_work_orders_processed_total',
help: 'Work orders processed',
labelNames: ['action', 'status'],
registers: [register],
}),
syncLag: new Gauge({
name: 'maintainx_sync_lag_seconds',
help: 'Seconds since last successful sync',
registers: [register],
}),
};
export { register };
// src/observability/instrumented-client.ts
import axios, { AxiosInstance } from 'axios';
import { metrics } from './metrics';
export function createInstrumentedClient(apiKey: string): AxiosInstance {
const client = axios.create({
baseURL: 'https://api.getmaintainx.com/v1',
headers: { Authorization: `Bearer ${apiKey}`, 'Content-Type': 'application/json' },
timeout: 30_000,
});
client.interceptors.request.use((config) => {
(config as any).__startTime = process.hrtime.bigint();
return config;
});
client.interceptors.response.use(
(response) => {
const elapsed = Number(process.hrtime.bigint() - (response.config as any).__startTime) / 1e9;
const endpoint = response.config.url?.split('?')[0] || 'unknown';
metrics.apiRequests.inc({
method: response.config.method?.toUpperCase() || 'GET',
endpoint,
status: String(response.status),
});
metrics.apiLatency.observe(
{ method: response.config.method?.toUpperCase() || 'GET', endpoint },
elapsed,
);
return response;
},
(error) => {
const status = error.response?.status || 0;
const endpoint = error.config?.url?.split('?')[0] || 'unknown';
metrics.apiRequests.inc({
method: error.config?.method?.toUpperCase() || 'GET',
endpoint,
status: String(status),
});
if (status === 429) {
metrics.rateLimitHits.inc();
}
throw error;
},
);
return client;
}
// src/observability/logger.ts
type LogLevel = 'debug' | 'info' | 'warn' | 'error';
interface LogEntry {
level: LogLevel;
message: string;
service: string;
timestamp: string;
[key: string]: any;
}
class StructuredLogger {
private service: string;
constructor(service: string) {
this.service = service;
}
private log(level: LogLevel, message: string, data?: Record<string, any>) {
const entry: LogEntry = {
level,
message,
service: this.service,
timestamp: new Date().toISOString(),
...data,
};
// JSON output for log aggregation (ELK, CloudWatch, Datadog)
console.log(JSON.stringify(entry));
}
info(message: string, data?: Record<string, any>) { this.log('info', message, data); }
warn(message: string, data?: Record<string, any>) { this.log('warn', message, data); }
error(message: string, data?: Record<string, any>) { this.log('error', message, data); }
debug(message: string, data?: Record<string, any>) { this.log('debug', message, data); }
}
export const logger = new StructuredLogger('maintainx-integration');
// Usage
logger.info('Work order created', { workOrderId: 12345, priority: 'HIGH' });
logger.error('API call failed', { endpoint: '/workorders', status: 500, retryCount: 2 });
// src/observability/server.ts
import express from 'express';
import { register, metrics } from './metrics';
const app = express();
// Prometheus scrape endpoint
app.get('/metrics', async (req, res) => {
res.set('Content-Type', register.contentType);
res.end(await register.metrics());
});
// Health check with metrics
app.get('/health', async (req, res) => {
const health = {
status: 'healthy',
uptime: process.uptime(),
metrics: {
totalRequests: await metrics.apiRequests.get(),
rateLimitHits: await metrics.rateLimitHits.get(),
syncLagSeconds: (await metrics.syncLag.get()).values[0]?.value || 0,
},
};
res.json(health);
});
app.listen(9090, () => logger.info('Metrics server on :9090'));
# prometheus/alerts.yml
groups:
- name: maintainx
rules:
- alert: MaintainXHighErrorRate
expr: rate(maintainx_api_requests_total{status=~"5.."}[5m]) > 0.1
for: 5m
labels:
severity: critical
annotations:
summary: "MaintainX API error rate > 10%"
- alert: MaintainXHighLatency
expr: histogram_quantile(0.95, rate(maintainx_api_latency_seconds_bucket[5m])) > 5
for: 5m
labels:
severity: warning
annotations:
summary: "MaintainX API p95 latency > 5s"
- alert: MaintainXRateLimited
expr: rate(maintainx_rate_limit_hits_total[5m]) > 0
for: 1m
labels:
severity: warning
annotations:
summary: "MaintainX API rate limiting detected"
- alert: MaintainXSyncStale
expr: maintainx_sync_lag_seconds > 900
for: 5m
labels:
severity: critical
annotations:
summary: "MaintainX sync lag > 15 minutes"
/metrics endpoint for Prometheus scraping| Issue | Cause | Solution |
|---|---|---|
| Metrics endpoint 500 | prom-client not initialized | Ensure Registry is created before metrics |
| Missing labels | Metric name mismatch | Check labelNames match inc()/observe() calls |
| Log volume too high | Debug logging in production | Set LOG_LEVEL=info in production |
| Stale sync alert | Sync job stopped | Check cron schedule, restart sync process |
For incident response, see maintainx-incident-runbook.
Datadog integration using DogStatsD:
import StatsD from 'hot-shots';
const dogstatsd = new StatsD({ prefix: 'maintainx.' });
// Record API call
dogstatsd.increment('api.requests', 1, { endpoint: '/workorders', status: '200' });
dogstatsd.histogram('api.latency', 0.45, { endpoint: '/workorders' });
Review OpenRouter integration for regulatory compliance (SOC2, GDPR,
Data synchronization, ETL patterns, and data management for MaintainX.
Execute Groq primary workflow: chat completions with tool use and JSON
Validate CSRF protection implementations for security gaps. Use when
Configure this skill should be used when the user asks about "API contract",
Execute Ideogram incident response with triage, mitigation, and postmortem.
Execute create, select, and transform features to improve machine learning
Reusable patterns for the Gamma REST API (no SDK exists).
Apply production-ready Deepgram SDK patterns for TypeScript and Python.
Migrate to OpenRouter from direct provider APIs or upgrade between SDK/model
Diagnose and fix common OpenRouter API errors. Use when encountering
Optimize Linear API usage, reduce unnecessary calls, and maximize
Generate, edit, and beat-sync AI video with leading models in one workspace.
The world's fastest calendar for remote work
Transform Your Design with AI Designer by ImgCreator.ai
Revolutionizing Video Production with AI-Powered Creativity
Extend an image past the frame and let AI fill the new aspect ratio.
Discover your celebrity doppelgänger with StarByFace!
ChainClarity explains 700+ crypto whitepapers in plain English, with layered summaries, comparisons, research tools, alerts, and a $4.99 Pro plan.
Opus.ai: Revolutionize Your Web Experience