Loading...
Loading...
Compare original and translation side by side
| Metric | Type | Description |
|---|---|---|
| Counter | Total API requests |
| Histogram | Request latency |
| Counter | Error count by type |
| Gauge | Rate limit headroom |
| 指标 | 类型 | 描述 |
|---|---|---|
| Counter | 总API请求数 |
| Histogram | 请求延迟 |
| Counter | 按类型统计的错误数 |
| Gauge | 剩余限流额度 |
import { Registry, Counter, Histogram, Gauge } from 'prom-client';
const registry = new Registry();
const requestCounter = new Counter({
name: 'instantly_requests_total',
help: 'Total Instantly API requests',
labelNames: ['method', 'status'],
registers: [registry],
});
const requestDuration = new Histogram({
name: 'instantly_request_duration_seconds',
help: 'Instantly request duration',
labelNames: ['method'],
buckets: [0.05, 0.1, 0.25, 0.5, 1, 2.5, 5],
registers: [registry],
});
const errorCounter = new Counter({
name: 'instantly_errors_total',
help: 'Instantly errors by type',
labelNames: ['error_type'],
registers: [registry],
});import { Registry, Counter, Histogram, Gauge } from 'prom-client';
const registry = new Registry();
const requestCounter = new Counter({
name: 'instantly_requests_total',
help: 'Total Instantly API requests',
labelNames: ['method', 'status'],
registers: [registry],
});
const requestDuration = new Histogram({
name: 'instantly_request_duration_seconds',
help: 'Instantly request duration',
labelNames: ['method'],
buckets: [0.05, 0.1, 0.25, 0.5, 1, 2.5, 5],
registers: [registry],
});
const errorCounter = new Counter({
name: 'instantly_errors_total',
help: 'Instantly errors by type',
labelNames: ['error_type'],
registers: [registry],
});async function instrumentedRequest<T>(
method: string,
operation: () => Promise<T>
): Promise<T> {
const timer = requestDuration.startTimer({ method });
try {
const result = await operation();
requestCounter.inc({ method, status: 'success' });
return result;
} catch (error: any) {
requestCounter.inc({ method, status: 'error' });
errorCounter.inc({ error_type: error.code || 'unknown' });
throw error;
} finally {
timer();
}
}async function instrumentedRequest<T>(
method: string,
operation: () => Promise<T>
): Promise<T> {
const timer = requestDuration.startTimer({ method });
try {
const result = await operation();
requestCounter.inc({ method, status: 'success' });
return result;
} catch (error: any) {
requestCounter.inc({ method, status: 'error' });
errorCounter.inc({ error_type: error.code || 'unknown' });
throw error;
} finally {
timer();
}
}import { trace, SpanStatusCode } from '@opentelemetry/api';
const tracer = trace.getTracer('instantly-client');
async function tracedInstantlyCall<T>(
operationName: string,
operation: () => Promise<T>
): Promise<T> {
return tracer.startActiveSpan(`instantly.${operationName}`, async (span) => {
try {
const result = await operation();
span.setStatus({ code: SpanStatusCode.OK });
return result;
} catch (error: any) {
span.setStatus({ code: SpanStatusCode.ERROR, message: error.message });
span.recordException(error);
throw error;
} finally {
span.end();
}
});
}import { trace, SpanStatusCode } from '@opentelemetry/api';
const tracer = trace.getTracer('instantly-client');
async function tracedInstantlyCall<T>(
operationName: string,
operation: () => Promise<T>
): Promise<T> {
return tracer.startActiveSpan(`instantly.${operationName}`, async (span) => {
try {
const result = await operation();
span.setStatus({ code: SpanStatusCode.OK });
return result;
} catch (error: any) {
span.setStatus({ code: SpanStatusCode.ERROR, message: error.message });
span.recordException(error);
throw error;
} finally {
span.end();
}
});
}import pino from 'pino';
const logger = pino({
name: 'instantly',
level: process.env.LOG_LEVEL || 'info',
});
function logInstantlyOperation(
operation: string,
data: Record<string, any>,
duration: number
) {
logger.info({
service: 'instantly',
operation,
duration_ms: duration,
...data,
});
}import pino from 'pino';
const logger = pino({
name: 'instantly',
level: process.env.LOG_LEVEL || 'info',
});
function logInstantlyOperation(
operation: string,
data: Record<string, any>,
duration: number
) {
logger.info({
service: 'instantly',
operation,
duration_ms: duration,
...data,
});
}undefinedundefinedundefinedundefined{
"panels": [
{
"title": "Instantly Request Rate",
"targets": [{
"expr": "rate(instantly_requests_total[5m])"
}]
},
{
"title": "Instantly Latency P50/P95/P99",
"targets": [{
"expr": "histogram_quantile(0.5, rate(instantly_request_duration_seconds_bucket[5m]))"
}]
}
]
}{
"panels": [
{
"title": "Instantly Request Rate",
"targets": [{
"expr": "rate(instantly_requests_total[5m])"
}]
},
{
"title": "Instantly Latency P50/P95/P99",
"targets": [{
"expr": "histogram_quantile(0.5, rate(instantly_request_duration_seconds_bucket[5m]))"
}]
}
]
}| Issue | Cause | Solution |
|---|---|---|
| Missing metrics | No instrumentation | Wrap client calls |
| Trace gaps | Missing propagation | Check context headers |
| Alert storms | Wrong thresholds | Tune alert rules |
| High cardinality | Too many labels | Reduce label values |
| 问题 | 原因 | 解决方案 |
|---|---|---|
| 缺失指标 | 无埋点 | 封装客户端调用 |
| 链路断层 | 缺少上下文传播 | 检查上下文头 |
| 告警风暴 | 阈值不合理 | 调整告警规则 |
| 高基数 | 标签过多 | 减少标签值数量 |
app.get('/metrics', async (req, res) => {
res.set('Content-Type', registry.contentType);
res.send(await registry.metrics());
});app.get('/metrics', async (req, res) => {
res.set('Content-Type', registry.contentType);
res.send(await registry.metrics());
});instantly-incident-runbookinstantly-incident-runbook