Loading spec/labkit/tracing/rails/action_view/render_collection_instrumenter_spec.rb +13 −20 Original line number Diff line number Diff line require_relative "../../../../support/tracing/rails/shared_examples" describe Labkit::Tracing::Rails::ActiveRecord::SqlInstrumenter do describe Labkit::Tracing::Rails::ActionView::RenderCollectionInstrumenter do using RSpec::Parameterized::TableSyntax where(:name, :operation_name, :exception, :connection_id, :cached, :cached_response, :sql) do nil | "active_record:sqlquery" | nil | nil | nil | false | nil "" | "active_record:sqlquery" | nil | nil | nil | false | nil "User Load" | "active_record:User Load" | nil | nil | nil | false | nil "Repo Load" | "active_record:Repo Load" | StandardError.new | nil | nil | false | nil nil | "active_record:sqlquery" | nil | 123 | nil | false | nil nil | "active_record:sqlquery" | nil | nil | false | false | nil nil | "active_record:sqlquery" | nil | nil | true | true | nil nil | "active_record:sqlquery" | nil | nil | true | true | "SELECT * FROM users" where(:identifier, :count, :expected_count, :cache_hits, :expected_cache_hits, :exception) do nil | nil | 0 | nil | 0 | nil "" | nil | 0 | nil | 0 | nil "show.haml" | nil | 0 | nil | 0 | nil nil | 0 | 0 | nil | 0 | nil nil | 1 | 1 | nil | 0 | nil nil | nil | 0 | 0 | 0 | nil nil | nil | 0 | 1 | 1 | nil nil | nil | 0 | nil | 0 | StandardError.new end with_them do it_behaves_like "a tracing instrumenter" do let(:expected_span_name) { operation_name } let(:payload) { { name: name, exception: exception, connection_id: connection_id, cached: cached, sql: sql } } let(:expected_span_name) { "render_collection" } let(:payload) { { exception: exception, identifier: identifier, count: count, cache_hits: cache_hits } } let(:expected_tags) do { "component" => "ActiveRecord", "span.kind" => "client", "db.type" => "sql", "db.connection_id" => connection_id, "db.cached" => cached_response, "db.statement" => sql, } { "component" => "ActionView", "template.id" => identifier, "template.count" => expected_count, "template.cache.hits" => expected_cache_hits } end end end Loading spec/labkit/tracing/rails/active_record/sql_instrumenter_spec.rb +23 −13 Original line number Diff line number Diff line require_relative "../../../../support/tracing/rails/shared_examples" describe Labkit::Tracing::Rails::ActionView::RenderCollectionInstrumenter do describe Labkit::Tracing::Rails::ActiveRecord::SqlInstrumenter do using RSpec::Parameterized::TableSyntax where(:identifier, :count, :expected_count, :cache_hits, :expected_cache_hits, :exception) do nil | nil | 0 | nil | 0 | nil "" | nil | 0 | nil | 0 | nil "show.haml" | nil | 0 | nil | 0 | nil nil | 0 | 0 | nil | 0 | nil nil | 1 | 1 | nil | 0 | nil nil | nil | 0 | 0 | 0 | nil nil | nil | 0 | 1 | 1 | nil nil | nil | 0 | nil | 0 | StandardError.new where(:name, :operation_name, :exception, :connection_id, :cached, :cached_response, :sql, :expected_sql, :tracing_sampled) do nil | "active_record:sqlquery" | nil | nil | nil | false | nil | nil | true "" | "active_record:sqlquery" | nil | nil | nil | false | nil | nil | true "User Load" | "active_record:User Load" | nil | nil | nil | false | nil | nil | true "Repo Load" | "active_record:Repo Load" | StandardError.new | nil | nil | false | nil | nil | true nil | "active_record:sqlquery" | nil | 123 | nil | false | nil | nil | true nil | "active_record:sqlquery" | nil | nil | false | false | nil | nil | true nil | "active_record:sqlquery" | nil | nil | true | true | nil | nil | true nil | "active_record:sqlquery" | nil | nil | true | true | "SELECT * FROM users" | "SELECT * FROM users" | true nil | "active_record:sqlquery" | nil | nil | true | true | "SELECT 42" | "SELECT $1" | true nil | "active_record:sqlquery" | nil | nil | true | true | "SELECT 42" | nil | false end with_them do it_behaves_like "a tracing instrumenter" do let(:expected_span_name) { "render_collection" } let(:payload) { { exception: exception, identifier: identifier, count: count, cache_hits: cache_hits } } let(:expected_span_name) { operation_name } let(:payload) { { name: name, exception: exception, connection_id: connection_id, cached: cached, sql: sql } } let(:expected_tags) do { "component" => "ActionView", "template.id" => identifier, "template.count" => expected_count, "template.cache.hits" => expected_cache_hits } { "component" => "ActiveRecord", "span.kind" => "client", "db.type" => "sql", "db.connection_id" => connection_id, "db.cached" => cached_response, "db.statement" => expected_sql, } end let(:sampled) { tracing_sampled } end end end spec/support/tracing/rails/shared_examples.rb +2 −1 Original line number Diff line number Diff line Loading @@ -5,11 +5,12 @@ RSpec.shared_examples "a tracing instrumenter" do let(:fake_span) { double("OpenTracing span") } let(:fake_scope) { double("OpenTracing scope", span: fake_span) } let(:sampled) { true } before do instrumenter.scope_stack.clear allow(Labkit::Tracing).to receive(:sampled?).and_return(true) allow(Labkit::Tracing).to receive(:sampled?).and_return(sampled) end describe "#start" do Loading Loading
spec/labkit/tracing/rails/action_view/render_collection_instrumenter_spec.rb +13 −20 Original line number Diff line number Diff line require_relative "../../../../support/tracing/rails/shared_examples" describe Labkit::Tracing::Rails::ActiveRecord::SqlInstrumenter do describe Labkit::Tracing::Rails::ActionView::RenderCollectionInstrumenter do using RSpec::Parameterized::TableSyntax where(:name, :operation_name, :exception, :connection_id, :cached, :cached_response, :sql) do nil | "active_record:sqlquery" | nil | nil | nil | false | nil "" | "active_record:sqlquery" | nil | nil | nil | false | nil "User Load" | "active_record:User Load" | nil | nil | nil | false | nil "Repo Load" | "active_record:Repo Load" | StandardError.new | nil | nil | false | nil nil | "active_record:sqlquery" | nil | 123 | nil | false | nil nil | "active_record:sqlquery" | nil | nil | false | false | nil nil | "active_record:sqlquery" | nil | nil | true | true | nil nil | "active_record:sqlquery" | nil | nil | true | true | "SELECT * FROM users" where(:identifier, :count, :expected_count, :cache_hits, :expected_cache_hits, :exception) do nil | nil | 0 | nil | 0 | nil "" | nil | 0 | nil | 0 | nil "show.haml" | nil | 0 | nil | 0 | nil nil | 0 | 0 | nil | 0 | nil nil | 1 | 1 | nil | 0 | nil nil | nil | 0 | 0 | 0 | nil nil | nil | 0 | 1 | 1 | nil nil | nil | 0 | nil | 0 | StandardError.new end with_them do it_behaves_like "a tracing instrumenter" do let(:expected_span_name) { operation_name } let(:payload) { { name: name, exception: exception, connection_id: connection_id, cached: cached, sql: sql } } let(:expected_span_name) { "render_collection" } let(:payload) { { exception: exception, identifier: identifier, count: count, cache_hits: cache_hits } } let(:expected_tags) do { "component" => "ActiveRecord", "span.kind" => "client", "db.type" => "sql", "db.connection_id" => connection_id, "db.cached" => cached_response, "db.statement" => sql, } { "component" => "ActionView", "template.id" => identifier, "template.count" => expected_count, "template.cache.hits" => expected_cache_hits } end end end Loading
spec/labkit/tracing/rails/active_record/sql_instrumenter_spec.rb +23 −13 Original line number Diff line number Diff line require_relative "../../../../support/tracing/rails/shared_examples" describe Labkit::Tracing::Rails::ActionView::RenderCollectionInstrumenter do describe Labkit::Tracing::Rails::ActiveRecord::SqlInstrumenter do using RSpec::Parameterized::TableSyntax where(:identifier, :count, :expected_count, :cache_hits, :expected_cache_hits, :exception) do nil | nil | 0 | nil | 0 | nil "" | nil | 0 | nil | 0 | nil "show.haml" | nil | 0 | nil | 0 | nil nil | 0 | 0 | nil | 0 | nil nil | 1 | 1 | nil | 0 | nil nil | nil | 0 | 0 | 0 | nil nil | nil | 0 | 1 | 1 | nil nil | nil | 0 | nil | 0 | StandardError.new where(:name, :operation_name, :exception, :connection_id, :cached, :cached_response, :sql, :expected_sql, :tracing_sampled) do nil | "active_record:sqlquery" | nil | nil | nil | false | nil | nil | true "" | "active_record:sqlquery" | nil | nil | nil | false | nil | nil | true "User Load" | "active_record:User Load" | nil | nil | nil | false | nil | nil | true "Repo Load" | "active_record:Repo Load" | StandardError.new | nil | nil | false | nil | nil | true nil | "active_record:sqlquery" | nil | 123 | nil | false | nil | nil | true nil | "active_record:sqlquery" | nil | nil | false | false | nil | nil | true nil | "active_record:sqlquery" | nil | nil | true | true | nil | nil | true nil | "active_record:sqlquery" | nil | nil | true | true | "SELECT * FROM users" | "SELECT * FROM users" | true nil | "active_record:sqlquery" | nil | nil | true | true | "SELECT 42" | "SELECT $1" | true nil | "active_record:sqlquery" | nil | nil | true | true | "SELECT 42" | nil | false end with_them do it_behaves_like "a tracing instrumenter" do let(:expected_span_name) { "render_collection" } let(:payload) { { exception: exception, identifier: identifier, count: count, cache_hits: cache_hits } } let(:expected_span_name) { operation_name } let(:payload) { { name: name, exception: exception, connection_id: connection_id, cached: cached, sql: sql } } let(:expected_tags) do { "component" => "ActionView", "template.id" => identifier, "template.count" => expected_count, "template.cache.hits" => expected_cache_hits } { "component" => "ActiveRecord", "span.kind" => "client", "db.type" => "sql", "db.connection_id" => connection_id, "db.cached" => cached_response, "db.statement" => expected_sql, } end let(:sampled) { tracing_sampled } end end end
spec/support/tracing/rails/shared_examples.rb +2 −1 Original line number Diff line number Diff line Loading @@ -5,11 +5,12 @@ RSpec.shared_examples "a tracing instrumenter" do let(:fake_span) { double("OpenTracing span") } let(:fake_scope) { double("OpenTracing scope", span: fake_span) } let(:sampled) { true } before do instrumenter.scope_stack.clear allow(Labkit::Tracing).to receive(:sampled?).and_return(true) allow(Labkit::Tracing).to receive(:sampled?).and_return(sampled) end describe "#start" do Loading