Skip to content

Commit 51eb11a

Browse files
more specs
1 parent 5310ffb commit 51eb11a

File tree

4 files changed

+68
-10
lines changed

4 files changed

+68
-10
lines changed

lib/mongo/client.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -984,7 +984,10 @@ def list_databases(filter = {}, name_only = false, opts = {})
984984
cmd[:nameOnly] = !!name_only
985985
cmd[:filter] = filter unless filter.empty?
986986
cmd[:authorizedDatabases] = true if opts[:authorized_databases]
987-
use(Database::ADMIN).database.read_command(cmd, opts).first[Database::DATABASES]
987+
use(Database::ADMIN)
988+
.database
989+
.read_command(cmd, opts.merge(op_name: 'listDatabases'))
990+
.first[Database::DATABASES]
988991
end
989992

990993
# Returns a list of Mongo::Database objects.

lib/mongo/database.rb

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -268,10 +268,12 @@ def command(operation, opts = {})
268268
# @option opts :session [ Session ] The session to use for this command.
269269
# @option opts [ Object ] :comment A user-provided
270270
# comment to attach to this command.
271-
# @option options [ Integer ] :timeout_ms The operation timeout in milliseconds.
271+
# @option opts [ Integer ] :timeout_ms The operation timeout in milliseconds.
272272
# Must be a non-negative integer. An explicit value of 0 means infinite.
273273
# The default value is unset which means the value is inherited from
274274
# the database or the client.
275+
# @option opts :op_name [ String | nil ] The name of the operation for
276+
# tracing purposes.
275277
#
276278
# @return [ Hash ] The result of the command execution.
277279
# @api private
@@ -291,14 +293,18 @@ def read_command(operation, opts = {})
291293
session: session,
292294
operation_timeouts: operation_timeouts(opts)
293295
)
294-
read_with_retry(session, preference, context) do |server|
295-
Operation::Command.new(
296-
selector: operation.dup,
297-
db_name: name,
298-
read: preference,
299-
session: session,
300-
comment: opts[:comment],
301-
).execute(server, context: context)
296+
operation = Operation::Command.new(
297+
selector: operation.dup,
298+
db_name: name,
299+
read: preference,
300+
session: session,
301+
comment: opts[:comment],
302+
)
303+
op_name = opts[:op_name] || 'command'
304+
tracer.trace_operation(operation, context, op_name: op_name) do
305+
read_with_retry(session, preference, context) do |server|
306+
operation.execute(server, context: context)
307+
end
302308
end
303309
end
304310
end

lib/mongo/tracing/open_telemetry/operation_tracer.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,8 @@ def collection_name(operation)
111111
end
112112

113113
def operation_span_name(operation, op_name = nil)
114+
return 'listDatabases' if op_name == 'listDatabases'
115+
114116
coll_name = collection_name(operation)
115117
if coll_name && !coll_name.empty?
116118
"#{operation_name(operation, op_name)} #{operation.db_name}.#{coll_name}"
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
description: operation list databases
2+
schemaVersion: '1.26'
3+
createEntities:
4+
- client:
5+
id: &client0 client0
6+
useMultipleMongoses: false
7+
observeTracingMessages:
8+
enableCommandPayload: true
9+
tests:
10+
- description: list databases
11+
operations:
12+
- object: *client0
13+
name: listDatabases
14+
15+
expectTracingMessages:
16+
- client: *client0
17+
ignoreExtraSpans: false
18+
spans:
19+
- name: listDatabases
20+
tags:
21+
db.system: mongodb
22+
db.namespace: admin
23+
db.operation.name: listDatabases
24+
db.operation.summary: listDatabases admin
25+
nested:
26+
- name: listDatabases admin
27+
tags:
28+
db.system: mongodb
29+
db.namespace: admin
30+
db.command.name: listDatabases
31+
network.transport: tcp
32+
db.mongodb.cursor_id: { $$exists: false }
33+
db.response.status_code: { $$exists: false }
34+
exception.message: { $$exists: false }
35+
exception.type: { $$exists: false }
36+
exception.stacktrace: { $$exists: false }
37+
server.address: { $$type: string }
38+
server.port: { $$type: ['int', 'long'] }
39+
db.query.summary: listDatabases
40+
db.query.text:
41+
$$matchAsDocument:
42+
$$matchAsRoot:
43+
listDatabases: 1
44+
db.mongodb.server_connection_id:
45+
$$type: [ 'int', 'long' ]
46+
db.mongodb.driver_connection_id:
47+
$$type: [ 'int', 'long' ]

0 commit comments

Comments
 (0)