Skip to content

Commit

Permalink
chore: Prepare bridge for review
Browse files Browse the repository at this point in the history
* Add references to released logs gems
* Test Rails 7.0 - 8.0
* Rubocop
* Set gem version
  • Loading branch information
kaylareopelle committed Dec 5, 2024
1 parent 0f3df26 commit c9f47c6
Show file tree
Hide file tree
Showing 13 changed files with 37 additions and 52 deletions.
33 changes: 13 additions & 20 deletions instrumentation/logger/Appraisals
Original file line number Diff line number Diff line change
@@ -1,22 +1,15 @@
# frozen_string_literal: true

# # Copyright The OpenTelemetry Authors
# #
# # SPDX-License-Identifier: Apache-2.0

# # TOOD: Re-enable before release, along with active_support_logger tests
# # Appraisals wont work with gems installed by a branch, so we can't
# # set this up until there's a release of the otel logs gems
# # Only test Rails versions that are still in support

# appraise 'rails-7.0' do
# gem 'rails', '~> 7.0.0'
# end

# appraise 'rails-7.1' do
# gem 'rails', '~> 7.1.0'
# end

# appraise 'rails-7.2' do
# gem 'rails', '~> 7.2.0'
# end
# Copyright The OpenTelemetry Authors
#
# SPDX-License-Identifier: Apache-2.0

%w[7.0.0 7.1.0].each do |version|
appraise "rails-#{version}" do
gem 'rails', "~> #{version}"
end
end

appraise 'rails-latest' do
gem 'rails'
end
8 changes: 0 additions & 8 deletions instrumentation/logger/Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

source 'https://rubygems.org'

### TODO: Ignore the below comment during development, fix before release ###
# DO NOT ADD DEPENDENCIES HERE!
# Please declare a minimum development dependency in the gemspec,
# then target specific versions in the Appraisals file.
Expand All @@ -15,11 +14,4 @@ gemspec

group :test do
gem 'opentelemetry-instrumentation-base', path: '../base'
gem 'opentelemetry-api', git: 'https://github.com/kaylareopelle/opentelemetry-ruby', branch: 'log-record-processor3', glob: 'api/*.gemspec'
gem 'opentelemetry-logs-api', git: 'https://github.com/kaylareopelle/opentelemetry-ruby', branch: 'log-record-processor3', glob: 'logs_api/*.gemspec'
gem 'opentelemetry-logs-sdk', git: 'https://github.com/kaylareopelle/opentelemetry-ruby', branch: 'log-record-processor3', glob: 'logs_sdk/*.gemspec'
gem 'opentelemetry-sdk', git: 'https://github.com/kaylareopelle/opentelemetry-ruby', branch: 'log-record-processor3', glob: 'sdk/*.gemspec'
end

# Temporary for testing, Appraisal does not work with gems installed from git source
gem 'rails', '~> 7.1.0'
3 changes: 2 additions & 1 deletion instrumentation/logger/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ OpenTelemetry::SDK.configure do |c|
end
```

Alternatively, you can also call `use_all` to install all the available instrumentation.
Alternatively, you can call `use_all` to install all the available instrumentation.

```ruby
OpenTelemetry::SDK.configure do |c|
Expand All @@ -40,6 +40,7 @@ The test suite leverages [appraisal][appraisal] to verify the integration across

```shell
cd instrumentation/logger
bundle exec appraisal generate
bundle exec appraisal install
bundle exec appraisal rake test
```
Expand Down
10 changes: 5 additions & 5 deletions instrumentation/logger/example/logger.rb
Original file line number Diff line number Diff line change
@@ -1,32 +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/sdk'
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'
ENV['OTEL_LOGS_EXPORTER'] ||= 'console'

OpenTelemetry::SDK.configure do |c|
c.use OpenTelemetry::Instrumentation::Logger
c.use 'OpenTelemetry::Instrumentation::Logger'
end

at_exit do
OpenTelemetry.logger_provider.shutdown
end

logger = Logger.new
logger = Logger.new(STDOUT)
logger.debug('emerald ash borer')
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
# The OpenTelemetry module provides global accessors for telemetry objects.
# See the documentation for the `opentelemetry-api` gem for details.
module OpenTelemetry
# The Instrumentation module is a namespace for all OpenTelemetry Instrumentation libraries
module Instrumentation
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ module Logger
attr_writer :skip_instrumenting

def format_message(severity, datetime, progname, msg)
formatted_message = super(severity, datetime, progname, msg)
formatted_message = super
return formatted_message if skip_instrumenting?

OpenTelemetry.logger_provider.logger(
Expand All @@ -23,7 +23,7 @@ def format_message(severity, datetime, progname, msg)
severity_text: severity,
severity_number: severity_number(severity),
timestamp: datetime,
body: msg, # New Relic uses formatted_message here. This also helps us with not recording progname, because it is included in the formatted message by default. Which seems more appropriate?
body: msg,
context: OpenTelemetry::Context.current
)
formatted_message
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
module OpenTelemetry
module Instrumentation
module Logger
# TODO: Update me when ready to release
VERSION = '0.0.0'
VERSION = '0.1.0'
end
end
end
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,18 @@ Gem::Specification.new do |spec|
spec.require_paths = ['lib']
spec.required_ruby_version = '>= 3.0'

spec.add_dependency 'opentelemetry-api', '~> 1.2'
spec.add_dependency 'opentelemetry-instrumentation-base', '~> 0.22'
spec.add_dependency 'opentelemetry-logs-api', '~> 0.1'

spec.add_development_dependency 'appraisal', '~> 2.2.0'
spec.add_development_dependency 'appraisal', '~> 2.5.0'
spec.add_development_dependency 'bundler', '~> 2.4'
spec.add_development_dependency 'minitest', '~> 5.0'
spec.add_development_dependency 'opentelemetry-sdk', '~> 1.0'
spec.add_development_dependency 'opentelemetry-logs-sdk', '~> 0.1'
spec.add_development_dependency 'opentelemetry-test-helpers', '~> 0.3'
spec.add_development_dependency 'rake', '~> 13.0'
spec.add_development_dependency 'rubocop', '~> 1.62.1'
spec.add_development_dependency 'rubocop-performance', '~> 1.20.2'
spec.add_development_dependency 'rubocop', '~> 1.69.1'
spec.add_development_dependency 'rubocop-performance', '~> 1.23.0'
spec.add_development_dependency 'simplecov'
spec.add_development_dependency 'webmock', '~> 3.7.6'
spec.add_development_dependency 'yard', '~> 0.9'
spec.add_development_dependency 'yard-doctest', '~> 0.1.6'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
let(:broadcast) { ActiveSupport::BroadcastLogger.new(logger, logger2) }

before do
skip unless defined?(::ActiveSupport::BroadcastLogger)
skip unless defined?(ActiveSupport::BroadcastLogger)
EXPORTER.reset
instrumentation.install
end
Expand All @@ -24,15 +24,15 @@

describe '#add' do
it 'emits the log to the broadcasted loggers' do
body = "Ground control to Major Tom"
body = 'Ground control to Major Tom'
broadcast.add(Logger::DEBUG, body)

assert_includes(LOG_STREAM.string, body)
assert_includes(BROADCASTED_STREAM.string, body)
end

it 'emits only one OpenTelemetry log record' do
body = "Wake up, you sleepyhead"
body = 'Wake up, you sleepyhead'
broadcast.add(Logger::DEBUG, body)
log_records = EXPORTER.emitted_log_records

Expand All @@ -44,7 +44,7 @@

describe '#unknown' do
it 'emits the log to the broadcasted loggers' do
body = "I know when to go out"
body = 'I know when to go out'
broadcast.unknown(body)

assert_includes(LOG_STREAM.string, body)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
let(:broadcasted_logger) { ActiveSupport::Logger.new(BROADCASTED_STREAM) }

before do
skip unless defined?(::ActiveSupport::Logger) && !defined?(::ActiveSupport::BroadcastLogger)
skip unless defined?(ActiveSupport::Logger) && !defined?(ActiveSupport::BroadcastLogger)
EXPORTER.reset
Rails.logger = main_logger.extend(ActiveSupport::Logger.broadcast(broadcasted_logger))
instrumentation.install
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,14 @@

it 'sets log record attributes based on the Ruby log' do
timestamp = Time.now
nano_timestamp = OpenTelemetry::SDK::Logs::LogRecord.new.send(:to_integer_nanoseconds, timestamp)

Time.stub(:now, timestamp) do
ruby_logger.debug(msg)
assert_equal(msg, log_record.body)
assert_equal('DEBUG', log_record.severity_text)
assert_equal(5, log_record.severity_number)
assert_equal(timestamp, log_record.timestamp)
assert_equal(nano_timestamp, log_record.timestamp)
end
end

Expand Down
2 changes: 0 additions & 2 deletions instrumentation/logger/test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
SimpleCov.minimum_coverage 85

require 'minitest/autorun'
require 'webmock/minitest'
require 'opentelemetry/sdk/logs'
require 'test_helpers/app_config'

EXPORTER = OpenTelemetry::SDK::Logs::Export::InMemoryLogRecordExporter.new
Expand Down

0 comments on commit c9f47c6

Please sign in to comment.