diff --git a/.github/scripts/announce_release_on_slack.py b/.github/scripts/announce_release_on_slack.py index acda0e643..b4524ea02 100755 --- a/.github/scripts/announce_release_on_slack.py +++ b/.github/scripts/announce_release_on_slack.py @@ -53,10 +53,10 @@ def reformat_github_md_to_slack_markup(msg): # /c938c67e957345ba6a0015ca3ace1fd779d0979c/lib/Markdown.ts#LL111C1-L116C44 msg = re.sub(r"^(\s*)[-*](\s+)", r"\1•\2", msg, flags=re.MULTILINE) - msg = re.sub(r"(\*|_)\1(\S|\S.*?\S)\1\1(?!\1)", r"\2", msg) - msg = re.sub(r"(\*|_)(?!\1)(\S|\S.*?\S)\1(?!\1)", r"\2", msg) + msg = re.sub(r"([*_])\1(\S|\S.*?\S)\1\1(?!\1)", r"\2", msg) + msg = re.sub(r"([*_])(?!\1)(\S|\S.*?\S)\1(?!\1)", r"\2", msg) msg = msg.replace("", "*").replace("", "_") - msg = re.sub(r"^([#]+)\s+([\S ]+)$", r"*\2*", msg, flags=re.MULTILINE) + msg = re.sub(r"^#+\s+(\S[\S ]*)$", r"*\1*", msg, flags=re.MULTILINE) # TODO: The message text has to have a partial entity encoding # https://api.slack.com/reference/surfaces/formatting#escaping diff --git a/.github/workflows/release-notification-on-slack.yml b/.github/workflows/release-notification-on-slack.yml index d040e2a9b..8e111c5dc 100644 --- a/.github/workflows/release-notification-on-slack.yml +++ b/.github/workflows/release-notification-on-slack.yml @@ -24,7 +24,7 @@ jobs: export GITHUB_RELEASE_TAG=$(basename ${GITHUB_REF}) fi echo "New release published ${GITHUB_RELEASE_TAG}" - pip3 install httpx PyGithub + pip3 install --only-binary :all: httpx==0.28.1 PyGithub==2.10.0 echo $PWD ls -lah python ./.github/scripts/announce_release_on_slack.py diff --git a/bin/aws-lambda/Dockerfile b/bin/aws-lambda/Dockerfile index c59b5d2a7..89fd223fe 100644 --- a/bin/aws-lambda/Dockerfile +++ b/bin/aws-lambda/Dockerfile @@ -1,4 +1,4 @@ -FROM public.ecr.aws/lambda/ruby:3.4 as ruby_dependencies_34 +FROM public.ecr.aws/lambda/ruby:3.4 AS ruby_dependencies_34 # Install system dependencies for native extensions RUN dnf update -y && \ @@ -13,7 +13,7 @@ RUN echo "source 'https://rubygems.org'; gem 'instana'; gem 'get_process_mem'" > RUN mkdir -p ruby/gems/3.4.0 && \ cp -r vendor/bundle/ruby/3.4.0*/* ruby/gems/3.4.0/ -FROM public.ecr.aws/lambda/ruby:3.3 as ruby_dependencies_33 +FROM public.ecr.aws/lambda/ruby:3.3 AS ruby_dependencies_33 # Install system dependencies for native extensions RUN dnf update -y && \ @@ -28,7 +28,7 @@ RUN echo "source 'https://rubygems.org'; gem 'instana'; gem 'get_process_mem'" > RUN mkdir -p ruby/gems/3.3.0 && \ cp -r vendor/bundle/ruby/3.3.0*/* ruby/gems/3.3.0/ -FROM public.ecr.aws/lambda/ruby:3.2 as ruby_dependencies_32 +FROM public.ecr.aws/lambda/ruby:3.2 AS ruby_dependencies_32 # Install system dependencies for native extensions RUN yum update -y && \ @@ -44,7 +44,7 @@ RUN echo "source 'https://rubygems.org'; gem 'instana'; gem 'get_process_mem'" > RUN mkdir -p ruby/gems/3.2.0 && \ cp -r vendor/bundle/ruby/3.2.0*/* ruby/gems/3.2.0/ -FROM public.ecr.aws/docker/library/alpine:3.22 as final +FROM public.ecr.aws/docker/library/alpine:3.22 AS final RUN apk add --no-cache zip unzip diff --git a/download.sh b/download.sh index 9c75a6fbc..90393810f 100755 --- a/download.sh +++ b/download.sh @@ -2,7 +2,7 @@ if [[ -z ${CIRCLE_TOKEN} ]] then - echo "ERROR: The CIRCLE_TOKEN variable is missing" + echo "ERROR: The CIRCLE_TOKEN variable is missing" >&2 exit 255 fi @@ -27,7 +27,7 @@ fi if [[ -z ${PIPELINE_ID} ]] then - echo "ERROR: Could not determine the pipeline ID. Check CIRCLE_TOKEN and CIRCLE_BUILD_NUM (or WORKFLOW_ID)." + echo "ERROR: Could not determine the pipeline ID. Check CIRCLE_TOKEN and CIRCLE_BUILD_NUM (or WORKFLOW_ID)." >&2 exit 253 fi @@ -47,7 +47,7 @@ WORKFLOW_IDS=$(curl -s \ if [[ -z ${WORKFLOW_IDS} ]] then - echo "ERROR: No workflows found for pipeline ${PIPELINE_ID}" + echo "ERROR: No workflows found for pipeline ${PIPELINE_ID}" >&2 exit 252 fi @@ -73,7 +73,7 @@ do if [[ "${STATUS}" != "success" ]] then - echo "ERROR: Workflow ${workflow_id} did not succeed! Status is: ${STATUS}" + echo "ERROR: Workflow ${workflow_id} did not succeed! Status is: ${STATUS}" >&2 exit 254 else echo "Workflow ${workflow_id} has finished successfully! Status is: ${STATUS}" diff --git a/lib/instana/exporter/otlp/rpc_converter.rb b/lib/instana/exporter/otlp/rpc_converter.rb index 57dc55486..695e83b5c 100644 --- a/lib/instana/exporter/otlp/rpc_converter.rb +++ b/lib/instana/exporter/otlp/rpc_converter.rb @@ -150,11 +150,8 @@ def grpc_status_code(rpc_data) # Attempt to extract gRPC status string from error message error_msg = rpc_data[:error].to_s - GRPC_STATUS_CODES.each do |name, code| - return code if error_msg.include?(name) - end - - GRPC_STATUS_CODES['UNKNOWN'] + _name, code = GRPC_STATUS_CODES.find { |name, _code| error_msg.include?(name) } + code || GRPC_STATUS_CODES['UNKNOWN'] end end end diff --git a/lib/instana/frameworks/cuba.rb b/lib/instana/frameworks/cuba.rb index 288ea7373..5e570c27a 100644 --- a/lib/instana/frameworks/cuba.rb +++ b/lib/instana/frameworks/cuba.rb @@ -12,7 +12,7 @@ def self.prepended(base) end def on(*args, &blk) - wrapper = lambda do |*caputres| + wrapper = lambda do |*_captures| env['INSTANA_PATH_TEMPLATE_FRAGMENTS'] << args .select { |a| a.is_a?(String) } .join('/') diff --git a/lib/instana/instrumentation/action_view.rb b/lib/instana/instrumentation/action_view.rb index ba5822a3a..1671e385f 100644 --- a/lib/instana/instrumentation/action_view.rb +++ b/lib/instana/instrumentation/action_view.rb @@ -6,14 +6,7 @@ module Instrumentation module ActionView module PartialRenderer def render_partial(*args) - call_payload = { - render: { - type: :partial, - name: @options.is_a?(Hash) ? @options[:partial].to_s : 'Unknown' - } - } - - ::Instana.tracer.in_span(:render, attributes: call_payload) { super(*args) } + ::Instana.tracer.in_span(:render, attributes: partial_call_payload) { super(*args) } end def render_collection(*args) @@ -28,14 +21,18 @@ def render_collection(*args) end def render_partial_template(*args) - call_payload = { + ::Instana.tracer.in_span(:render, attributes: partial_call_payload) { super(*args) } + end + + private + + def partial_call_payload + { render: { type: :partial, name: @options.is_a?(Hash) ? @options[:partial].to_s : 'Unknown' } } - - ::Instana.tracer.in_span(:render, attributes: call_payload) { super(*args) } end end diff --git a/lib/instana/instrumentation/excon.rb b/lib/instana/instrumentation/excon.rb index 8f896e883..e5737cee0 100644 --- a/lib/instana/instrumentation/excon.rb +++ b/lib/instana/instrumentation/excon.rb @@ -51,7 +51,7 @@ def error_call(datum) end def response_call(datum) - # FIXME: Will connect exceptions call a response? + # Open question: will connect exceptions call a response? # return @stack.response_call(datum) unless traceable? diff --git a/lib/instana/instrumentation/graphql.rb b/lib/instana/instrumentation/graphql.rb index f875eacea..d73deb0c2 100644 --- a/lib/instana/instrumentation/graphql.rb +++ b/lib/instana/instrumentation/graphql.rb @@ -15,7 +15,7 @@ class GraphqlTracing < GraphQL::Tracing::PlatformTracing 'execute_query_lazy' => 'execute.graphql', } - def platform_trace(platform_key, key, data) + def platform_trace(_platform_key, key, data) return yield unless key == 'execute_query' operation = data[:query].selected_operation diff --git a/lib/instana/instrumentation/resque.rb b/lib/instana/instrumentation/resque.rb index 841bac545..4bb28a649 100644 --- a/lib/instana/instrumentation/resque.rb +++ b/lib/instana/instrumentation/resque.rb @@ -10,7 +10,7 @@ def self.prepended(klass) klass.send :extend, ::Resque end - def collect_kvs(op, klass, args) + def collect_kvs(_op, klass, _args) kvs = {} begin @@ -85,7 +85,7 @@ def perform(job) end span = OpenTelemetry::Trace.non_recording_span(trace_context) if trace_context Trace.with_span(span) do - Instana.tracer.in_span(:'resque-worker', attributes: kvs) do |span| + Instana.tracer.in_span(:'resque-worker', attributes: kvs) do |_span| super(job) end end diff --git a/lib/instana/samplers/samplers.rb b/lib/instana/samplers/samplers.rb index 218209ce0..bbc8d5a13 100644 --- a/lib/instana/samplers/samplers.rb +++ b/lib/instana/samplers/samplers.rb @@ -66,7 +66,7 @@ def self.trace_id_ratio_based(_) self end - def self.should_sample?(trace_id:, parent_context:, links:, name:, kind:, attributes:) # rubocop:disable Metrics/ParameterLists, Lint/UnusedMethodArgument: + def self.should_sample?(parent_context:, **) parent_span_context = OpenTelemetry::Trace.current_span(parent_context).context # Parents wrapped in non_recording_span can expose a non-SpanContext # #context; the new span's SpanContext needs a Tracestate, never nil. diff --git a/lib/instana/snapshot/docker_container.rb b/lib/instana/snapshot/docker_container.rb index c22e14772..3a5d7d4c7 100644 --- a/lib/instana/snapshot/docker_container.rb +++ b/lib/instana/snapshot/docker_container.rb @@ -142,7 +142,7 @@ def lookup(resource) path = @metadata_uri.path + resource response = @client.send_request('GET', path) - raise "Unable to get `#{path}`. Got `#{response.code}`." unless response.ok? + raise StandardError, "Unable to get `#{path}`. Got `#{response.code}`." unless response.ok? response.json end diff --git a/lib/instana/snapshot/fargate_container.rb b/lib/instana/snapshot/fargate_container.rb index 1a560f1aa..efbf6ae22 100644 --- a/lib/instana/snapshot/fargate_container.rb +++ b/lib/instana/snapshot/fargate_container.rb @@ -79,7 +79,7 @@ def current_conatiner path = @metadata_uri.path response = @client.send_request('GET', path) - raise "Unable to get `#{path}`. Got `#{response.code}`." unless response.ok? + raise StandardError, "Unable to get `#{path}`. Got `#{response.code}`." unless response.ok? response.json end diff --git a/lib/instana/snapshot/fargate_process.rb b/lib/instana/snapshot/fargate_process.rb index b3d421bb2..2929fd129 100644 --- a/lib/instana/snapshot/fargate_process.rb +++ b/lib/instana/snapshot/fargate_process.rb @@ -50,7 +50,7 @@ def lookup(resource = nil) path = resource ? @metadata_uri.path + resource : @metadata_uri.path response = @client.send_request('GET', path) - raise "Unable to get `#{path}`. Got `#{response.code}`." unless response.ok? + raise StandardError, "Unable to get `#{path}`. Got `#{response.code}`." unless response.ok? response.json end diff --git a/lib/instana/snapshot/fargate_task.rb b/lib/instana/snapshot/fargate_task.rb index cc1eb7901..930e3a7fb 100644 --- a/lib/instana/snapshot/fargate_task.rb +++ b/lib/instana/snapshot/fargate_task.rb @@ -63,7 +63,7 @@ def lookup(resource) path = @metadata_uri.path + resource response = @client.send_request('GET', path) - raise "Unable to get `#{path}`. Got `#{response.code}`." unless response.ok? + raise StandardError, "Unable to get `#{path}`. Got `#{response.code}`." unless response.ok? response.json end diff --git a/lib/instana/snapshot/google_cloud_run_instance.rb b/lib/instana/snapshot/google_cloud_run_instance.rb index 2e8f40bfd..0e71a083d 100644 --- a/lib/instana/snapshot/google_cloud_run_instance.rb +++ b/lib/instana/snapshot/google_cloud_run_instance.rb @@ -60,7 +60,7 @@ def lookup(resource) path = @metadata_uri.path + resource response = @client.send_request('GET', path, nil, {'Metadata-Flavor' => 'Google'}) - raise "Unable to get `#{path}`. Got `#{response.code}` `#{response['location']}`." unless response.ok? + raise StandardError, "Unable to get `#{path}`. Got `#{response.code}` `#{response['location']}`." unless response.ok? response.body end diff --git a/lib/instana/snapshot/google_cloud_run_process.rb b/lib/instana/snapshot/google_cloud_run_process.rb index dc60d2601..7d2c5d397 100644 --- a/lib/instana/snapshot/google_cloud_run_process.rb +++ b/lib/instana/snapshot/google_cloud_run_process.rb @@ -49,7 +49,7 @@ def lookup(resource) path = @metadata_uri.path + resource response = @client.send_request('GET', path, nil, {'Metadata-Flavor' => 'Google'}) - raise "Unable to get `#{path}`. Got `#{response.code}` `#{response['location']}`." unless response.ok? + raise StandardError, "Unable to get `#{path}`. Got `#{response.code}` `#{response['location']}`." unless response.ok? response.body end diff --git a/lib/instana/span_filtering.rb b/lib/instana/span_filtering.rb index 30a551a61..fb0a05c6e 100644 --- a/lib/instana/span_filtering.rb +++ b/lib/instana/span_filtering.rb @@ -32,20 +32,15 @@ def filter_span(span) return nil unless @configuration # Check include rules first (whitelist) - if @configuration.include_rules.any? - # If we have include rules, only keep spans that match at least one include rule - unless @configuration.include_rules.any? { |rule| rule.matches?(span) } - return { filtered: true, suppression: false } - end - # If it matches an include rule, continue to exclude rules + # If we have include rules, only keep spans that match at least one include rule + include_rules = @configuration.include_rules + if include_rules.any? && include_rules.none? { |rule| rule.matches?(span) } + return { filtered: true, suppression: false } end # Check exclude rules (blacklist) - @configuration.exclude_rules.each do |rule| - if rule.matches?(span) - return { filtered: true, suppression: rule.suppression } - end - end + excluded_by = @configuration.exclude_rules.find { |rule| rule.matches?(span) } + return { filtered: true, suppression: excluded_by.suppression } if excluded_by nil # Keep the span if no rules match end diff --git a/lib/instana/trace/processor.rb b/lib/instana/trace/processor.rb index 582a39edc..5f14c3471 100644 --- a/lib/instana/trace/processor.rb +++ b/lib/instana/trace/processor.rb @@ -63,7 +63,7 @@ def span_metrics # # Sends all traces in @queue to the host agent # - # FIXME: Add limits checking here in regards to: + # Known gaps: limits checking is missing in regards to: # - Max HTTP Post size # - Out of control/growing queue # - Prevent another run of the timer while this is running diff --git a/lib/instana/trace/span.rb b/lib/instana/trace/span.rb index 4d6d45e1d..fbac71228 100644 --- a/lib/instana/trace/span.rb +++ b/lib/instana/trace/span.rb @@ -520,7 +520,7 @@ def add_link(_link) # # @return [self] returns itself # Todo Add the vent logic later - def add_event(_name, attributes: nil, timestamp: nil) # rubocop:disable Lint/UnusedMethodArgument + def add_event(_name, **) self end diff --git a/test/backend/host_agent_reporting_observer_test.rb b/test/backend/host_agent_reporting_observer_test.rb index 39c98bf00..3d5bf83c8 100644 --- a/test/backend/host_agent_reporting_observer_test.rb +++ b/test/backend/host_agent_reporting_observer_test.rb @@ -281,7 +281,7 @@ def test_report_standard_error processor = Class.new do def send - raise 'Standard Error' + raise StandardError, 'Standard Error' end end.new diff --git a/test/benchmarks/bench_id_generation.rb b/test/benchmarks/bench_id_generation.rb index 3582b2208..cd108913e 100644 --- a/test/benchmarks/bench_id_generation.rb +++ b/test/benchmarks/bench_id_generation.rb @@ -6,7 +6,7 @@ class BenchIDs < Minitest::Benchmark def bench_generate_id # TODO: This performs poorly on JRuby. - assert_performance_constant do |input| + assert_performance_constant do |_input| 500_000.times do ::Instana::Util.generate_id end diff --git a/test/benchmarks/bench_opentracing.rb b/test/benchmarks/bench_opentracing.rb index bbd511dd7..5d25dfd0f 100644 --- a/test/benchmarks/bench_opentracing.rb +++ b/test/benchmarks/bench_opentracing.rb @@ -5,7 +5,7 @@ class BenchOpenTracing < Minitest::Benchmark def bench_start_finish_span - assert_performance_constant do |input| + assert_performance_constant do |_input| 10_000.times do span = ::Instana.tracer.start_span(:blah) span.set_tag(:zero, 0) diff --git a/test/instrumentation/dalli_test.rb b/test/instrumentation/dalli_test.rb index b3471cc6d..73703bda5 100644 --- a/test/instrumentation/dalli_test.rb +++ b/test/instrumentation/dalli_test.rb @@ -300,7 +300,8 @@ def test_get_error_logging ::Instana.tracer.in_span(:dalli_test) do result = broken_dc.get(:instana) end - rescue + rescue StandardError + # The error is expected; the resulting spans are asserted below end spans = ::Instana.processor.queued_spans diff --git a/test/instrumentation/graphql_test.rb b/test/instrumentation/graphql_test.rb index 190987859..74a2ed94b 100644 --- a/test/instrumentation/graphql_test.rb +++ b/test/instrumentation/graphql_test.rb @@ -25,7 +25,7 @@ def self.resolve_type(object, _context) elsif !object.description? JobType else - raise("Unexpected object: #{object}") + raise(StandardError, "Unexpected object: #{object}") end end end diff --git a/test/instrumentation/grpc_test.rb b/test/instrumentation/grpc_test.rb index 5e7f73288..24374941e 100644 --- a/test/instrumentation/grpc_test.rb +++ b/test/instrumentation/grpc_test.rb @@ -255,7 +255,8 @@ def test_request_response_failure Instana.tracer.in_span(:rpctests) do begin client_stub.fail_to_ping( PingPongService::PingRequest.new(message: 'Hello World')) - rescue + rescue StandardError + # The error is expected; the resulting spans are asserted below end end @@ -299,7 +300,8 @@ def test_client_streamer_failure PingPongService::PingRequest.new(message: index.to_s) end ) - rescue + rescue StandardError + # The error is expected; the resulting spans are asserted below end end @@ -342,7 +344,8 @@ def test_server_streamer_failure client_stub.fail_to_ping_with_server_stream( PingPongService::PingRequest.new(message: 'Hello World') ) - rescue + rescue StandardError + # The error is expected; the resulting spans are asserted below end end diff --git a/test/instrumentation/rack_test.rb b/test/instrumentation/rack_test.rb index 9b9802999..21a61b868 100644 --- a/test/instrumentation/rack_test.rb +++ b/test/instrumentation/rack_test.rb @@ -23,7 +23,7 @@ def call(env) class ErrorApp def call(_env) - raise 'An Error' + raise StandardError, 'An Error' end end diff --git a/test/instrumentation/redis_test.rb b/test/instrumentation/redis_test.rb index 93c52f584..e34f0d145 100644 --- a/test/instrumentation/redis_test.rb +++ b/test/instrumentation/redis_test.rb @@ -63,7 +63,8 @@ def test_normal_call_with_error Instana.tracer.in_span(:redis_test) do begin @redis_client.zadd('hello', 'invalid', 'value') - rescue + rescue StandardError + # The error is expected; the resulting spans are asserted below end end @@ -92,7 +93,8 @@ def test_pipeline_call_with_error pipeline.set('other', 'world') pipeline.call('invalid') end - rescue + rescue StandardError + # The error is expected; the resulting spans are asserted below end end @@ -121,7 +123,8 @@ def test_multi_call_with_error multi.set('other', 'world') multi.call('invalid') end - rescue + rescue StandardError + # The error is expected; the resulting spans are asserted below end end diff --git a/test/instrumentation/sidekiq-client_test.rb b/test/instrumentation/sidekiq-client_test.rb index d5478f818..45eef50eb 100644 --- a/test/instrumentation/sidekiq-client_test.rb +++ b/test/instrumentation/sidekiq-client_test.rb @@ -168,7 +168,7 @@ def assert_failure_trace_recorded SidekiqMiddlewareException = Class.new do def call(*_args) - raise 'Fail to enqueue job' + raise StandardError, 'Fail to enqueue job' end end diff --git a/test/support/apps/grpc/grpc_server.rb b/test/support/apps/grpc/grpc_server.rb index 557b2e5b5..9338e9e21 100644 --- a/test/support/apps/grpc/grpc_server.rb +++ b/test/support/apps/grpc/grpc_server.rb @@ -66,7 +66,7 @@ class Service end class PingPongServer < PingPongService::Service - def ping(ping_request, active_call) + def ping(ping_request, _active_call) PingPongService::PongReply.new(message: "Hello #{ping_request.message}") end @@ -78,7 +78,7 @@ def ping_with_client_stream(active_call) PingPongService::PongReply.new(message: message) end - def ping_with_server_stream(ping_request, active_call) + def ping_with_server_stream(_ping_request, _active_call) (0..5).map do |index| PingPongService::PongReply.new(message: index.to_s) end @@ -91,18 +91,18 @@ def ping_with_bidi_stream(ping_requests) end def fail_to_ping(ping_request, active_call) - raise 'Unexpected failed' + raise StandardError, 'Unexpected failed' end def fail_to_ping_with_client_stream(active_call) - raise 'Unexpected failed' + raise StandardError, 'Unexpected failed' end def fail_to_ping_with_server_stream(ping_request, active_call) - raise 'Unexpected failed' + raise StandardError, 'Unexpected failed' end def fail_to_ping_with_bidi_stream(ping_requests) - raise 'Unexpected failed' + raise StandardError, 'Unexpected failed' end end diff --git a/test/support/apps/http_endpoint/boot.rb b/test/support/apps/http_endpoint/boot.rb index 6a932764e..8b3644bab 100644 --- a/test/support/apps/http_endpoint/boot.rb +++ b/test/support/apps/http_endpoint/boot.rb @@ -11,18 +11,18 @@ app = Rack::Builder.new { use ::Instana::Rack map "/" do - run Proc.new { |env| + run Proc.new { |_env| [200, {"Content-Type" => "application/json"}, ["[\"Stan\",\"is\",\"on\",\"the\",\"scene!\"]"]] } end map "/error" do - run Proc.new { |env| + run Proc.new { |_env| [500, {"Content-Type" => "application/json"}, ["[\"Stan\",\"is\",\"on\",\"the\",\"error!\"]"]] } end # Returns any status code supplied as the last path segment, e.g. /status/401 map "/status" do - run Proc.new { |env| + run Proc.new { |_env| code = env['PATH_INFO'].split('/').last.to_i code = 200 if code < 100 || code > 599 [code, {"Content-Type" => "application/json"}, ["[\"status\",#{code}]"]] diff --git a/test/support/apps/rails/models/block.rb b/test/support/apps/rails/models/block.rb index 20dc50d02..648bc438d 100644 --- a/test/support/apps/rails/models/block.rb +++ b/test/support/apps/rails/models/block.rb @@ -2,7 +2,7 @@ # (c) Copyright Instana Inc. 2017 class Block < ActiveRecord::Base - def do_work(*args) + def do_work(*) block = Block.first block.name = "Charlie" block.color = "Black" diff --git a/test/support/apps/rails/models/block6.rb b/test/support/apps/rails/models/block6.rb index ab565b13c..c3c2003fb 100644 --- a/test/support/apps/rails/models/block6.rb +++ b/test/support/apps/rails/models/block6.rb @@ -2,7 +2,7 @@ # (c) Copyright Instana Inc. 2017 class Block < ActiveRecord::Base - def do_work(*args) + def do_work(*) block = Block.first block.name = "Charlie" block.color = "Black" diff --git a/test/support/apps/resque/jobs/resque_fast_job.rb b/test/support/apps/resque/jobs/resque_fast_job.rb index d1c532403..ab8f70c43 100644 --- a/test/support/apps/resque/jobs/resque_fast_job.rb +++ b/test/support/apps/resque/jobs/resque_fast_job.rb @@ -8,7 +8,7 @@ class FastJob @queue = :critical def self.perform(*args) - raise 'Invalid Args' unless args.empty? + raise ArgumentError, 'Invalid Args' unless args.empty? if ENV.key?('REDIS_URL') redis = Redis.new(:url => ENV['REDIS_URL']) diff --git a/test/support/apps/sidekiq/jobs/sidekiq_job_2.rb b/test/support/apps/sidekiq/jobs/sidekiq_job_2.rb index 87f22f29b..9d381eebd 100644 --- a/test/support/apps/sidekiq/jobs/sidekiq_job_2.rb +++ b/test/support/apps/sidekiq/jobs/sidekiq_job_2.rb @@ -5,6 +5,6 @@ class SidekiqJobTwo include Sidekiq::Worker def perform(a, b, c) - raise 'Fail to execute the job' + raise StandardError, 'Fail to execute the job' end end diff --git a/test/support/helpers.rb b/test/support/helpers.rb index 432abd284..64e57a93b 100644 --- a/test/support/helpers.rb +++ b/test/support/helpers.rb @@ -47,22 +47,26 @@ def find_spans_by_name(spans, name) end def find_first_span_by_name(spans, name) - spans.each do |span| - case span[:n] + span = spans.find do |candidate| + case candidate[:n] when :sdk - return span if span[:data][:sdk][:name] == name + candidate[:data][:sdk][:name] == name when name - return span + true + else + false end end - raise StandardError, "Span (#{name}) not found" + raise StandardError, "Span (#{name}) not found" unless span + + span end def find_span_by_id(spans, id) - spans.each do |span| - return span if span[:s] == id - end - raise StandardError, "Span with id (#{id}) not found" + span = spans.find { |candidate| candidate[:s] == id } + raise StandardError, "Span with id (#{id}) not found" unless span + + span end # Finds the first span in +spans+ for which +block+ returns true @@ -76,10 +80,10 @@ def find_span_by_id(spans, id) # +spans+: +Array+ of spans to search # +block+: The Ruby block to evaluate against each span def find_first_span_by_qualifier(spans, &block) - spans.each do |span| - return span if block.call(span) - end - raise StandardError, 'Span with qualifier not found' + span = spans.find(&block) + raise StandardError, 'Span with qualifier not found' unless span + + span end end end diff --git a/test/trace/custom_test.rb b/test/trace/custom_test.rb index 2b263874c..6affd98ca 100644 --- a/test/trace/custom_test.rb +++ b/test/trace/custom_test.rb @@ -179,7 +179,7 @@ def test_custom_tracing_with_error # rubocop:disable Metrics/MethodLength kvs[:return] = true span2 = ::Instana.tracer.start_span(:custom_span, attributes: kvs) - raise "custom tracing error. This is only a test" + raise StandardError, "custom tracing error. This is only a test" rescue => e span2.record_exception(e) ensure diff --git a/test/trace/tracer_provider_test.rb b/test/trace/tracer_provider_test.rb index cc79e140d..2bbe2bd53 100644 --- a/test/trace/tracer_provider_test.rb +++ b/test/trace/tracer_provider_test.rb @@ -110,39 +110,22 @@ def test_add_span_processor_after_shutdown assert_equal 1, @tracer_provider.instance_variable_get(:@span_processors).length end - def test_internal_start_span_untraced + # Todo add proper testcases for the untraced, traced and stopped scenarios + def test_internal_start_span @tracer_provider = ::Instana::Trace::TracerProvider.new - Minitest::Mock.new result = @tracer_provider.internal_start_span('test_span', 'kind', {}, [], Time.now, nil, @instrumentation_scope) assert_instance_of(Instana::Span, result) - # Todo add proper testcase - end - - def test_internal_start_span_traced - @tracer_provider = ::Instana::Trace::TracerProvider.new - Minitest::Mock.new - result = @tracer_provider.internal_start_span('test_span', 'kind', {}, [], Time.now, nil, @instrumentation_scope) - assert_instance_of(Instana::Span, result) - # Todo add proper testcase - end - - def test_internal_start_span_stopped - @tracer_provider = ::Instana::Trace::TracerProvider.new - Minitest::Mock.new - result = @tracer_provider.internal_start_span('test_span', 'kind', {}, [], Time.now, nil, @instrumentation_scope) - assert_instance_of(Instana::Span, result) - # Todo add proper testcase end end class DummyProcessor def initialize; end - def shutdown(timeout: nil) # rubocop:disable Lint/UnusedMethodArgument + def shutdown(**) Instana::Trace::Export::SUCCESS end - def force_flush(timeout: nil) # rubocop:disable Lint/UnusedMethodArgument + def force_flush(**) Instana::Trace::Export::SUCCESS end end