-
Notifications
You must be signed in to change notification settings - Fork 55
RCBC-524: OpenTelemetry integration #216
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
DemetrisChr
wants to merge
3
commits into
couchbase:main
Choose a base branch
from
DemetrisChr:RCBC-524-otel-integration
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| # Copyright 2026-Present Couchbase, Inc. | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| lib = File.expand_path("lib", __dir__) | ||
| $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) | ||
|
|
||
| Gem::Specification.new do |spec| | ||
| spec.name = "couchbase-opentelemetry" | ||
| spec.version = "0.0.1" | ||
| spec.authors = ["Sergey Avseyev"] | ||
| spec.email = ["sergey.avseyev@gmail.com"] | ||
| spec.summary = "OpenTelemetry integration for the Couchbase Ruby Client" | ||
| spec.description = "OpenTelemetry integration for the Couchbase Ruby Client" | ||
| spec.homepage = "https://www.couchbase.com" | ||
| spec.license = "Apache-2.0" | ||
| spec.required_ruby_version = "> 3.1" | ||
|
|
||
| spec.metadata = { | ||
| "homepage_uri" => "https://docs.couchbase.com/ruby-sdk/current/hello-world/start-using-sdk.html", | ||
| "bug_tracker_uri" => "https://jira.issues.couchbase.com/browse/RCBC", | ||
| "mailing_list_uri" => "https://www.couchbase.com/forums/c/ruby-sdk", | ||
| "source_code_uri" => "https://github.com/couchbase/couchbase-ruby-client/tree/#{spec.version}", | ||
| "changelog_uri" => "https://github.com/couchbase/couchbase-ruby-client/releases/tag/#{spec.version}", | ||
| "documentation_uri" => "https://docs.couchbase.com/sdk-api/couchbase-ruby-client-#{spec.version}/index.html", | ||
| "github_repo" => "https://github.com/couchbase/couchbase-ruby-client", | ||
| "rubygems_mfa_required" => "true", | ||
| } | ||
|
|
||
| spec.files = Dir.glob([ | ||
| "lib/**/*.rb", | ||
| ], File::FNM_DOTMATCH).select { |path| File.file?(path) } | ||
| spec.bindir = "exe" | ||
| spec.executables = spec.files.grep(/^exe\//) { |f| File.basename(f) } | ||
| spec.require_paths = ["lib"] | ||
|
|
||
| spec.add_dependency "concurrent-ruby", "~> 1.3" | ||
| spec.add_dependency "opentelemetry-api", "~> 1.7" | ||
| spec.add_dependency "opentelemetry-metrics-api", "~> 0.4.0" | ||
| end |
49 changes: 49 additions & 0 deletions
49
couchbase-opentelemetry/lib/couchbase/metrics/open_telemetry_meter.rb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| # Copyright 2026-Present Couchbase, Inc. | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| require "couchbase/metrics/meter" | ||
| require "couchbase/errors" | ||
| require_relative "open_telemetry_value_recorder" | ||
|
|
||
| require "opentelemetry-metrics-api" | ||
|
|
||
| module Couchbase | ||
| module Metrics | ||
| class OpenTelemetryMeter < Meter | ||
| def initialize(meter_provider) | ||
| super() | ||
| @histogram_cache = Concurrent::Map.new | ||
| begin | ||
| @wrapped = meter_provider.meter("com.couchbase.client/ruby") | ||
| rescue StandardError => e | ||
| raise Error::MeterError.new("Failed to create OpenTelemetry Meter: #{e.message}", nil, e) | ||
| end | ||
| end | ||
|
|
||
| def value_recorder(name, tags) | ||
| unit = tags.delete("__unit") | ||
|
|
||
| otel_histogram = @histogram_cache.compute_if_absent(name) do | ||
| @wrapped.create_histogram(name, unit: unit) | ||
| end | ||
|
|
||
| OpenTelemetryValueRecorder.new(otel_histogram, tags, unit: unit) | ||
| rescue StandardError => e | ||
| raise Error::MeterError.new("Failed to create OpenTelemetry Histogram: #{e.message}", nil, e) | ||
| end | ||
| end | ||
| end | ||
| end |
42 changes: 42 additions & 0 deletions
42
couchbase-opentelemetry/lib/couchbase/metrics/open_telemetry_value_recorder.rb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| # Copyright 2026-Present Couchbase, Inc. | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| require "couchbase/metrics/value_recorder" | ||
|
|
||
| module Couchbase | ||
| module Metrics | ||
| class OpenTelemetryValueRecorder < ValueRecorder | ||
| def initialize(recorder, tags, unit: nil) | ||
| super() | ||
| @wrapped = recorder | ||
| @tags = tags | ||
| @unit = unit | ||
| end | ||
|
|
||
| def record_value(value) | ||
| value = | ||
| case @unit | ||
| when "s" | ||
| value / 1_000_000.0 | ||
| else | ||
| value | ||
| end | ||
|
|
||
| @wrapped.record(value, attributes: @tags) | ||
| end | ||
| end | ||
| end | ||
| end |
49 changes: 49 additions & 0 deletions
49
couchbase-opentelemetry/lib/couchbase/tracing/open_telemetry_request_span.rb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| # Copyright 2026-Present Couchbase, Inc. | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| require "couchbase/tracing/request_span" | ||
|
|
||
| require "opentelemetry-api" | ||
|
|
||
| module Couchbase | ||
| module Tracing | ||
| class OpenTelemetryRequestSpan < RequestSpan | ||
| def initialize(span) | ||
| super() | ||
|
|
||
| @wrapped = span | ||
| end | ||
|
|
||
| def set_attribute(key, value) | ||
| @wrapped.set_attribute(key, value) | ||
| end | ||
|
|
||
| def status=(status_code) | ||
| @wrapped.status = if status_code == :ok | ||
| ::OpenTelemetry::Trace::Status.ok | ||
| elsif status_code == :error | ||
| ::OpenTelemetry::Trace::Status.error | ||
| else | ||
| ::OpenTelemetry::Trace::Status.unset | ||
| end | ||
| end | ||
|
|
||
| def finish(end_timestamp: nil) | ||
| @wrapped.finish(end_timestamp: end_timestamp) | ||
| end | ||
| end | ||
| end | ||
| end |
50 changes: 50 additions & 0 deletions
50
couchbase-opentelemetry/lib/couchbase/tracing/open_telemetry_request_tracer.rb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| # Copyright 2026-Present Couchbase, Inc. | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| require "opentelemetry-api" | ||
|
|
||
| require "couchbase/tracing/request_tracer" | ||
| require "couchbase/errors" | ||
| require_relative "open_telemetry_request_span" | ||
|
|
||
| module Couchbase | ||
| module Tracing | ||
| class OpenTelemetryRequestTracer < RequestTracer | ||
| def initialize(tracer_provider) | ||
| super() | ||
| begin | ||
| @wrapped = tracer_provider.tracer("com.couchbase.client/ruby") | ||
| rescue StandardError => e | ||
| raise Error::TracerError.new("Failed to create OpenTelemetry tracer: #{e.message}", nil, e) | ||
| end | ||
| end | ||
|
|
||
| def request_span(name, parent: nil, start_timestamp: nil) | ||
| parent_context = parent.nil? ? nil : ::OpenTelemetry::Trace.context_with_span(parent.instance_variable_get(:@wrapped)) | ||
| OpenTelemetryRequestSpan.new( | ||
| @wrapped.start_span( | ||
| name, | ||
| with_parent: parent_context, | ||
| start_timestamp: start_timestamp, | ||
| kind: :client, | ||
| ), | ||
| ) | ||
| rescue StandardError => e | ||
| raise Error::TracerError.new("Failed to create OpenTelemetry span: #{e.message}", nil, e) | ||
| end | ||
| end | ||
| end | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@DemetrisChr somehow we need to figure out proper fix here. The idea is to use specific precompiled gem for the tests and avoid fetching it from the repository.
Maybe some other solution will fit better here. Like
and then, point bundler to use it from there.
or from the different angle, create local gem repository like
And then patch
Gemfileto use something like