跳至内容
observabilityx

observabilityx

observabilityx

observabilityx 为日志/追踪/指标提供可选的统一门面。

路线图

为什么

  • 保持 authxeventxconfigx API 稳定。
  • 使可观测性后端可选。
  • 避免强制业务代码使用一个遥测栈。

后端

  • observabilityx.Nop() - 默认无操作后端。
  • observabilityx/otel - OpenTelemetry 后端(trace + metric)。
  • observabilityx/prometheus - Prometheus 后端(指标 + /metrics 处理器)。

组合多个后端

otelObs := otelobs.New()
promObs := promobs.New()

obs := observabilityx.Multi(otelObs, promObs)

接入包

manager, _ := authx.NewManager(
    authx.WithObservability(obs),
    authx.WithProvider(provider),
)

bus := eventx.New(
    eventx.WithObservability(obs),
)

var cfg AppConfig
_ = configx.Load(&cfg,
    configx.WithObservability(obs),
    configx.WithFiles("config.yaml"),
)

Prometheus 指标端点

promObs := promobs.New()

stdAdapter := std.New(nil, adapter.HumaOptions{
    DisableDocsRoutes: true,
})

metricsServer := httpx.New(
    httpx.WithAdapter(stdAdapter),
)
stdAdapter.Router().Handle("/metrics", promObs.Handler())

示例

  • multi: 组合 OTel + Prometheus 后端。