MCPcopy
hub / github.com/redis/go-redis / RecordPubSubMessage

Method RecordPubSubMessage

extra/redisotel-native/metrics.go:744–786  ·  view source on GitHub ↗

RecordPubSubMessage records redis.client.pubsub.messages metric

(
	ctx context.Context,
	cn redis.ConnInfo,
	direction string,
	channel string,
	sharded bool,
)

Source from the content-addressed store, hash-verified

742
743// RecordPubSubMessage records redis.client.pubsub.messages metric
744func (r *metricsRecorder) RecordPubSubMessage(
745 ctx context.Context,
746 cn redis.ConnInfo,
747 direction string,
748 channel string,
749 sharded bool,
750) {
751 if r.pubsubMessages == nil {
752 return
753 }
754
755 // Extract server address and peer address from connection
756 serverAddr, serverPort := extractServerInfo(cn)
757 peerAddr, peerPort := serverAddr, serverPort
758
759 // Build attributes
760 attrs := []attribute.KeyValue{
761 attribute.String(AttrDBSystemName, DBSystemRedis),
762 attribute.String(AttrServerAddress, serverAddr),
763 attribute.String(AttrRedisClientPubSubDirection, direction), // "sent" or "received"
764 attribute.Bool(AttrRedisClientPubSubSharded, sharded),
765 getLibraryVersionAttr(),
766 }
767
768 // Add channel name if not hidden for cardinality reduction
769 if !r.cfg.hidePubSubChannelNames && channel != "" {
770 attrs = append(attrs, attribute.String(AttrRedisClientPubSubChannel, channel))
771 }
772
773 // Add server.port if not default
774 attrs = addServerPortIfNonDefault(attrs, serverPort)
775
776 // Add peer info
777 if peerAddr != "" {
778 attrs = append(attrs, attribute.String(AttrNetworkPeerAddress, peerAddr))
779 if peerPort != "" {
780 attrs = append(attrs, attribute.String(AttrNetworkPeerPort, peerPort))
781 }
782 }
783
784 // Record the counter
785 r.pubsubMessages.Add(ctx, 1, metric.WithAttributes(attrs...))
786}
787
788// RecordStreamLag records redis.client.stream.lag metric
789func (r *metricsRecorder) RecordStreamLag(

Callers

nothing calls this directly

Calls 6

extractServerInfoFunction · 0.85
getLibraryVersionAttrFunction · 0.85
StringMethod · 0.65
AddMethod · 0.65
BoolMethod · 0.45

Tested by

no test coverage detected