You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
39 lines
1.0 KiB
Go
39 lines
1.0 KiB
Go
3 years ago
|
package opentelemetry
|
||
|
|
||
|
import (
|
||
|
"context"
|
||
|
|
||
|
"go.opentelemetry.io/otel/attribute"
|
||
|
"go.opentelemetry.io/otel/trace"
|
||
|
"google.golang.org/protobuf/proto"
|
||
|
)
|
||
|
|
||
3 years ago
|
const messageEvent = "message"
|
||
|
|
||
3 years ago
|
var (
|
||
3 years ago
|
// MessageSent is the type of sent messages.
|
||
|
MessageSent = messageType(RPCMessageTypeSent)
|
||
|
// MessageReceived is the type of received messages.
|
||
3 years ago
|
MessageReceived = messageType(RPCMessageTypeReceived)
|
||
|
)
|
||
|
|
||
|
type messageType attribute.KeyValue
|
||
|
|
||
|
// Event adds an event of the messageType to the span associated with the
|
||
|
// passed context with id and size (if message is a proto message).
|
||
|
func (m messageType) Event(ctx context.Context, id int, message interface{}) {
|
||
|
span := trace.SpanFromContext(ctx)
|
||
|
if p, ok := message.(proto.Message); ok {
|
||
3 years ago
|
span.AddEvent(messageEvent, trace.WithAttributes(
|
||
3 years ago
|
attribute.KeyValue(m),
|
||
|
RPCMessageIDKey.Int(id),
|
||
|
RPCMessageUncompressedSizeKey.Int(proto.Size(p)),
|
||
|
))
|
||
|
} else {
|
||
3 years ago
|
span.AddEvent(messageEvent, trace.WithAttributes(
|
||
3 years ago
|
attribute.KeyValue(m),
|
||
|
RPCMessageIDKey.Int(id),
|
||
|
))
|
||
|
}
|
||
|
}
|