Skip to content

Commit 48cef92

Browse files
committed
Otel test: Add check for cluster label support
1 parent ac2f4fe commit 48cef92

File tree

1 file changed

+47
-28
lines changed

1 file changed

+47
-28
lines changed

test/opentelemetry_test.rb

Lines changed: 47 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -100,48 +100,60 @@ def test_opentelemetry_tracer
100100
parent_span_id: nil,
101101
)
102102

103+
expected_attributes = {
104+
"db.system.name" => "couchbase",
105+
"db.operation.name" => "upsert",
106+
"db.namespace" => @bucket.name,
107+
"couchbase.scope.name" => "_default",
108+
"couchbase.collection.name" => "_default",
109+
"couchbase.retries" => nil,
110+
}
111+
if env.server_version.supports_cluster_labels?
112+
expected_attributes["couchbase.cluster.name"] = env.cluster_name
113+
expected_attributes["couchbase.cluster.uuid"] = env.cluster_uuid
114+
end
115+
103116
assert_otel_span(
104117
spans[1],
105118
"upsert",
106-
attributes: {
107-
"db.system.name" => "couchbase",
108-
"couchbase.cluster.name" => env.cluster_name,
109-
"couchbase.cluster.uuid" => env.cluster_uuid,
110-
"db.operation.name" => "upsert",
111-
"db.namespace" => @bucket.name,
112-
"couchbase.scope.name" => "_default",
113-
"couchbase.collection.name" => "_default",
114-
"couchbase.retries" => nil,
115-
},
119+
attributes: expected_attributes,
116120
parent_span_id: spans[0].span_id,
117121
status_code: ::OpenTelemetry::Trace::Status::OK,
118122
)
119123

124+
expected_attributes = {
125+
"db.system.name" => "couchbase",
126+
}
127+
if env.server_version.supports_cluster_labels?
128+
expected_attributes["couchbase.cluster.name"] = env.cluster_name
129+
expected_attributes["couchbase.cluster.uuid"] = env.cluster_uuid
130+
end
131+
120132
assert_otel_span(
121133
spans[2],
122134
"request_encoding",
123-
attributes: {
124-
"db.system.name" => "couchbase",
125-
"couchbase.cluster.name" => env.cluster_name,
126-
"couchbase.cluster.uuid" => env.cluster_uuid,
127-
},
135+
attributes: expected_attributes,
128136
parent_span_id: spans[1].span_id,
129137
)
130138

139+
expected_attributes = {
140+
"db.system.name" => "couchbase",
141+
"network.peer.address" => nil,
142+
"network.peer.port" => nil,
143+
"network.transport" => "tcp",
144+
"server.address" => nil,
145+
"server.port" => nil,
146+
"couchbase.local_id" => nil,
147+
}
148+
if env.server_version.supports_cluster_labels?
149+
expected_attributes["couchbase.cluster.name"] = env.cluster_name
150+
expected_attributes["couchbase.cluster.uuid"] = env.cluster_uuid
151+
end
152+
131153
assert_otel_span(
132154
spans[3],
133155
"dispatch_to_server",
134-
attributes: {
135-
"db.system.name" => "couchbase",
136-
"couchbase.cluster.name" => env.cluster_name,
137-
"couchbase.cluster.uuid" => env.cluster_uuid,
138-
"network.peer.address" => nil,
139-
"network.peer.port" => nil,
140-
"network.transport" => "tcp",
141-
"server.address" => nil,
142-
"server.port" => nil,
143-
"couchbase.local_id" => nil,
144-
},
156+
attributes: expected_attributes,
145157
parent_span_id: spans[1].span_id,
146158
)
147159
end
@@ -167,8 +179,15 @@ def test_opentelemetry_meter
167179

168180
snapshot.data_points.each_with_index do |p, idx|
169181
assert_equal "couchbase", p.attributes["db.system.name"]
170-
assert_equal env.cluster_name, p.attributes["couchbase.cluster.name"]
171-
assert_equal env.cluster_uuid, p.attributes["couchbase.cluster.uuid"]
182+
183+
if env.server_version.supports_cluster_labels?
184+
assert_equal env.cluster_name, p.attributes["couchbase.cluster.name"]
185+
assert_equal env.cluster_uuid, p.attributes["couchbase.cluster.uuid"]
186+
else
187+
assert_nil p.attributes["couchbase.cluster.name"]
188+
assert_nil p.attributes["couchbase.cluster.uuid"]
189+
end
190+
172191
assert_equal env.bucket, p.attributes["db.namespace"]
173192
assert_equal "_default", p.attributes["couchbase.scope.name"]
174193
assert_equal "_default", p.attributes["couchbase.collection.name"]

0 commit comments

Comments
 (0)