Documentation
¶
Overview ¶
@index OpenTelemetry SDK tracer setup and trace-aware logging helpers for server paths.
Index ¶
- func ContextWithHTTPTrace(ctx context.Context, header http.Header) context.Context
- func ServerSpan(ctx context.Context, name string, header http.Header, ...) (context.Context, oteltrace.Span)
- func SetGlobal(t *Telemetry)
- func StartChildSpan(ctx context.Context, name string, attrs ...attribute.KeyValue) (context.Context, oteltrace.Span)
- func StartSpan(ctx context.Context, name string, attrs ...attribute.KeyValue) (context.Context, oteltrace.Span)
- func TraceLogArgs(ctx context.Context) []any
- type Config
- type Telemetry
- func (t *Telemetry) Shutdown(ctx context.Context) error
- func (t *Telemetry) StartChildSpan(ctx context.Context, name string, attrs ...attribute.KeyValue) (context.Context, oteltrace.Span)
- func (t *Telemetry) StartServerSpan(ctx context.Context, name string, header http.Header, ...) (context.Context, oteltrace.Span)
- func (t *Telemetry) StartSpan(ctx context.Context, name string, attrs ...attribute.KeyValue) (context.Context, oteltrace.Span)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ContextWithHTTPTrace ¶
ContextWithHTTPTrace extracts inbound trace headers into the provided context. @intent HTTP 요청의 traceparent와 baggage를 downstream span 시작에 연결한다.
func ServerSpan ¶
func ServerSpan(ctx context.Context, name string, header http.Header, attrs ...attribute.KeyValue) (context.Context, oteltrace.Span)
ServerSpan starts a server-kind span from the current global telemetry. @intent inbound HTTP 요청 처리를 공통 helper 하나로 server span화한다.
func SetGlobal ¶
func SetGlobal(t *Telemetry)
SetGlobal replaces the process-wide telemetry handle used by helper functions. @intent 서버 초기화 이후 어디서나 같은 tracer를 쓰도록 전역 핸들을 갱신한다. @sideEffect globalTelemetry를 교체한다.
func StartChildSpan ¶
func StartChildSpan(ctx context.Context, name string, attrs ...attribute.KeyValue) (context.Context, oteltrace.Span)
StartChildSpan starts a child span from the current global telemetry. @intent 현재 컨텍스트 아래 후속 작업 span을 일관된 helper로 생성한다.
func StartSpan ¶
func StartSpan(ctx context.Context, name string, attrs ...attribute.KeyValue) (context.Context, oteltrace.Span)
StartSpan starts an internal span from the current global telemetry. @intent 런타임 내부 작업을 현재 trace 아래 새 span으로 감싼다.
func TraceLogArgs ¶
TraceLogArgs extracts trace identifiers for structured logging. @intent span이 있는 컨텍스트를 slog 필드(trace_id, span_id, sampled)로 바꾼다.
Types ¶
type Config ¶
type Config struct {
ServiceName string
ServiceVersion string
Mode string
Endpoint string
Logger *slog.Logger
}
Config describes how the shared telemetry provider should be initialized. @intent 서비스 이름, 버전, export endpoint 같은 텔레메트리 부트스트랩 설정을 묶는다.
type Telemetry ¶
type Telemetry struct {
// contains filtered or unexported fields
}
Telemetry holds the active tracer provider and tracer used by CCG runtime code. @intent 서버 전역에서 재사용할 tracer provider 수명주기를 한 구조체로 묶는다.
func Global ¶
func Global() *Telemetry
Global returns the current process-wide telemetry handle. @intent helper 함수들이 명시적 의존성 주입 없이 현재 tracer를 가져오게 한다.
func Setup ¶
Setup builds the OpenTelemetry SDK provider and optional OTLP exporter. @intent endpoint 유무에 따라 local-only tracing 또는 OTLP export tracing을 초기화한다. @sideEffect 전역 tracer provider와 text map propagator를 설정한다.
func (*Telemetry) Shutdown ¶
Shutdown flushes and stops the active tracer provider. @intent 서버 종료 시 export 대기 중인 span을 정리하고 provider를 닫는다. @sideEffect tracer provider의 종료 훅을 실행한다.
func (*Telemetry) StartChildSpan ¶
func (t *Telemetry) StartChildSpan(ctx context.Context, name string, attrs ...attribute.KeyValue) (context.Context, oteltrace.Span)
StartChildSpan starts a child span with the telemetry instance tracer. @intent telemetry 인스턴스 기준으로 후속 작업 span을 생성한다.
func (*Telemetry) StartServerSpan ¶
func (t *Telemetry) StartServerSpan(ctx context.Context, name string, header http.Header, attrs ...attribute.KeyValue) (context.Context, oteltrace.Span)
StartServerSpan extracts inbound HTTP headers and starts a server-kind span. @intent telemetry 인스턴스에 묶인 tracer로 HTTP 진입 span을 시작한다.