mirror of
https://github.com/mainflux/mainflux.git
synced 2025-04-26 13:48:53 +08:00

* Initial Commit: Sync Env Veriables With Docker Deployment Signed-off-by: rodneyosodo <blackd0t@protonmail.com> * Sync Env Vars With Master Signed-off-by: rodneyosodo <blackd0t@protonmail.com> * Initial Commit: Add Tags to Database and Message Bus Signed-off-by: rodneyosodo <blackd0t@protonmail.com> * Format Address Well Signed-off-by: rodneyosodo <blackd0t@protonmail.com> * Propagate Context Signed-off-by: rodneyosodo <blackd0t@protonmail.com> * Update PostgresSQL spans Signed-off-by: rodneyosodo <blackd0t@protonmail.com> * Update Message Bus Spans Signed-off-by: rodneyosodo <blackd0t@protonmail.com> * Add Tracing To MQTT Adapter Signed-off-by: rodneyosodo <blackd0t@protonmail.com> * Add Span Tags to HTTP Signed-off-by: rodneyosodo <blackd0t@protonmail.com> * Combine Tracing and PubSub Signed-off-by: rodneyosodo <blackd0t@protonmail.com> * Fix Error After Rebase Signed-off-by: rodneyosodo <blackd0t@protonmail.com> * Reorder Server Config Signed-off-by: rodneyosodo <blackd0t@protonmail.com> * Seperate Tracing Signed-off-by: rodneyosodo <blackd0t@protonmail.com> * shorten span names Signed-off-by: rodneyosodo <blackd0t@protonmail.com> * Fix Issue After Rebase Signed-off-by: rodneyosodo <blackd0t@protonmail.com> --------- Signed-off-by: rodneyosodo <blackd0t@protonmail.com>
55 lines
1.5 KiB
Go
55 lines
1.5 KiB
Go
// Copyright (c) Mainflux
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
package tracing
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/mainflux/mainflux/internal/server"
|
|
"github.com/mainflux/mainflux/pkg/messaging"
|
|
"github.com/mainflux/mainflux/pkg/messaging/tracing"
|
|
"go.opentelemetry.io/otel/attribute"
|
|
"go.opentelemetry.io/otel/trace"
|
|
)
|
|
|
|
// Traced operations.
|
|
const publishOP = "publish"
|
|
|
|
var defaultAttributes = []attribute.KeyValue{
|
|
attribute.String("messaging.system", "rabbitmq"),
|
|
attribute.String("network.protocol.name", "amqp"),
|
|
attribute.String("network.protocol.version", "3.9.20"),
|
|
attribute.String("messaging.rabbitmq.destination.routing_key", "mainflux"),
|
|
}
|
|
|
|
var _ messaging.Publisher = (*publisherMiddleware)(nil)
|
|
|
|
type publisherMiddleware struct {
|
|
publisher messaging.Publisher
|
|
tracer trace.Tracer
|
|
host server.Config
|
|
}
|
|
|
|
func NewPublisher(config server.Config, tracer trace.Tracer, publisher messaging.Publisher) messaging.Publisher {
|
|
pub := &publisherMiddleware{
|
|
publisher: publisher,
|
|
tracer: tracer,
|
|
host: config,
|
|
}
|
|
|
|
return pub
|
|
}
|
|
|
|
func (pm *publisherMiddleware) Publish(ctx context.Context, topic string, msg *messaging.Message) error {
|
|
ctx, span := tracing.CreateSpan(ctx, publishOP, msg.Publisher, topic, msg.Subtopic, len(msg.Payload), pm.host, trace.SpanKindClient, pm.tracer)
|
|
defer span.End()
|
|
|
|
span.SetAttributes(defaultAttributes...)
|
|
|
|
return pm.publisher.Publish(ctx, topic, msg)
|
|
}
|
|
|
|
func (pm *publisherMiddleware) Close() error {
|
|
return pm.publisher.Close()
|
|
}
|