diff --git a/gemfiles/test_gems.gemfile b/gemfiles/test_gems.gemfile index 6927c94..9f0f73b 100644 --- a/gemfiles/test_gems.gemfile +++ b/gemfiles/test_gems.gemfile @@ -37,4 +37,5 @@ group :development, :test do gem 'opentelemetry-instrumentation-all' gem 'opentelemetry-propagator-b3' gem 'opentelemetry-exporter-otlp' + gem 'opentelemetry-metrics-sdk' end diff --git a/lib/solarwinds_apm/opentelemetry/otlp_processor.rb b/lib/solarwinds_apm/opentelemetry/otlp_processor.rb index 17286ea..ad1c78d 100644 --- a/lib/solarwinds_apm/opentelemetry/otlp_processor.rb +++ b/lib/solarwinds_apm/opentelemetry/otlp_processor.rb @@ -70,10 +70,11 @@ def meter_attributes(span) 'sw.transaction' => calculate_lambda_transaction_name(span) } - http_status_code = get_http_status_code(span) - meter_attrs['http.status_code'] = http_status_code if http_status_code != 0 - meter_attrs['http.method'] = span.attributes[HTTP_METHOD] if span.attributes[HTTP_METHOD] - + if span_http?(span) + http_status_code = get_http_status_code(span) + meter_attrs['http.status_code'] = http_status_code if http_status_code != 0 + meter_attrs['http.method'] = span.attributes[HTTP_METHOD] if span.attributes[HTTP_METHOD] + end SolarWindsAPM.logger.debug { "[#{self.class}/#{__method__}] meter_attrs: #{meter_attrs.inspect}" } meter_attrs end diff --git a/test/opentelemetry/otlp_processor_test.rb b/test/opentelemetry/otlp_processor_test.rb index dcf1aa5..dd94bb5 100644 --- a/test/opentelemetry/otlp_processor_test.rb +++ b/test/opentelemetry/otlp_processor_test.rb @@ -9,18 +9,11 @@ require './lib/solarwinds_apm/support/txn_name_manager' require './lib/solarwinds_apm/otel_config' require './lib/solarwinds_apm/api' +require 'opentelemetry-metrics-sdk' describe 'otlp processor test' do before do - skip unless defined?(OpenTelemetry::SDK::Metrics) # skip if no metrics_sdk loaded - - @exporter = OpenTelemetry::Exporter::OTLP::Exporter.new - @txn_manager = SolarWindsAPM::TxnNameManager.new - - @meters = { 'sw.apm.sampling.metrics' => OpenTelemetry.meter_provider.meter('sw.apm.sampling.metrics'), - 'sw.apm.request.metrics' => OpenTelemetry.meter_provider.meter('sw.apm.request.metrics') } - - @processor = SolarWindsAPM::OpenTelemetry::OTLPProcessor.new(@meters, @exporter, @txn_manager) + @processor = SolarWindsAPM::OpenTelemetry::OTLPProcessor.new end after do @@ -28,21 +21,13 @@ @processor.instance_variable_get(:@meters)['sw.apm.sampling.metrics'].instance_variable_set(:@instrument_registry, {}) end - # Yellow ERROR due to missing metrics_sdk so far for testing otlp processor - it 'processor_meters_should_be_nil_at_beginning' do - _(@processor.instance_variable_get(:@metrics).size).must_equal 0 - end - - # Yellow ERROR due to missing metrics_sdk so far for testing otlp processor - it 'test_on_start_verfy_component_initialized_correctly' do - @processor.on_start(create_span, OpenTelemetry::Context.current) - + it 'initializes_meters_and_metrics' do request_metrics = @processor.instance_variable_get(:@meters)['sw.apm.request.metrics'] sampling_metrics = @processor.instance_variable_get(:@meters)['sw.apm.sampling.metrics'] request_metrics_registry = request_metrics.instance_variable_get(:@instrument_registry) sampling_metrics_registry = sampling_metrics.instance_variable_get(:@instrument_registry) - _(@processor.txn_manager.get_root_context_h('77cb6ccc522d3106114dd6ecbb70036a')).must_equal '31e175128efc4018-00' + _(@processor.instance_variable_get(:@meters).size).must_equal 2 _(@processor.instance_variable_get(:@metrics).size).must_equal 7 refute_nil(request_metrics_registry['trace.service.response_time']) @@ -53,4 +38,12 @@ refute_nil(sampling_metrics_registry['trace.service.through_trace_count']) refute_nil(sampling_metrics_registry['trace.service.triggered_trace_count']) end + + it 'does_not_have_transaction_manager' do + # currently otlp processor is only used in lambda which does not support transaction naming via SDK + # this assumption may change when we introduce otlp export for non-lambda environments + assert_nil(@processor.txn_manager) + end + + # TODO: tests for on_start and on_end behaviour end