Skip to content

Commit 5bc6b05

Browse files
committed
fix: 统一跨 Peer 时延指标的标签与秒分桶
1 parent 0e7435e commit 5bc6b05

2 files changed

Lines changed: 20 additions & 3 deletions

File tree

‎docs/30-unit-tdd/client-runtime-and-delegation.md‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,9 @@ exporter 为 10 秒,经 relay 为 35 秒,以覆盖服务端最多 32 秒的
151151
`JobManager.create` 在同一个 PostgREST INSERT 中写入 SDK 注入的提交 carrier。超出
152152
512 UTF-8 bytes 的可选 tracestate 会被省略并计数。执行成功 claim 后创建独立 trace,
153153
通过 SDK Span Link 关联提交;claim、取消和 close 不重写提交列。Job ID 是诊断关联字段,
154-
不是 trace ID。`job.submitted`、`job.started`、`job.closed` 只从明确的业务边界发出结构化
154+
不是 trace ID。时延指标 `inkcre.operation.duration` 使用与 Core 一致的 `operation` /
155+
`outcome` 标签和 5ms 至 300s 的显式秒分桶,便于跨 Peer 聚合;日志保留 `inkcre.*` 属性。
156+
`job.submitted`、`job.started`、`job.closed` 只从明确的业务边界发出结构化
155157
事件;既有应用日志、异常 message、参数和内容不会桥接到新增 OTLP。
156158

157159
浏览器原生 `await` 不能依赖 StackContextManager 或 ZoneContextManager 自动保留当前

‎packages/core/src/obsrv/telemetry.ts‎

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,11 +177,23 @@ export async function configureTelemetry(
177177
logger = provider.getLogger('inkcre.browser')
178178
}
179179
if (endpoints.metrics) {
180-
const { MeterProvider, PeriodicExportingMetricReader } =
180+
const { MeterProvider, PeriodicExportingMetricReader, AggregationType } =
181181
await import('@opentelemetry/sdk-metrics')
182182
const { OTLPMetricExporter } = await import('@opentelemetry/exporter-metrics-otlp-proto')
183183
const provider = new MeterProvider({
184184
resource,
185+
// Match the Core histogram so cross-Peer aggregation keeps seconds and buckets aligned.
186+
views: [
187+
{
188+
instrumentName: 'inkcre.operation.duration',
189+
aggregation: {
190+
type: AggregationType.EXPLICIT_BUCKET_HISTOGRAM,
191+
options: {
192+
boundaries: [0.005, 0.01, 0.025, 0.05, 0.1, 0.25, 0.5, 1, 2.5, 5, 10, 30, 60, 300],
193+
},
194+
},
195+
},
196+
],
185197
readers: [
186198
new PeriodicExportingMetricReader({
187199
exporter: new OTLPMetricExporter({
@@ -255,7 +267,10 @@ export async function observeOperation<T>(
255267
} finally {
256268
span.end()
257269
const attributes = { 'inkcre.operation': name, 'inkcre.outcome': result.outcome }
258-
operationDuration?.record((performance.now() - started) / 1000, attributes)
270+
operationDuration?.record((performance.now() - started) / 1000, {
271+
operation: name,
272+
outcome: result.outcome,
273+
})
259274
operationLogger?.emit({
260275
context: active,
261276
eventName: 'inkcre.operation.completed',

0 commit comments

Comments
 (0)