otel

package
v1.11.0 Latest Latest
Warning

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

Go to latest
Published: Jul 9, 2026 License: MIT Imports: 8 Imported by: 0

README

OpenTelemetry Package

Home  /  OpenTelemetry Package

 

The otel package provides OpenTelemetry integration for the go-rabbitmq library. It implements the MetricsCollector and Tracer interfaces using OpenTelemetry semantic conventions for messaging systems, enabling production-grade observability for your RabbitMQ applications.

 

Features

  • OpenTelemetry Metrics: Full metrics collection using OpenTelemetry SDK
  • Distributed Tracing: Span creation and context propagation for publish/consume operations
  • Semantic Conventions: Follows OpenTelemetry Messaging Semantic Conventions
  • Connection Metrics: Track connections, reconnections, and connection attempts
  • Publishing Metrics: Monitor publish operations, confirmations, and message sizes
  • Consumption Metrics: Track message consumption, processing, and requeue events
  • Delivery Assurance Metrics: Monitor delivery outcomes and timeouts
  • Health Check Metrics: Track health check operations and durations
  • Error Tracking: Comprehensive error counting by operation type

 

🔝 back to top

 

Installation

go get github.com/cloudresty/go-rabbitmq/otel

 

🔝 back to top

 

Quick Start

Basic OpenTelemetry Integration
package main

import (
    "context"
    "log"

    "github.com/cloudresty/go-rabbitmq"
    rabbitotel "github.com/cloudresty/go-rabbitmq/otel"
    "go.opentelemetry.io/otel"
)

func main() {
    // Get OpenTelemetry meter and tracer from your provider
    meter := otel.Meter("rabbitmq-client")
    tracer := otel.Tracer("rabbitmq-client")

    // Create OpenTelemetry metrics collector
    metrics, err := rabbitotel.NewMetricsCollector(meter)
    if err != nil {
        log.Fatal("Failed to create metrics collector:", err)
    }

    // Create OpenTelemetry tracer wrapper
    otelTracer := rabbitotel.NewTracer(tracer)

    // Create RabbitMQ client with OpenTelemetry observability
    client, err := rabbitmq.NewClient(
        rabbitmq.FromEnv(),
        rabbitmq.WithMetrics(metrics),
        rabbitmq.WithTracer(otelTracer),
    )
    if err != nil {
        log.Fatal("Failed to create client:", err)
    }
    defer client.Close()

    // All publish/consume operations are now traced and metered
    publisher, _ := client.NewPublisher()
    _ = publisher.Publish(context.Background(), "events", "user.created",
        rabbitmq.NewMessage([]byte(`{"user_id": "123"}`)))
}

 

🔝 back to top

 

Metrics Reference

Connection Metrics
Metric Name Type Description
rabbitmq.connections Counter Number of RabbitMQ connections established
rabbitmq.connection.attempts Counter Number of connection attempts
rabbitmq.connection.duration Histogram Duration of connection attempts (seconds)
rabbitmq.reconnections Counter Number of reconnection attempts
Publishing Metrics
Metric Name Type Description
rabbitmq.publish.count Counter Number of messages published
rabbitmq.publish.duration Histogram Duration of publish operations (seconds)
rabbitmq.publish.message.size Histogram Size of published messages (bytes)
rabbitmq.publish.confirmations Counter Number of publish confirmations
rabbitmq.publish.confirmation.duration Histogram Duration waiting for confirmations (seconds)
Delivery Assurance Metrics
Metric Name Type Description
rabbitmq.delivery.outcomes Counter Number of delivery outcomes by type
rabbitmq.delivery.timeouts Counter Number of delivery timeouts
Consumption Metrics
Metric Name Type Description
rabbitmq.consume.count Counter Number of messages consumed
rabbitmq.consume.duration Histogram Duration of consume operations (seconds)
rabbitmq.consume.message.size Histogram Size of consumed messages (bytes)
rabbitmq.messages.received Counter Number of messages received
rabbitmq.messages.processed Counter Number of messages processed
rabbitmq.messages.requeued Counter Number of messages requeued
Health Metrics
Metric Name Type Description
rabbitmq.health.checks Counter Number of health checks
rabbitmq.health.check.duration Histogram Duration of health checks (seconds)
rabbitmq.errors Counter Number of errors by operation

 

🔝 back to top

 

Semantic Conventions

This package follows the OpenTelemetry Semantic Conventions for Messaging. The following attributes are automatically added to spans and metrics:

Attribute Description
messaging.system Always set to "rabbitmq"
messaging.operation Operation type: publish, receive, process
messaging.destination.name Exchange or queue name
messaging.rabbitmq.routing_key RabbitMQ routing key
messaging.message.id Message ID
messaging.message.body.size Message body size in bytes
messaging.consumer.id Consumer identifier

 

🔝 back to top

 

API Reference

For detailed API documentation, see API Reference.

 

🔝 back to top

 

 


Cloudresty

Website  |  LinkedIn  |  BlueSky  |  GitHub  |  Docker Hub

© Cloudresty - All rights reserved

 

Documentation

Overview

Package otel provides OpenTelemetry integration for the go-rabbitmq library. It implements the MetricsCollector and Tracer interfaces using OpenTelemetry semantic conventions for messaging systems.

Usage:

import (
    "github.com/cloudresty/go-rabbitmq"
    "github.com/cloudresty/go-rabbitmq/otel"
    "go.opentelemetry.io/otel"
    "go.opentelemetry.io/otel/metric"
)

// Create OpenTelemetry metrics collector
meter := otel.Meter("rabbitmq-client")
metrics, err := otel.NewMetricsCollector(meter)
if err != nil {
    log.Fatal(err)
}

// Create OpenTelemetry tracer
tracer := otel.NewTracer(otel.Tracer("rabbitmq-client"))

// Use with client
client, err := rabbitmq.NewClient(
    rabbitmq.WithMetrics(metrics),
    rabbitmq.WithTracer(tracer),
)

Index

Constants

View Source
const (
	// Messaging system attributes
	MessagingSystem    = "messaging.system"
	MessagingOperation = "messaging.operation"

	// RabbitMQ specific attributes
	MessagingRabbitMQRoutingKey = "messaging.rabbitmq.routing_key"
	MessagingDestinationName    = "messaging.destination.name"

	// Message attributes
	MessagingMessageID             = "messaging.message.id"
	MessagingMessageBodySize       = "messaging.message.body.size"
	MessagingMessageConversationID = "messaging.message.conversation_id"

	// Consumer attributes
	MessagingConsumerID = "messaging.consumer.id"

	// Operation types
	OperationPublish = "publish"
	OperationReceive = "receive"
	OperationProcess = "process"
)

Semantic convention attribute keys for messaging Based on OpenTelemetry Semantic Conventions for Messaging https://opentelemetry.io/docs/specs/semconv/messaging/

Variables

This section is empty.

Functions

This section is empty.

Types

type MetricsCollector

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

MetricsCollector implements rabbitmq.MetricsCollector using OpenTelemetry metrics.

func NewMetricsCollector

func NewMetricsCollector(meter metric.Meter) (*MetricsCollector, error)

NewMetricsCollector creates a new OpenTelemetry metrics collector. The meter should be obtained from an OpenTelemetry MeterProvider.

func (*MetricsCollector) RecordConnection

func (m *MetricsCollector) RecordConnection(connectionName string)

RecordConnection records a new connection

func (*MetricsCollector) RecordConnectionAttempt

func (m *MetricsCollector) RecordConnectionAttempt(success bool, duration time.Duration)

RecordConnectionAttempt records a connection attempt

func (*MetricsCollector) RecordConsume

func (m *MetricsCollector) RecordConsume(queue string, messageSize int, duration time.Duration)

RecordConsume records a consume operation

func (*MetricsCollector) RecordDeliveryOutcome

func (m *MetricsCollector) RecordDeliveryOutcome(outcome rabbitmq.DeliveryOutcome, duration time.Duration)

RecordDeliveryOutcome records a delivery assurance outcome

func (*MetricsCollector) RecordDeliveryTimeout

func (m *MetricsCollector) RecordDeliveryTimeout(messageID string)

RecordDeliveryTimeout records a delivery timeout

func (*MetricsCollector) RecordError

func (m *MetricsCollector) RecordError(operation string, err error)

RecordError records an error

func (*MetricsCollector) RecordHealthCheck

func (m *MetricsCollector) RecordHealthCheck(success bool, duration time.Duration)

RecordHealthCheck records a health check

func (*MetricsCollector) RecordMessageProcessed

func (m *MetricsCollector) RecordMessageProcessed(queue string, success bool, duration time.Duration)

RecordMessageProcessed records a message processed event

func (*MetricsCollector) RecordMessageReceived

func (m *MetricsCollector) RecordMessageReceived(queue string)

RecordMessageReceived records a message received event

func (*MetricsCollector) RecordMessageRequeued

func (m *MetricsCollector) RecordMessageRequeued(queue string)

RecordMessageRequeued records a message requeue event

func (*MetricsCollector) RecordPublish

func (m *MetricsCollector) RecordPublish(exchange, routingKey string, messageSize int, duration time.Duration)

RecordPublish records a publish operation

func (*MetricsCollector) RecordPublishConfirmation

func (m *MetricsCollector) RecordPublishConfirmation(success bool, duration time.Duration)

RecordPublishConfirmation records a publish confirmation

func (*MetricsCollector) RecordReconnection

func (m *MetricsCollector) RecordReconnection(attempt int)

RecordReconnection records a reconnection attempt

type Span

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

Span wraps an OpenTelemetry span to implement rabbitmq.Span

func (*Span) End

func (s *Span) End()

End ends the span

func (*Span) SetAttribute

func (s *Span) SetAttribute(key string, value any)

SetAttribute sets an attribute on the span

func (*Span) SetStatus

func (s *Span) SetStatus(code rabbitmq.SpanStatusCode, description string)

SetStatus sets the status of the span

type Tracer

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

Tracer implements rabbitmq.Tracer using OpenTelemetry tracing.

func NewTracer

func NewTracer(tracer trace.Tracer) *Tracer

NewTracer creates a new OpenTelemetry tracer wrapper. The tracer should be obtained from an OpenTelemetry TracerProvider.

func (*Tracer) StartSpan

func (t *Tracer) StartSpan(ctx context.Context, operation string) (context.Context, rabbitmq.Span)

StartSpan starts a new span for the given operation

Jump to

Keyboard shortcuts

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