|
| 1 | +# Couchbase Ruby Client OpenTelemetry Integration |
| 2 | + |
| 3 | +## Installation |
| 4 | + |
| 5 | +The library has been tested with MRI 3.2, 3.3, 3.4 and 4.0. Supported platforms are Linux and MacOS. |
| 6 | + |
| 7 | +Add this line to your application's Gemfile: |
| 8 | + |
| 9 | +```ruby |
| 10 | +gem "couchbase-opentelemetry", "0.1.0" |
| 11 | +``` |
| 12 | + |
| 13 | +And then execute: |
| 14 | + |
| 15 | + $ bundle install |
| 16 | + |
| 17 | +Or install it yourself as: |
| 18 | + |
| 19 | + $ gem install couchbase-opentelemetry |
| 20 | + |
| 21 | +## Usage |
| 22 | + |
| 23 | +Here is an example on how to set up Tracing and Metrics with OpenTelemetr: |
| 24 | + |
| 25 | +```ruby |
| 26 | +require "couchbase" |
| 27 | +require "couchbase/opentelemetry" |
| 28 | + |
| 29 | +require "opentelemetry-sdk" |
| 30 | +require "opentelemetry-metrics-sdk" |
| 31 | + |
| 32 | +# Initialize a tracer provider |
| 33 | +tracer_provider = OpenTelemetry::SDK::Trace::TracerProvider.new |
| 34 | +tracer_provider.add_span_processor( |
| 35 | + OpenTelemetry::SDK::Trace::Export::BatchSpanProcessor.new( |
| 36 | + OpenTelemetry::Exporter::OTLP::Exporter.new(endpoint: "https://<hostname>:<port>/v1/traces") |
| 37 | + ) |
| 38 | +) |
| 39 | + |
| 40 | +# Initialize the Couchbase OpenTelemetry Request Tracer |
| 41 | +tracer = Couchbase::OpenTelemetry::RequestTracer.new(tracer_provider) |
| 42 | + |
| 43 | +# Initialize a meter provider |
| 44 | +meter_provider = OpenTelemetry::SDK::Metrics::MeterProvider.new |
| 45 | +meter_provider.add_metric_reader( |
| 46 | + OpenTelemetry::SDk::Metrics::Export::PeriodicMetricReader.new( |
| 47 | + exporter: OpenTelemetry::Exporter::OTLP::Metrics::MetricsExporter.new( |
| 48 | + endpoint: "https://<hostname>:<port>/v1/metrics" |
| 49 | + ) |
| 50 | + ) |
| 51 | +) |
| 52 | + |
| 53 | +# Initialize the Couchbase OpenTelemetry Meter |
| 54 | +meter = Couchbase::OpenTelemetry::Meter.new(meter_provider) |
| 55 | + |
| 56 | +# Configure tracer and meter in cluster options |
| 57 | +options = Couchbase::Options::Cluster.new( |
| 58 | + authenticator: Couchbase::PasswordAuthenticator.new("Administrator", "password") |
| 59 | + tracer: tracer, |
| 60 | + meter: meter |
| 61 | +) |
| 62 | + |
| 63 | +# Initialize cluster instance |
| 64 | +cluster = Cluster.connect("couchbase://127.0.0.1", options) |
| 65 | +``` |
| 66 | + |
| 67 | +## License |
| 68 | + |
| 69 | +The gem is available as open source under the terms of the [Apache 2.0 License](https://opensource.org/licenses/Apache-2.0). |
| 70 | + |
| 71 | + Copyright 2025-Present Couchbase, Inc. |
| 72 | + |
| 73 | + Licensed under the Apache License, Version 2.0 (the "License"); |
| 74 | + you may not use this file except in compliance with the License. |
| 75 | + You may obtain a copy of the License at |
| 76 | + |
| 77 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 78 | + |
| 79 | + Unless required by applicable law or agreed to in writing, software |
| 80 | + distributed under the License is distributed on an "AS IS" BASIS, |
| 81 | + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 82 | + See the License for the specific language governing permissions and |
| 83 | + limitations under the License. |
0 commit comments