Documentation
¶
Index ¶
- Constants
- Variables
- func ExtractFromMetadata(ctx context.Context, metadata map[string]string) context.Context
- func InitSubModule(cfg config.ConfigService, logger logging.LoggerService) error
- func InjectToMetadata(ctx context.Context, metadata map[string]string)
- func MarkCancelled(ctx context.Context)
- func NewPropagator(names []string, baggageAllowlist []string) propagation.TextMapPropagator
- func NewTracerProvider(ctx context.Context, settings Settings) (*sdktrace.TracerProvider, []string, error)
- func NewTransport(base http.RoundTripper, allowedHosts []string, options ...otelhttp.Option) http.RoundTripper
- func PropagationHostAllowlist() []string
- func Propagator() propagation.TextMapPropagator
- func Shutdown(ctx context.Context) error
- func ShutdownTimeout() time.Duration
- func StartDetached(ctx context.Context, name string) (context.Context, trace.Span)
- func Tracer(scope string) trace.Tracer
- type AllowlistBaggage
- type Settings
Constants ¶
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" )
const ( BaggageMaxEntries = 16 BaggageMaxBytes = 2048 )
const ( ExporterNone = "none" ExporterOtlp = "otlp" ExporterConsole = "console" ProtocolHttpProtobuf = "http/protobuf" ProtocolGrpc = "grpc" SamplerParentBasedRatio = "parentbased_traceidratio" )
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).
const HeaderIdempotencyId = "X-Idempotency-ID"
Variables ¶
var ServiceVersion = ""
ServiceVersion is set at build time: -ldflags "-X .../modules/core/telemetry.ServiceVersion=1.2.3".
Functions ¶
func ExtractFromMetadata ¶
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 ¶
InjectToMetadata writes the active span context, allowlisted baggage and the idempotency id into an envelope's metadata.
func MarkCancelled ¶
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 ¶
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 ¶
ShutdownTimeout is CORE.TELEMETRY.SHUTDOWN_FLUSH_SECS, or 5 seconds before InitSubModule ran.
func StartDetached ¶
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.
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 (this AllowlistBaggage) Extract(ctx context.Context, carrier propagation.TextMapCarrier) context.Context
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.