From 00c8687913b7fe0f246fc4cdd5a8ad36ddba39b0 Mon Sep 17 00:00:00 2001 From: Kayla Reopelle Date: Tue, 17 Sep 2024 15:27:46 -0700 Subject: [PATCH] feat: Update example and readme --- instrumentation/logger/README.md | 20 +++++++++++---- instrumentation/logger/example/logger.rb | 32 ++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 5 deletions(-) create mode 100644 instrumentation/logger/example/logger.rb diff --git a/instrumentation/logger/README.md b/instrumentation/logger/README.md index 8540d0f18..819a5b962 100644 --- a/instrumentation/logger/README.md +++ b/instrumentation/logger/README.md @@ -1,6 +1,6 @@ # OpenTelemetry Logger Instrumentation -TODO: Update description. This README is incomplete. +The Logger instrumentation is a community-maintained bridge for the Ruby [logger][logger-home] standard library. ## How do I get started? @@ -30,15 +30,23 @@ OpenTelemetry::SDK.configure do |c| end ``` -TODO: Add documentation for config options. - ## Examples -TODO: Create example +Example usage can be seen in the `./example/logger.rb` file [here](https://github.com/open-telemetry/opentelemetry-ruby-contrib/blob/main/instrumentation/logger/example/logger.rb) + +## Development + +The test suite leverages [appraisal][appraisal] to verify the integration across multiple Rails versions. To run the tests with appraisal: + +```shell +cd instrumentation/logger +bundle exec appraisal install +bundle exec appraisal rake test +``` ## How can I get involved? -The `opentelemetry-instrumentation-logger` gem source is [on github][repo-github], along with related gems including `opentelemetry-api` and `opentelemetry-sdk`. +The `opentelemetry-instrumentation-logger` gem source is [on github][repo-github], along with related gems including `opentelemetry-logs-api` and `opentelemetry-logs-sdk`. The OpenTelemetry Ruby gems are maintained by the OpenTelemetry-Ruby special interest group (SIG). You can get involved by joining us in [GitHub Discussions][discussions-url] or attending our weekly meeting. See the [meeting calendar][community-meetings] for dates and times. For more information on this and other language SIGs, see the OpenTelemetry [community page][ruby-sig]. @@ -46,7 +54,9 @@ The OpenTelemetry Ruby gems are maintained by the OpenTelemetry-Ruby special int The `opentelemetry-instrumentation-logger` gem is distributed under the Apache 2.0 license. See [LICENSE][license-github] for more information. +[appraisal]: https://github.com/thoughtbot/appraisal [bundler-home]: https://bundler.io +[logger-home]: https://github.com/ruby/logger [repo-github]: https://github.com/open-telemetry/opentelemetry-ruby [license-github]: https://github.com/open-telemetry/opentelemetry-ruby-contrib/blob/main/LICENSE [ruby-sig]: https://github.com/open-telemetry/community#ruby-sig diff --git a/instrumentation/logger/example/logger.rb b/instrumentation/logger/example/logger.rb new file mode 100644 index 000000000..59369653c --- /dev/null +++ b/instrumentation/logger/example/logger.rb @@ -0,0 +1,32 @@ +# frozen_string_literal: true +# TODO: Test me once the logs API/SDK gems have been released +# Since the gems aren't released, this is broken atm +require 'bundler/inline' + +gemfile(true) do + source 'https://rubygems.org' + + gem 'logger' + gem 'opentelemetry-sdk' + gem 'opentelemetry-logs-api' + gem 'opentelemetry-logs-sdk' + gem 'opentelemetry-instrumentation-logger', path: '../' +end + +require 'opentelemetry-logs-sdk' +require 'opentelemetry-instrumentation-logger' +require 'logger' + +# Don't attempt to export traces, Logger instrumentation only emits logs. +ENV['OTEL_TRACES_EXPORTER'] ||= 'none' + +OpenTelemetry::SDK.configure do |c| + c.use OpenTelemetry::Instrumentation::Logger +end + +at_exit do + OpenTelemetry.logger_provider.shutdown +end + +logger = Logger.new +logger.debug('emerald ash borer')