diff --git a/lib/solarwinds_apm/opentelemetry.rb b/lib/solarwinds_apm/opentelemetry.rb index 165a2c6c..cd0b1f7a 100644 --- a/lib/solarwinds_apm/opentelemetry.rb +++ b/lib/solarwinds_apm/opentelemetry.rb @@ -11,6 +11,9 @@ require 'opentelemetry-exporter-otlp' require 'opentelemetry-exporter-otlp-metrics' require 'opentelemetry-instrumentation-all' +require 'opentelemetry-logs-sdk' +require 'opentelemetry-exporter-otlp-logs' +require 'opentelemetry-instrumentation-logger' require_relative 'opentelemetry/solarwinds_propagator' require_relative 'opentelemetry/solarwinds_response_propagator' diff --git a/lib/solarwinds_apm/opentelemetry/solarwinds_response_propagator.rb b/lib/solarwinds_apm/opentelemetry/solarwinds_response_propagator.rb index e9ab90a5..4eeff61f 100644 --- a/lib/solarwinds_apm/opentelemetry/solarwinds_response_propagator.rb +++ b/lib/solarwinds_apm/opentelemetry/solarwinds_response_propagator.rb @@ -61,6 +61,7 @@ def inject(carrier, context: ::OpenTelemetry::Context.current, end private + # SW_XTRACEOPTIONS_RESPONSE_KEY -> xtrace_options_response def recover_response_from_tracestate(span_context) sanitized = span_context.tracestate.value(SW_XTRACEOPTIONS_RESPONSE_KEY) diff --git a/lib/solarwinds_apm/otel_config.rb b/lib/solarwinds_apm/otel_config.rb index 2c15e285..388897a1 100644 --- a/lib/solarwinds_apm/otel_config.rb +++ b/lib/solarwinds_apm/otel_config.rb @@ -72,6 +72,9 @@ def self.initialize ENV['OTEL_LOG_LEVEL'] = SolarWindsAPM::Config::SW_LOG_LEVEL_MAPPING.dig(log_level, :otel) end + # disable log bridge by default + ENV['OTEL_RUBY_INSTRUMENTATION_LOGGER_ENABLED'] = 'false' unless %w[true false].include?(ENV['OTEL_RUBY_INSTRUMENTATION_LOGGER_ENABLED'].to_s) + ::OpenTelemetry::SDK.configure do |c| c.resource = final_attributes c.use_all(@@config_map) diff --git a/lib/solarwinds_apm/version.rb b/lib/solarwinds_apm/version.rb index a6f7f6d7..943b0c5e 100644 --- a/lib/solarwinds_apm/version.rb +++ b/lib/solarwinds_apm/version.rb @@ -12,8 +12,8 @@ module SolarWindsAPM # solarwinds_apm.gemspec during gem build process module Version MAJOR = 7 # breaking, - MINOR = 0 # feature, - PATCH = 2 # fix => BFF + MINOR = 1 # feature, + PATCH = 0 # fix => BFF PRE = 'prev1' STRING = [MAJOR, MINOR, PATCH, PRE].compact.join('.') diff --git a/solarwinds_apm.gemspec b/solarwinds_apm.gemspec index 2ef34e66..c4e3312b 100644 --- a/solarwinds_apm.gemspec +++ b/solarwinds_apm.gemspec @@ -27,8 +27,11 @@ Gem::Specification.new do |s| s.files -= ['Rakefile'] s.add_dependency('opentelemetry-exporter-otlp', '>= 0.29.1') + s.add_dependency('opentelemetry-exporter-otlp-logs', '>= 0.2.1') s.add_dependency('opentelemetry-exporter-otlp-metrics', '>= 0.3.0') s.add_dependency('opentelemetry-instrumentation-all', '>= 0.31.0') + s.add_dependency('opentelemetry-instrumentation-logger', '>= 0.1.0') + s.add_dependency('opentelemetry-logs-sdk', '>= 0.4.0') s.add_dependency('opentelemetry-metrics-sdk', '>= 0.2.0') s.add_dependency('opentelemetry-resource-detector-aws', '>= 0.1.0') s.add_dependency('opentelemetry-resource-detector-azure', '>= 0.2.0') diff --git a/test/solarwinds_apm/otel_config_log_bridge_test.rb b/test/solarwinds_apm/otel_config_log_bridge_test.rb new file mode 100644 index 00000000..fb9ed5c2 --- /dev/null +++ b/test/solarwinds_apm/otel_config_log_bridge_test.rb @@ -0,0 +1,47 @@ +# frozen_string_literal: true + +# Copyright (c) 2019 SolarWinds, LLC. +# All rights reserved. + +require 'minitest_helper' +require './lib/solarwinds_apm/config' +require './lib/solarwinds_apm/opentelemetry' +require './lib/solarwinds_apm/support/txn_name_manager' +require './lib/solarwinds_apm/otel_config' + +describe 'Log Bridge Initialization Test' do + describe 'check if log bridge is enabled' do + after do + ENV.delete('OTEL_RUBY_INSTRUMENTATION_LOGGER_ENABLED') + end + + it 'OTEL_RUBY_INSTRUMENTATION_LOGGER_ENABLED=true -> enabled' do + ENV['OTEL_RUBY_INSTRUMENTATION_LOGGER_ENABLED'] = 'true' + SolarWindsAPM::OTelConfig.initialize + _(ENV.fetch('OTEL_RUBY_INSTRUMENTATION_LOGGER_ENABLED', nil)).must_equal 'true' + end + + it 'OTEL_RUBY_INSTRUMENTATION_LOGGER_ENABLED=false -> enabled' do + ENV['OTEL_RUBY_INSTRUMENTATION_LOGGER_ENABLED'] = 'false' + SolarWindsAPM::OTelConfig.initialize + _(ENV.fetch('OTEL_RUBY_INSTRUMENTATION_LOGGER_ENABLED', nil)).must_equal 'false' + end + + it 'OTEL_RUBY_INSTRUMENTATION_LOGGER_ENABLED=empty -> disabled' do + ENV['OTEL_RUBY_INSTRUMENTATION_LOGGER_ENABLED'] = '' + SolarWindsAPM::OTelConfig.initialize + _(ENV.fetch('OTEL_RUBY_INSTRUMENTATION_LOGGER_ENABLED', nil)).must_equal 'false' + end + + it 'OTEL_RUBY_INSTRUMENTATION_LOGGER_ENABLED=nil -> disabled' do + ENV['OTEL_RUBY_INSTRUMENTATION_LOGGER_ENABLED'] = nil + SolarWindsAPM::OTelConfig.initialize + _(ENV.fetch('OTEL_RUBY_INSTRUMENTATION_LOGGER_ENABLED', nil)).must_equal 'false' + end + it 'OTEL_RUBY_INSTRUMENTATION_LOGGER_ENABLED=djisdfes -> disabled' do + ENV['OTEL_RUBY_INSTRUMENTATION_LOGGER_ENABLED'] = 'djisdfes' + SolarWindsAPM::OTelConfig.initialize + _(ENV.fetch('OTEL_RUBY_INSTRUMENTATION_LOGGER_ENABLED', nil)).must_equal 'false' + end + end +end