telemetry

package
v0.2.16 Latest Latest
Warning

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

Go to latest
Published: Apr 14, 2025 License: Apache-2.0 Imports: 25 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ComponentGraphQL  = "graphql"
	ComponentPostgres = "postgres"
	ComponentREST     = "rest"
	ComponentService  = "service"
	ComponentListener = "listener"
	ComponentCronJob  = "cron"
)

Component tag constants

View Source
const (
	SpanTagTenant    = "tenant"
	SpanTagUserId    = "user.id"
	SpanTagUserEmail = "user.email"
	SpanTagEntityId  = "entity.id"
)
View Source
const (
	SpanKindInternal = "internal"
	SpanKindServer   = "server"
	SpanKindClient   = "client"
	SpanKindProducer = "producer"
	SpanKindConsumer = "consumer"
)

SpanKind constants

Variables

This section is empty.

Functions

func ExtractOTelSpanID added in v0.2.1

func ExtractOTelSpanID(span trace.Span) string

ExtractOTelSpanID extracts OpenTelemetry span ID from span

func ExtractOTelTraceID added in v0.2.1

func ExtractOTelTraceID(span trace.Span) string

ExtractOTelTraceID extracts OpenTelemetry trace ID from span

func FinishSpans

func FinishSpans(spans *Spans)

FinishSpans ends both Jaeger and OpenTelemetry spans

func GetDefaultServiceSpanAttributes added in v0.2.1

func GetDefaultServiceSpanAttributes(ctx context.Context) []attribute.KeyValue

GetDefaultServiceSpanAttributes returns default attributes for service spans

func InitOpenTelemetry

func InitOpenTelemetry(ctx context.Context, cfg *OpenTelemetryConfig) error

InitOpenTelemetry initializes OpenTelemetry with the given configuration

func LogDebug

func LogDebug(ctx context.Context, msg string, fields ...log.Field)

TODO not used yet, check if needed

func LogError

func LogError(ctx context.Context, err error, fields ...log.Field)

TODO not used yet, check if needed

func LogInfo

func LogInfo(ctx context.Context, msg string, fields ...log.Field)

func LogObjectAsJson added in v0.2.7

func LogObjectAsJson(span opentracing.Span, name string, object any)

func NewJaegerTracer added in v0.2.7

func NewJaegerTracer(jaegerConfig *JaegerConfig, log logger.Logger) (opentracing.Tracer, io.Closer, error)

func Recover added in v0.2.15

func Recover(spans *Spans, logger logger.Logger)

func RecoveryWithJaeger added in v0.2.7

func RecoveryWithJaeger(tracer opentracing.Tracer) gin.HandlerFunc

func SetDefaultServiceSpanAttributes added in v0.2.1

func SetDefaultServiceSpanAttributes(ctx context.Context, span trace.Span)

SetDefaultServiceSpanAttributes sets default attributes on a span

func SetDefaultSpanTags added in v0.2.7

func SetDefaultSpanTags(ctx context.Context, span opentracing.Span)

func SetSpanKindClient

func SetSpanKindClient(spans *Spans)

func SetSpanKindConsumer

func SetSpanKindConsumer(spans *Spans)

func SetSpanKindDatabase

func SetSpanKindDatabase(spans *Spans)

func SetSpanKindInternal

func SetSpanKindInternal(spans *Spans)

Span Kind Helpers

func SetSpanKindProducer

func SetSpanKindProducer(spans *Spans)

func SetSpanKindServer

func SetSpanKindServer(spans *Spans)

func StartHttpServerTracerSpanWithHeader added in v0.2.7

func StartHttpServerTracerSpanWithHeader(ctx context.Context, operationName string, headers http.Header) (context.Context, opentracing.Span)

func TagComponentCronJob

func TagComponentCronJob(spans *Spans)

func TagComponentGraphQL

func TagComponentGraphQL(spans *Spans)

Component Tagging Helpers

func TagComponentListener

func TagComponentListener(spans *Spans)

func TagComponentPostgres

func TagComponentPostgres(spans *Spans)

func TagComponentREST

func TagComponentREST(spans *Spans)

func TagComponentService

func TagComponentService(spans *Spans)

func TagError

func TagError(span opentracing.Span, err error)

Error Handling

func TraceErr added in v0.2.7

func TraceErr(span opentracing.Span, err error, fields ...log.Field)

Types

type JaegerConfig added in v0.2.7

type JaegerConfig struct {
	Endpoint     string  `env:"JAEGER_ENDPOINT"`
	ServiceName  string  `env:"JAEGER_SERVICE_NAME" validate:"required"`
	AgentHost    string  `env:"JAEGER_AGENT_HOST" envDefault:"localhost" validate:"required"`
	AgentPort    string  `env:"JAEGER_AGENT_PORT" envDefault:"6831" validate:"required"`
	Enabled      bool    `env:"JAEGER_ENABLED" envDefault:"true"`
	LogSpans     bool    `env:"JAEGER_REPORTER_LOG_SPANS" envDefault:"false" `
	SamplerType  string  `env:"JAEGER_SAMPLER_TYPE" envDefault:"const" validate:"required"`
	SamplerParam float64 `env:"JAEGER_SAMPLER_PARAM" envDefault:"1" validate:"required"`
}

type OpenTelemetryConfig

type OpenTelemetryConfig struct {
	Enabled     bool   `env:"OTEL_ENABLED" envDefault:"true"`
	Endpoint    string `env:"OTEL_ENDPOINT" envDefault:"otel-collector:4319"`
	ServiceName string `env:"OTEL_SERVICE_NAME" envDefault:"mailstack"`
	Timeout     int    `env:"OTEL_TIMEOUT" envDefault:"30"`
}

type SpanOptions added in v0.2.1

type SpanOptions struct {
	NewRoot bool
}

SpanOptions defines options for span creation

func WithNewRoot added in v0.2.1

func WithNewRoot() SpanOptions

WithForceNewTrace returns a SpanOptions that forces creation of a new trace

type Spans

type Spans struct {
	Jaeger opentracing.Span
	OTel   trace.Span
}

Types and Constants

func StartCronSpan

func StartCronSpan(ctx context.Context, operationName string, opts ...SpanOptions) (*Spans, context.Context)

Component-specific Span Starters

func StartGraphQLSpan

func StartGraphQLSpan(ctx context.Context, operationName string, opts ...SpanOptions) (*Spans, context.Context)

func StartListenerSpan

func StartListenerSpan(ctx context.Context, operationName string, opts ...SpanOptions) (*Spans, context.Context)

func StartPostgresSpan

func StartPostgresSpan(ctx context.Context, operationName string, opts ...SpanOptions) (*Spans, context.Context)

func StartProducerSpan

func StartProducerSpan(ctx context.Context, operationName string, opts ...SpanOptions) (*Spans, context.Context)

func StartRestSpan

func StartRestSpan(ctx context.Context, operationName string, opts ...SpanOptions) (*Spans, context.Context)

func StartServiceSpan

func StartServiceSpan(ctx context.Context, operationName string, opts ...SpanOptions) (*Spans, context.Context)

func StartSpan added in v0.2.15

func StartSpan(ctx context.Context, operationName string, opts ...SpanOptions) (*Spans, context.Context)

Core Span Operations

func (*Spans) Finish added in v0.2.1

func (s *Spans) Finish()

Finish ends both Jaeger and OpenTelemetry spans

func (*Spans) LogFields

func (s *Spans) LogFields(fields ...log.Field)

Logging Methods

func (*Spans) LogKV

func (s *Spans) LogKV(alternatingKeyValues ...interface{})

func (*Spans) LogObjectAsJson

func (s *Spans) LogObjectAsJson(key string, obj interface{})

func (*Spans) TagBool

func (s *Spans) TagBool(key string, value bool)

func (*Spans) TagEntity

func (s *Spans) TagEntity(entityId string)

func (*Spans) TagInt

func (s *Spans) TagInt(key string, value int)

func (*Spans) TagString

func (s *Spans) TagString(key, value string)

Tagging Methods

func (*Spans) TagStringSlice

func (s *Spans) TagStringSlice(key string, value []string)

func (*Spans) TagUint32 added in v0.2.1

func (s *Spans) TagUint32(key string, value uint32)

func (*Spans) TraceError

func (s *Spans) TraceError(err error)

Jump to

Keyboard shortcuts

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