obs

package module
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 17, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package obs 提供 bootstrap 的可观测性接入组件(独立嵌套 module)。

以 BootstrapperOption 函数的形式注入 Prometheus 指标(oekit/metrics) 与 OpenTelemetry 追踪(oekit/tracing),使根包 github.com/oekit/bootstrap 保持零 prometheus/otel 依赖。

用法

b, _ := bootstrap.New(
    bootstrap.WithServiceName("my-service"),
    obs.WithMetrics(),
    obs.WithTracing(tracing.Config{Endpoint: "otel:4317"}),
)
err := b.Run(userFn)

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WithMetrics

func WithMetrics() bootstrap.BootstrapperOption

WithMetrics 添加 Prometheus 指标注册组件。 serviceName 由 bootstrap.New 经 ServiceNameAware 统一回填,与 WithServiceName 的调用顺序无关。

func WithTracing

func WithTracing(cfg tracing.Config) bootstrap.BootstrapperOption

WithTracing 添加 OpenTelemetry 追踪组件。

Types

type MetricsComponent

type MetricsComponent struct {
	// ServiceName 用于 Prometheus 指标中的 service 标签。
	// 由 bootstrap.New 在应用完全部选项后经 ServiceNameAware 接口统一回填。
	ServiceName string
}

MetricsComponent Prometheus 指标注册组件。

func (*MetricsComponent) Init

Init 注册 Prometheus 指标。

func (*MetricsComponent) Name

func (c *MetricsComponent) Name() string

Name 返回组件名称。

func (*MetricsComponent) SetServiceName

func (c *MetricsComponent) SetServiceName(name string)

SetServiceName 实现 bootstrap.ServiceNameAware,由 New 统一回填。

type TracingComponent

type TracingComponent struct {
	Config tracing.Config
}

TracingComponent OpenTelemetry 追踪初始化组件。

func (*TracingComponent) Init

Init 初始化 OpenTelemetry 追踪,并注册 shutdown 钩子。

func (*TracingComponent) Name

func (c *TracingComponent) Name() string

Name 返回组件名称。

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL