telemetry

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Aug 29, 2024 License: MIT Imports: 18 Imported by: 0

Documentation

Overview

Package telemetry provides functionality for instrumenting applications with OpenTelemetry-based tracing and metrics. It offers simple APIs for starting spans, recording metrics, and managing the telemetry lifecycle.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type OpenTelemetry added in v1.0.0

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

OpenTelemetry implements the Telemetry interface

func NewOpenTelemetry added in v1.0.0

func NewOpenTelemetry(serviceName, traceEndpoint, metricEndpoint string, traceEnabled, metricsEnabled bool) (*OpenTelemetry, error)

NewOpenTelemetry creates and initializes a new OpenTelemetry instance

func (*OpenTelemetry) AddEvent added in v1.0.0

func (o *OpenTelemetry) AddEvent(span trace.Span, name string, attributes ...attribute.KeyValue)

AddEvent adds an event to the given span

func (*OpenTelemetry) EndSpan added in v1.0.0

func (o *OpenTelemetry) EndSpan(span trace.Span)

EndSpan ends the given span

func (*OpenTelemetry) IncrementCounter added in v1.0.0

func (o *OpenTelemetry) IncrementCounter(ctx context.Context, name string, increment float64, attributes ...attribute.KeyValue)

IncrementCounter increments a counter metric

func (*OpenTelemetry) LogError added in v1.0.0

func (o *OpenTelemetry) LogError(ctx context.Context, message string, err error, attributes ...attribute.KeyValue)

LogError logs an error message

func (*OpenTelemetry) LogInfo added in v1.0.0

func (o *OpenTelemetry) LogInfo(ctx context.Context, message string, attributes ...attribute.KeyValue)

LogInfo logs an info message

func (*OpenTelemetry) LogWarning added in v1.0.0

func (o *OpenTelemetry) LogWarning(ctx context.Context, message string, attributes ...attribute.KeyValue)

LogWarning logs a warning message

func (*OpenTelemetry) PostEvent added in v1.0.0

func (o *OpenTelemetry) PostEvent(name string, properties map[string]string)

PostEvent posts an event with the given name and properties

func (*OpenTelemetry) PostTrace added in v1.0.0

func (o *OpenTelemetry) PostTrace(message string, severity string, properties map[string]string)

PostTrace posts a trace message with the given severity and properties

func (*OpenTelemetry) RecordError added in v1.0.0

func (o *OpenTelemetry) RecordError(ctx context.Context, err error, attributes ...attribute.KeyValue)

RecordError records an error as a span event and sets the span status

func (*OpenTelemetry) RecordGauge added in v1.0.0

func (o *OpenTelemetry) RecordGauge(ctx context.Context, name string, value float64, attributes ...attribute.KeyValue)

func (*OpenTelemetry) RecordMetric added in v1.0.0

func (o *OpenTelemetry) RecordMetric(ctx context.Context, name string, value float64, attributes ...attribute.KeyValue)

RecordMetric records a metric with the given name and value

func (*OpenTelemetry) SetSession added in v1.0.0

func (o *OpenTelemetry) SetSession(ctx context.Context, id string)

SetSession sets the session ID for the current context

func (*OpenTelemetry) SetUser added in v1.0.0

func (o *OpenTelemetry) SetUser(ctx context.Context, id string)

SetUser sets the user ID for the current context

func (*OpenTelemetry) Shutdown added in v1.0.0

func (o *OpenTelemetry) Shutdown(ctx context.Context) error

Shutdown shuts down the telemetry provider

func (*OpenTelemetry) StartSpan added in v1.0.0

func (o *OpenTelemetry) StartSpan(ctx context.Context, name string) (context.Context, trace.Span)

StartSpan starts a new span and returns the context and the span

func (*OpenTelemetry) TrackAvailability added in v1.0.0

func (o *OpenTelemetry) TrackAvailability(ctx context.Context, name string, duration time.Duration, success bool)

TrackAvailability records an availability test

func (*OpenTelemetry) TrackDependency added in v1.0.0

func (o *OpenTelemetry) TrackDependency(ctx context.Context, dependencyType, target string, duration time.Duration, success bool)

TrackDependency records a dependency call as a span

func (*OpenTelemetry) TrackRequest added in v1.0.0

func (o *OpenTelemetry) TrackRequest(ctx context.Context, method, url string, duration time.Duration, statusCode int)

TrackRequest records an HTTP request as a span

type Telemetry added in v1.0.0

type Telemetry interface {
	// StartSpan starts a new span and returns the context and the span
	StartSpan(ctx context.Context, name string) (context.Context, trace.Span)

	// EndSpan ends the given span
	EndSpan(span trace.Span)

	// AddEvent adds an event to the given span
	AddEvent(span trace.Span, name string, attributes ...attribute.KeyValue)

	// RecordMetric records a metric with the given name and value
	RecordMetric(ctx context.Context, name string, value float64, attributes ...attribute.KeyValue)

	// PostEvent posts an event with the given name and properties
	PostEvent(name string, properties map[string]string)

	// PostTrace posts a trace message with the given severity and properties
	PostTrace(message string, severity string, properties map[string]string)

	// RecordError records an error with the given attributes
	RecordError(ctx context.Context, err error, attributes ...attribute.KeyValue)

	// IncrementCounter increments a counter metric
	IncrementCounter(ctx context.Context, name string, increment float64, attributes ...attribute.KeyValue)

	// RecordGauge records a gauge metric
	RecordGauge(ctx context.Context, name string, value float64, attributes ...attribute.KeyValue)

	// LogInfo logs an info message
	LogInfo(ctx context.Context, message string, attributes ...attribute.KeyValue)

	// LogWarning logs a warning message
	LogWarning(ctx context.Context, message string, attributes ...attribute.KeyValue)

	// LogError logs an error message
	LogError(ctx context.Context, message string, err error, attributes ...attribute.KeyValue)

	// TrackRequest records an HTTP request as a span
	TrackRequest(ctx context.Context, method, url string, duration time.Duration, statusCode int)

	// TrackDependency records a dependency call as a span
	TrackDependency(ctx context.Context, dependencyType, target string, duration time.Duration, success bool)

	// TrackAvailability records an availability test
	TrackAvailability(ctx context.Context, name string, duration time.Duration, success bool)

	// SetUser sets the user ID for the current context
	SetUser(ctx context.Context, id string)

	// SetSession sets the session ID for the current context
	SetSession(ctx context.Context, id string)

	// Shutdown shuts down the telemetry provider
	Shutdown(ctx context.Context) error
}

Telemetry defines the interface for telemetry operations

func NewTelemetry added in v1.0.0

func NewTelemetry() (Telemetry, error)

NewTelemetry creates and returns the appropriate telemetry implementation

type TelemetryType added in v1.0.0

type TelemetryType string

TelemetryType represents the type of telemetry implementation to use

const (
	// TelemetryTypeOpenTelemetry represents the OpenTelemetry implementation
	TelemetryTypeOpenTelemetry TelemetryType = "opentelemetry"
	// TelemetryTypeAppInsights represents the Application Insights implementation
	TelemetryTypeAppInsights TelemetryType = "appinsights"
)

Jump to

Keyboard shortcuts

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