telemetry

package
v1.1.1035 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2024 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CtxSpanToNatsMsgMiddleware

func CtxSpanToNatsMsgMiddleware() middleware.Send

CtxSpanToNatsMsgMiddleware returns a middleware function which attaches telemetry to outgoing messages.

func CtxWithSpanToNatsMsg

func CtxWithSpanToNatsMsg(ctx context.Context, msg jetstream.Msg)

CtxWithSpanToNatsMsg injects traceID and spanID into a NATS message based on the provided context.

func CtxWithTraceParentFromNatsMsg

func CtxWithTraceParentFromNatsMsg(ctx context.Context, msg jetstream.Msg) context.Context

CtxWithTraceParentFromNatsMsg injects the traceparent value from a NATS message into the provided context. If the traceparent value is present in the message header, it is set as the value for the ctxkey.Traceparent key in the context. If the traceparent value is not present, a new traceparent value is generated with an empty spanID and set as the value for the ctxkey.Traceparent key in the context.

func CtxWithTraceParentFromNatsMsgMiddleware

func CtxWithTraceParentFromNatsMsgMiddleware() middleware.Receive

CtxWithTraceParentFromNatsMsgMiddleware is a middleware function that wraps the receive function in order to inject traceparent into the context based on the NATS message. The receive function should have the signature func(ctx context.Context, msg *nats.Msg) (context.Context, error).

func CtxWithTraceParentToWfState

func CtxWithTraceParentToWfState(ctx context.Context, state *model.WorkflowState)

CtxWithTraceParentToWfState injects the traceparent from the context into a WorkflowState. If telemetry is enabled in the configuration, the traceID and spanID will be extracted from the context and assigned to the TraceParent field of the WorkflowState object.

func GetTraceparentTraceAndSpan

func GetTraceparentTraceAndSpan(traceparent string) (string, string)

GetTraceparentTraceAndSpan returns a trace and span from a W3C traceparent

func NatsMsgToCtxWithSpan

func NatsMsgToCtxWithSpan(ctx context.Context, msg jetstream.Msg) context.Context

NatsMsgToCtxWithSpan injects traceID and spanID into a context based on the provided NATS message.

func NatsMsgToCtxWithSpanMiddleware

func NatsMsgToCtxWithSpanMiddleware() middleware.Receive

NatsMsgToCtxWithSpanMiddleware returns a middleware function which extracts telemetry from incoming messages.

func NewTraceID

func NewTraceID() [16]byte

NewTraceID generates a new W3C trace ID with 16 bytes of random data.

func NewTraceParent

func NewTraceParent(traceID [16]byte, spanID [8]byte) string

NewTraceParent returns a new W3C traceparent string using the provided traceID and spanID.

func NewTraceParentWithEmptySpan

func NewTraceParentWithEmptySpan(traceID [16]byte) string

NewTraceParentWithEmptySpan generates a traceparent string based on the provided trace ID. The spanID is left as a dummy value. The traceparent format follows the W3C Trace Context specification (https://www.w3.org/TR/trace-context/). Format: 00-{traceID}-{spanID}-00

func SetTraceParentSpanID

func SetTraceParentSpanID(traceparent string, spanID string) string

SetTraceParentSpanID sets the span portion of a W3C traceparent and returns a new W3C traceparent

func StartApiSpan

func StartApiSpan(ctx context.Context, tracerName string, apiName string) (context.Context, trace.Span)

StartApiSpan starts a new API span with the provided tracer name and API name. It takes a context, tracer name, and API name as input parameters. The function extracts the trace and span IDs from the provided traceparent string. If the trace ID is invalid, it starts a new root span with the tracer name and API name using the OpenTelemetry Tracer Provider. If the span ID is empty, it starts a new root span and updates the traceparent string with the new span ID. Otherwise, it creates a new SpanContext with the extracted trace and span IDs and updates the context with the remote span context. Finally, it starts a new span with the updated context, tracer name, and API name using the OpenTelemetry Tracer Provider. The function returns the updated context and the started span.

func TraceIDFromTraceparent

func TraceIDFromTraceparent(traceparent string) (trace.TraceID, error)

TraceIDFromTraceparent extracts the trace ID from a W3C traceparent header and returns it as a trace.TraceID

Types

type Config

type Config struct {
	Enabled  bool
	Endpoint string
}

Config describes the open-telemetry configuration for an application

type JetStreamCarrier added in v1.1.927

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

JetStreamCarrier defines an open telemetry carrier that serialises to NATS headers

func NewJetStreamCarrier added in v1.1.927

func NewJetStreamCarrier(msg jetstream.Msg) *JetStreamCarrier

NewJetStreamCarrier creates a new instance of NatsCarrier

func (*JetStreamCarrier) Get added in v1.1.927

func (c *JetStreamCarrier) Get(key string) string

Get a header value

func (*JetStreamCarrier) Keys added in v1.1.927

func (c *JetStreamCarrier) Keys() []string

Keys - returns all header keys

func (*JetStreamCarrier) Set added in v1.1.927

func (c *JetStreamCarrier) Set(key string, value string)

Set a header value

type MapCarrier

type MapCarrier struct {
	Map map[string]string
}

MapCarrier defines an open telemetry carrier that serialises to a go map[string]string

func NewMapCarrier

func NewMapCarrier() *MapCarrier

NewMapCarrier creates a new instance of MapCarrier

func (*MapCarrier) Get

func (c *MapCarrier) Get(key string) string

Get a map key

func (*MapCarrier) Keys

func (c *MapCarrier) Keys() []string

Keys - gets all map keys

func (*MapCarrier) Set

func (c *MapCarrier) Set(key string, value string)

Set a map key

type NatsCarrier

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

NatsCarrier defines an open telemetry carrier that serialises to NATS headers

func (*NatsCarrier) Get

func (c *NatsCarrier) Get(key string) string

Get a header value

func (*NatsCarrier) Keys

func (c *NatsCarrier) Keys() []string

Keys - returns all header keys

func (*NatsCarrier) Set

func (c *NatsCarrier) Set(key string, value string)

Set a header value

type PropagateOption

type PropagateOption func(*propagateOptions)

PropagateOption is the prototype for the propagate option function

func WithNewDefaultTraceId

func WithNewDefaultTraceId() PropagateOption

WithNewDefaultTraceId returns a PropagateOption function that sets the default trace ID to a newly generated trace ID.

type TraceParams

type TraceParams struct {
	TraceParent string
}

TraceParams represents parameters related to tracing

Jump to

Keyboard shortcuts

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