telemetry

package
v0.0.0-...-d09923a Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2026 License: LGPL-2.1 Imports: 31 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ScopeName = "github.com/sky-as-code/nikki-erp"

	// MetadataIdempotencyId is the bus/envelope metadata key; traceparent, tracestate and
	// baggage use their W3C header names.
	MetadataIdempotencyId = "idempotency_id"
)
View Source
const (
	BaggageMaxEntries = 16
	BaggageMaxBytes   = 2048
)
View Source
const (
	ExporterNone    = "none"
	ExporterOtlp    = "otlp"
	ExporterConsole = "console"

	ProtocolHttpProtobuf = "http/protobuf"
	ProtocolGrpc         = "grpc"

	SamplerParentBasedRatio = "parentbased_traceidratio"
)
View Source
const AttrCancelled = "coremart.cancelled"

AttrCancelled marks a span whose operation the client ended. It is not an error, so the status stays unset (BR §5, streaming).

View Source
const HeaderIdempotencyId = "X-Idempotency-ID"

Variables

View Source
var ServiceVersion = ""

ServiceVersion is set at build time: -ldflags "-X .../modules/core/telemetry.ServiceVersion=1.2.3".

Functions

func ExtractFromMetadata

func ExtractFromMetadata(ctx context.Context, metadata map[string]string) context.Context

ExtractFromMetadata is InjectToMetadata's inverse. An invalid idempotency id is dropped, not replaced: the consumer decides whether its unit of work needs a new one.

func InitSubModule

func InitSubModule(cfg config.ConfigService, logger logging.LoggerService) error

InitSubModule installs the global tracer provider, propagator and error handler. It runs right after config, before anything that builds a client or serves traffic.

func InjectToMetadata

func InjectToMetadata(ctx context.Context, metadata map[string]string)

InjectToMetadata writes the active span context, allowlisted baggage and the idempotency id into an envelope's metadata.

func MarkCancelled

func MarkCancelled(ctx context.Context)

func NewPropagator

func NewPropagator(names []string, baggageAllowlist []string) propagation.TextMapPropagator

NewPropagator returns the configured propagators. Baggage, when enabled, is always the allowlisting one: the SDK's own would carry every key through.

func NewTracerProvider

func NewTracerProvider(ctx context.Context, settings Settings) (*sdktrace.TracerProvider, []string, error)

NewTracerProvider always returns a real SDK provider, so trace and span IDs exist and propagate even when nothing is exported. The returned warnings are settings that fell back to a default.

func NewTransport

func NewTransport(base http.RoundTripper, allowedHosts []string, options ...otelhttp.Option) http.RoundTripper

NewTransport instruments an outbound transport. Per hop it strips the propagation headers a request inherited (net/http copies headers onto redirects), opens a CLIENT span through otelhttp, and injects the span context and X-Idempotency-ID only when the hop's host is allowlisted, so a redirect to another host is judged again.

func PropagationHostAllowlist

func PropagationHostAllowlist() []string

PropagationHostAllowlist is the configured CORE.TELEMETRY.PROPAGATION_HOST_ALLOWLIST, for building NewTransport.

func Propagator

func Propagator() propagation.TextMapPropagator

func Shutdown

func Shutdown(ctx context.Context) error

Shutdown flushes pending spans and stops the provider. Call it after the HTTP server has drained, with a bounded ctx: an unreachable receiver must not hold the process.

func ShutdownTimeout

func ShutdownTimeout() time.Duration

ShutdownTimeout is CORE.TELEMETRY.SHUTDOWN_FLUSH_SECS, or 5 seconds before InitSubModule ran.

func StartDetached

func StartDetached(ctx context.Context, name string) (context.Context, trace.Span)

StartDetached starts a new root INTERNAL span for work that outlives the request, linked to the span ctx carries. The returned context keeps ctx's values (idempotency id included) but not its cancellation, so the request ending does not abort the work.

func Tracer

func Tracer(scope string) trace.Tracer

Types

type AllowlistBaggage

type AllowlistBaggage struct {
	// contains filtered or unexported fields
}

AllowlistBaggage keeps only allowlisted keys, at most BaggageMaxEntries members and BaggageMaxBytes encoded. Inbound members are kept in header order; outbound in key order, as a context's baggage has no order of its own. Each member is parsed by the SDK's parser.

func NewAllowlistBaggage

func NewAllowlistBaggage(allowlist []string) AllowlistBaggage

func (AllowlistBaggage) Extract

func (AllowlistBaggage) Fields

func (this AllowlistBaggage) Fields() []string

func (AllowlistBaggage) Inject

func (this AllowlistBaggage) Inject(ctx context.Context, carrier propagation.TextMapCarrier)

type Settings

type Settings struct {
	ServiceName        string
	ResourceAttributes map[string]string
	Propagators        []string
	Sampler            string
	SamplerArg         string
	Exporter           string
	OtlpProtocol       string
	OtlpEndpoint       string
	OtlpHeaders        map[string]string
	BspMaxQueueSize    int
	BspMaxExportBatch  int
	BspExportTimeout   time.Duration
	BspScheduleDelay   time.Duration
	BaggageAllowlist   []string
	HostAllowlist      []string
	ShutdownFlush      time.Duration
}

func LoadSettings

func LoadSettings(cfg config.ConfigService) Settings

LoadSettings passes a default for every key, so a binary whose config predates telemetry still boots with exporting off.

Jump to

Keyboard shortcuts

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