couchbase-opentelemetry 3.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 6e1312cc5095ec60121ba6d28d407d7600aa8aa8a441f446303ea5e5d176ca88
4
+ data.tar.gz: 4542b7625cc80c34bfd4fcf085f11e0459396c42bf52c8de747b2aa83786d2f0
5
+ SHA512:
6
+ metadata.gz: 7c4a114d769450c05824c3a3b7c3677c54d621ed6ea93a0219c11f0b1f107e6d62aa29cce49dbfc21e2d0e9e16e596817280048b57c8ec0c91bcb230bd441a1d
7
+ data.tar.gz: 294181eb4b749822f1ea5b31128763052461afbbbd62881883c839895ffd4e2f356300eff4eecde8af6db4ba9007025f1b567f9059af79073fd0290ff7208aee
@@ -0,0 +1,82 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright 2026-Present Couchbase, Inc.
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+
17
+ require "couchbase/metrics/meter"
18
+ require "couchbase/errors"
19
+ require_relative "value_recorder"
20
+
21
+ require "opentelemetry-metrics-api"
22
+
23
+ module Couchbase
24
+ module OpenTelemetry
25
+ # @couchbase.stability
26
+ # **Uncommitted:** This API may change in the future, as Metrics in OpenTelemetry Ruby are currently in development.
27
+ #
28
+ # See the {https://opentelemetry.io/docs/languages/ruby/#status-and-releases OpenTelemetry Ruby documentation} for more information.
29
+ class Meter < ::Couchbase::Metrics::Meter
30
+ # Initializes a Couchbase OpenTelemetry Meter
31
+ #
32
+ # @param [::OpenTelemetry::Metrics::MeterProvider] meter_provider The OpenTelemetry meter provider
33
+ #
34
+ # @raise [Couchbase::Error::MeterError] if the meter cannot be created for any reason
35
+ #
36
+ # @example Initializing a Couchbase OpenTelemetry Meter with an OTLP Exporter
37
+ # require "opentelemetry-metrics-sdk"
38
+ #
39
+ # # Initialize a meter provider
40
+ # meter_provider = ::OpenTelemetry::SDK::Metrics::MeterProvider.new
41
+ # meter_provider.add_metric_reader(
42
+ # ::OpenTelemetry::SDK::Metrics::Export::PeriodicMetricReader.new(
43
+ # exporter: ::OpenTelemetry::Exporter::OTLP::Metrics::MetricsExporter.new(
44
+ # endpoint: "https://<hostname>:<port>/v1/metrics"
45
+ # )
46
+ # )
47
+ # )
48
+ # # Initialize the Couchbase OpenTelemetry Meter
49
+ # meter = Couchbase::OpenTelemetry::Meter.new(meter_provider)
50
+ #
51
+ # # Set the meter in the cluster options
52
+ # options = Couchbase::Options::Cluster.new(
53
+ # authenticator: Couchbase::PasswordAuthenticator.new("Administrator", "password")
54
+ # meter: meter
55
+ # )
56
+ #
57
+ # @see https://www.rubydoc.info/gems/opentelemetry-metrics-sdk/OpenTelemetry/SDK/Metrics/MeterProvider
58
+ # <tt>opentelemetry-metrics-sdk</tt> API Reference
59
+ def initialize(meter_provider)
60
+ super()
61
+ @histogram_cache = Concurrent::Map.new
62
+ begin
63
+ @wrapped = meter_provider.meter("com.couchbase.client/ruby")
64
+ rescue StandardError => e
65
+ raise Error::MeterError.new("Failed to create OpenTelemetry Meter: #{e.message}", nil, e)
66
+ end
67
+ end
68
+
69
+ def value_recorder(name, tags)
70
+ unit = tags.delete("__unit")
71
+
72
+ otel_histogram = @histogram_cache.compute_if_absent(name) do
73
+ @wrapped.create_histogram(name, unit: unit)
74
+ end
75
+
76
+ ValueRecorder.new(otel_histogram, tags, unit: unit)
77
+ rescue StandardError => e
78
+ raise Error::MeterError.new("Failed to create OpenTelemetry Histogram: #{e.message}", nil, e)
79
+ end
80
+ end
81
+ end
82
+ end
@@ -0,0 +1,49 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright 2026-Present Couchbase, Inc.
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+
17
+ require "couchbase/tracing/request_span"
18
+
19
+ require "opentelemetry-api"
20
+
21
+ module Couchbase
22
+ module OpenTelemetry
23
+ class RequestSpan < ::Couchbase::Tracing::RequestSpan
24
+ def initialize(span)
25
+ super()
26
+
27
+ @wrapped = span
28
+ end
29
+
30
+ def set_attribute(key, value)
31
+ @wrapped.set_attribute(key, value)
32
+ end
33
+
34
+ def status=(status_code)
35
+ @wrapped.status = if status_code == :ok
36
+ ::OpenTelemetry::Trace::Status.ok
37
+ elsif status_code == :error
38
+ ::OpenTelemetry::Trace::Status.error
39
+ else
40
+ ::OpenTelemetry::Trace::Status.unset
41
+ end
42
+ end
43
+
44
+ def finish(end_timestamp: nil)
45
+ @wrapped.finish(end_timestamp: end_timestamp)
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,79 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright 2026-Present Couchbase, Inc.
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+
17
+ require "opentelemetry-api"
18
+
19
+ require "couchbase/tracing/request_tracer"
20
+ require "couchbase/errors"
21
+ require_relative "request_span"
22
+
23
+ module Couchbase
24
+ module OpenTelemetry
25
+ class RequestTracer < ::Couchbase::Tracing::RequestTracer
26
+ # Initializes a Couchbase OpenTelemetry Request Tracer
27
+ #
28
+ # @param [::OpenTelemetry::Trace::TracerProvider] tracer_provider The OpenTelemetry tracer provider
29
+ #
30
+ # @raise [Couchbase::Error::TracerError] if the tracer cannot be created for any reason
31
+ #
32
+ # @example Initializing a Couchbase OpenTelemetry Request Tracer with an OTLP Exporter
33
+ # require "opentelemetry-sdk"
34
+ #
35
+ # # Initialize a tracer provider
36
+ # tracer_provider = ::OpenTelemetry::SDK::Trace::TracerProvider.new
37
+ # tracer_provider.add_span_processor(
38
+ # ::OpenTelemetry::SDK::Trace::Export::BatchSpanProcessor.new(
39
+ # exporter: ::OpenTelemetry::Exporter::OTLP::Exporter.new(
40
+ # endpoint: "https://<hostname>:<port>/v1/traces"
41
+ # )
42
+ # )
43
+ # )
44
+ # # Initialize the Couchbase OpenTelemetry Request Tracer
45
+ # tracer = Couchbase::OpenTelemetry::RequestTracer.new(tracer_provider)
46
+ #
47
+ # # Set the tracer in the cluster options
48
+ # options = Couchbase::Options::Cluster.new(
49
+ # authenticator: Couchbase::PasswordAuthenticator.new("Administrator", "password")
50
+ # tracer: tracer
51
+ # )
52
+ #
53
+ # @see https://www.rubydoc.info/gems/opentelemetry-sdk/OpenTelemetry/SDK/Trace/TracerProvider
54
+ # <tt>opentelemetry-sdk</tt> API Reference
55
+ def initialize(tracer_provider)
56
+ super()
57
+ begin
58
+ @wrapped = tracer_provider.tracer("com.couchbase.client/ruby")
59
+ rescue StandardError => e
60
+ raise Error::TracerError.new("Failed to create OpenTelemetry tracer: #{e.message}", nil, e)
61
+ end
62
+ end
63
+
64
+ def request_span(name, parent: nil, start_timestamp: nil)
65
+ parent_context = parent.nil? ? nil : ::OpenTelemetry::Trace.context_with_span(parent.instance_variable_get(:@wrapped))
66
+ RequestSpan.new(
67
+ @wrapped.start_span(
68
+ name,
69
+ with_parent: parent_context,
70
+ start_timestamp: start_timestamp,
71
+ kind: :client,
72
+ ),
73
+ )
74
+ rescue StandardError => e
75
+ raise Error::TracerError.new("Failed to create OpenTelemetry span: #{e.message}", nil, e)
76
+ end
77
+ end
78
+ end
79
+ end
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright 2026-Present Couchbase, Inc.
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+
17
+ require "couchbase/metrics/value_recorder"
18
+
19
+ module Couchbase
20
+ module OpenTelemetry
21
+ class ValueRecorder < ::Couchbase::Metrics::ValueRecorder
22
+ def initialize(recorder, tags, unit: nil)
23
+ super()
24
+ @wrapped = recorder
25
+ @tags = tags
26
+ @unit = unit
27
+ end
28
+
29
+ def record_value(value)
30
+ value =
31
+ case @unit
32
+ when "s"
33
+ value / 1_000_000.0
34
+ else
35
+ value
36
+ end
37
+
38
+ @wrapped.record(value, attributes: @tags)
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright 2026-Present Couchbase, Inc.
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+
17
+ module Couchbase
18
+ module OpenTelemetry
19
+ # Version of the Couchbase OpenTelemetry integration gem
20
+ VERSION = "3.8.0"
21
+ end
22
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright 2026-Present Couchbase, Inc.
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+
17
+ require_relative "opentelemetry/request_tracer"
18
+ require_relative "opentelemetry/meter"
19
+ require_relative "opentelemetry/version"
metadata ADDED
@@ -0,0 +1,99 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: couchbase-opentelemetry
3
+ version: !ruby/object:Gem::Version
4
+ version: 3.8.0
5
+ platform: ruby
6
+ authors:
7
+ - Sergey Avseyev
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2026-03-31 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: concurrent-ruby
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: opentelemetry-api
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.7'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.7'
41
+ - !ruby/object:Gem::Dependency
42
+ name: opentelemetry-metrics-api
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 0.4.0
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 0.4.0
55
+ description: OpenTelemetry integration for the Couchbase Ruby Client
56
+ email:
57
+ - sergey.avseyev@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - lib/couchbase/opentelemetry.rb
63
+ - lib/couchbase/opentelemetry/meter.rb
64
+ - lib/couchbase/opentelemetry/request_span.rb
65
+ - lib/couchbase/opentelemetry/request_tracer.rb
66
+ - lib/couchbase/opentelemetry/value_recorder.rb
67
+ - lib/couchbase/opentelemetry/version.rb
68
+ homepage: https://www.couchbase.com
69
+ licenses:
70
+ - Apache-2.0
71
+ metadata:
72
+ homepage_uri: https://docs.couchbase.com/ruby-sdk/current/hello-world/start-using-sdk.html
73
+ bug_tracker_uri: https://jira.issues.couchbase.com/browse/RCBC
74
+ mailing_list_uri: https://www.couchbase.com/forums/c/ruby-sdk
75
+ source_code_uri: https://github.com/couchbase/couchbase-ruby-client/tree/3.8.0
76
+ changelog_uri: https://github.com/couchbase/couchbase-ruby-client/releases/tag/3.8.0
77
+ documentation_uri: https://docs.couchbase.com/sdk-api/couchbase-ruby-client-3.8.0/index.html
78
+ github_repo: https://github.com/couchbase/couchbase-ruby-client
79
+ rubygems_mfa_required: 'true'
80
+ post_install_message:
81
+ rdoc_options: []
82
+ require_paths:
83
+ - lib
84
+ required_ruby_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">"
87
+ - !ruby/object:Gem::Version
88
+ version: '3.2'
89
+ required_rubygems_version: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - ">="
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ requirements: []
95
+ rubygems_version: 3.5.22
96
+ signing_key:
97
+ specification_version: 4
98
+ summary: OpenTelemetry integration for the Couchbase Ruby Client
99
+ test_files: []