Documentation ¶
Index ¶
- func AddAnnotation(ctx context.Context, event string)
- func AddAnnotationWithAttr(ctx context.Context, event string, attr []attribute.KeyValue)
- type Attributes
- type MeterProvider
- type OTelConfig
- type OpenTelemetry
- func (o *OpenTelemetry) EndSpan(span trace.Span)
- func (o *OpenTelemetry) InitMeterProvider(ctx context.Context, resource *resource.Resource) (*sdkmetric.MeterProvider, error)
- func (o *OpenTelemetry) InitTracerProvider(ctx context.Context, resource *resource.Resource) (*sdktrace.TracerProvider, error)
- func (o *OpenTelemetry) RecordError(span trace.Span, err error)
- func (o *OpenTelemetry) RecordLatencyMetric(ctx context.Context, duration time.Time, attrs Attributes)
- func (o *OpenTelemetry) RecordRequestCountMetric(ctx context.Context, attrs Attributes)
- func (o *OpenTelemetry) SetError(ctx context.Context, err error)
- func (o *OpenTelemetry) StartSpan(ctx context.Context, name string, attrs []attribute.KeyValue) (context.Context, trace.Span)
- type TelemetryInitializer
- type TracerProvider
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AddAnnotation ¶
AddAnnotation add event to the span of the given ctx.
Types ¶
type Attributes ¶
type MeterProvider ¶
type MeterProvider interface {
InitMeterProvider(ctx context.Context) (*sdkmetric.MeterProvider, error)
}
MeterProvider defines the interface for creating meters.
type OTelConfig ¶
type OTelConfig struct { TracerEndpoint string MetricEndpoint string ServiceName string TraceSampleRatio float64 OTELEnabled bool Database string Instance string HealthCheckEnabled bool HealthCheckEp string ServiceVersion string }
OTelConfig holds configuration for OpenTelemetry.
type OpenTelemetry ¶
type OpenTelemetry struct { Config *OTelConfig TracerProvider *sdktrace.TracerProvider MeterProvider *sdkmetric.MeterProvider Tracer trace.Tracer Meter metric.Meter Logger *zap.Logger // contains filtered or unexported fields }
OpenTelemetry provides methods to setup tracing and metrics.
func NewOpenTelemetry ¶
func NewOpenTelemetry(ctx context.Context, config *OTelConfig, logger *zap.Logger) (*OpenTelemetry, func(context.Context) error, error)
NewOpenTelemetry creates and initializes a new instance of OpenTelemetry, including its Tracer and Meter providers, and returns Tracer and Meter instances.
func (*OpenTelemetry) EndSpan ¶
func (o *OpenTelemetry) EndSpan(span trace.Span)
EndSpan stops the span.
func (*OpenTelemetry) InitMeterProvider ¶
func (o *OpenTelemetry) InitMeterProvider(ctx context.Context, resource *resource.Resource) (*sdkmetric.MeterProvider, error)
InitMeterProvider initializes the MeterProvider for OpenTelemetry. This function sets up a gRPC exporter for metrics data, targeting the configured MetricEndpoint. It returns an initialized MeterProvider or an error if the setup fails. The MeterProvider is responsible for collecting and exporting metrics from your application to an OpenTelemetry Collector or directly to a backend that supports OTLP over gRPC for metrics.
func (*OpenTelemetry) InitTracerProvider ¶
func (o *OpenTelemetry) InitTracerProvider(ctx context.Context, resource *resource.Resource) (*sdktrace.TracerProvider, error)
InitTracerProvider initializes the TracerProvider for OpenTelemetry. This function configures a gRPC exporter for trace data, pointing to the configured TracerEndpoint. It returns an initialized TracerProvider or an error if the initialization fails.
func (*OpenTelemetry) RecordError ¶
func (o *OpenTelemetry) RecordError(span trace.Span, err error)
RecordError records a new error under a span.
func (*OpenTelemetry) RecordLatencyMetric ¶
func (o *OpenTelemetry) RecordLatencyMetric(ctx context.Context, duration time.Time, attrs Attributes)
RecordLatencyMetric adds the latency metric based on provided context, name, duration and attributes.
func (*OpenTelemetry) RecordRequestCountMetric ¶
func (o *OpenTelemetry) RecordRequestCountMetric(ctx context.Context, attrs Attributes)
RecordRequestCountMetric adds the request count based on provided context, name and attributes.
func (*OpenTelemetry) SetError ¶
func (o *OpenTelemetry) SetError(ctx context.Context, err error)
SetError records an error for the span retrieved from the provided context. If OpenTelemetry (OTEL) is not enabled or if the error is nil, the function will return immediately without recording the error. If enabled and an error is present, the error will be recorded and the span status will be set to error with the corresponding error message.
Parameters: - ctx: The context from which the span is retrieved. - err: The error to be recorded and set on the span.
type TelemetryInitializer ¶
type TelemetryInitializer interface {
InitOpenTelemetry(ctx context.Context) (shutdown func(context.Context) error, err error)
}
TelemetryInitializer defines the interface for initializing OpenTelemetry components.
type TracerProvider ¶
type TracerProvider interface {
InitTracerProvider(ctx context.Context) (*sdktrace.TracerProvider, error)
}
TracerProvider defines the interface for creating traces.