Skip to content

Commit 37ea80d

Browse files
slashmofabianfett
authored andcommitted
Add static name to Valkey commands
Signed-off-by: Moritz Lang <16192401+slashmo@users.noreply.github.com>
1 parent ff8e1ce commit 37ea80d

File tree

1 file changed

+17
-9
lines changed

1 file changed

+17
-9
lines changed

Sources/Valkey/Connection/ValkeyConnection.swift

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ import Network
2323
import NIOTransportServices
2424
#endif
2525

26+
#if DistributedTracingSupport
27+
import Tracing
28+
#endif
29+
2630
/// A single connection to a Valkey database.
2731
@available(valkeySwift 1.0, *)
2832
public final actor ValkeyConnection: ValkeyClientProtocol, Sendable {
@@ -159,16 +163,20 @@ public final actor ValkeyConnection: ValkeyClientProtocol, Sendable {
159163

160164
@inlinable
161165
func _execute<Command: ValkeyCommand>(command: Command) async throws -> RESPToken {
162-
let requestID = Self.requestIDGenerator.next()
163-
return try await withTaskCancellationHandler {
164-
if Task.isCancelled {
165-
throw ValkeyClientError(.cancelled)
166-
}
167-
return try await withCheckedThrowingContinuation { continuation in
168-
self.channelHandler.write(command: command, continuation: continuation, requestID: requestID)
166+
try await withSpan(Command.name, ofKind: .client) { span in
167+
span.attributes["db.system.name"] = "valkey"
168+
169+
let requestID = Self.requestIDGenerator.next()
170+
return try await withTaskCancellationHandler {
171+
if Task.isCancelled {
172+
throw ValkeyClientError(.cancelled)
173+
}
174+
return try await withCheckedThrowingContinuation { continuation in
175+
self.channelHandler.write(command: command, continuation: continuation, requestID: requestID)
176+
}
177+
} onCancel: {
178+
self.cancel(requestID: requestID)
169179
}
170-
} onCancel: {
171-
self.cancel(requestID: requestID)
172180
}
173181
}
174182

0 commit comments

Comments
 (0)