@@ -30,17 +30,20 @@ class Bucket
3030 alias inspect to_s
3131
3232 # @param [Couchbase::Backend] backend
33- def initialize ( backend , name )
33+ #
34+ # @api private
35+ def initialize ( backend , name , observability )
3436 backend . open_bucket ( name , true )
3537 @backend = backend
3638 @name = name
39+ @observability = observability
3740 end
3841
3942 # Get default scope
4043 #
4144 # @return [Scope]
4245 def default_scope
43- Scope . new ( @backend , @name , "_default" )
46+ Scope . new ( @backend , @name , "_default" , @observability )
4447 end
4548
4649 # Get a named scope
@@ -49,7 +52,7 @@ def default_scope
4952 #
5053 # @return [Scope]
5154 def scope ( scope_name )
52- Scope . new ( @backend , @name , scope_name )
55+ Scope . new ( @backend , @name , scope_name , @observability )
5356 end
5457
5558 # Opens the named collection in the default scope of the bucket
@@ -65,7 +68,7 @@ def collection(collection_name)
6568 #
6669 # @return [Collection]
6770 def default_collection
68- Collection . new ( @backend , @name , "_default" , "_default" )
71+ Collection . new ( @backend , @name , "_default" , "_default" , @observability )
6972 end
7073
7174 # Performs query to view index.
@@ -83,30 +86,32 @@ def default_collection
8386 #
8487 # @return [ViewResult]
8588 def view_query ( design_document_name , view_name , options = Options ::View ::DEFAULT )
86- resp = @backend . document_view ( @name , design_document_name , view_name , options . namespace , options . to_backend )
87- ViewResult . new do |res |
88- res . meta_data = ViewMetaData . new do |meta |
89- meta . total_rows = resp [ :meta ] [ :total_rows ]
90- meta . debug_info = resp [ :meta ] [ :debug_info ]
91- end
92- res . rows = resp [ :rows ] . map do |entry |
93- ViewRow . new do |row |
94- row . id = entry [ :id ] if entry . key? ( :id )
95- row . key = JSON . parse ( entry [ :key ] )
96- row . value = JSON . parse ( entry [ :value ] )
89+ @observability . record_operation ( Observability ::OP_VIEW_QUERY , opts . parent_span , self , :views ) do |_obs_handler |
90+ resp = @backend . document_view ( @name , design_document_name , view_name , options . namespace , options . to_backend )
91+ ViewResult . new do |res |
92+ res . meta_data = ViewMetaData . new do |meta |
93+ meta . total_rows = resp [ :meta ] [ :total_rows ]
94+ meta . debug_info = resp [ :meta ] [ :debug_info ]
95+ end
96+ res . rows = resp [ :rows ] . map do |entry |
97+ ViewRow . new do |row |
98+ row . id = entry [ :id ] if entry . key? ( :id )
99+ row . key = JSON . parse ( entry [ :key ] )
100+ row . value = JSON . parse ( entry [ :value ] )
101+ end
97102 end
98103 end
99104 end
100105 end
101106
102107 # @return [Management::CollectionManager]
103108 def collections
104- Management ::CollectionManager . new ( @backend , @name )
109+ Management ::CollectionManager . new ( @backend , @name , @observability )
105110 end
106111
107112 # @return [Management::ViewIndexManager]
108113 def view_indexes
109- Management ::ViewIndexManager . new ( @backend , @name )
114+ Management ::ViewIndexManager . new ( @backend , @name , @observability )
110115 end
111116
112117 # Performs application-level ping requests against services in the couchbase cluster
@@ -115,20 +120,22 @@ def view_indexes
115120 #
116121 # @return [PingResult]
117122 def ping ( options = Options ::Ping ::DEFAULT )
118- resp = @backend . ping ( @name , options . to_backend )
119- PingResult . new do |res |
120- res . version = resp [ :version ]
121- res . id = resp [ :id ]
122- res . sdk = resp [ :sdk ]
123- resp [ :services ] . each do |type , svcs |
124- res . services [ type ] = svcs . map do |svc |
125- PingResult ::ServiceInfo . new do |info |
126- info . id = svc [ :id ]
127- info . state = svc [ :state ]
128- info . latency = svc [ :latency ]
129- info . remote = svc [ :remote ]
130- info . local = svc [ :local ]
131- info . error = svc [ :error ]
123+ @observability . record_operation ( Observability ::OP_PING , options . parent_span , self ) do |_obs_handler |
124+ resp = @backend . ping ( @name , options . to_backend )
125+ PingResult . new do |res |
126+ res . version = resp [ :version ]
127+ res . id = resp [ :id ]
128+ res . sdk = resp [ :sdk ]
129+ resp [ :services ] . each do |type , svcs |
130+ res . services [ type ] = svcs . map do |svc |
131+ PingResult ::ServiceInfo . new do |info |
132+ info . id = svc [ :id ]
133+ info . state = svc [ :state ]
134+ info . latency = svc [ :latency ]
135+ info . remote = svc [ :remote ]
136+ info . local = svc [ :local ]
137+ info . error = svc [ :error ]
138+ end
132139 end
133140 end
134141 end
0 commit comments