Skip to content

Commit e03b091

Browse files
authored
Dual-mode transaction and helper spec coverage
Audit of the transaction and helper specs for behaviors covered in only one mode, agent or collector, that should be covered in both. Most gaps were agent-only leftovers that assert through `to_h`-based matchers, which do nothing in collector mode. Fold the two send_error block specs into one dual-moded spec. It sets an active transaction, calls `send_error` with a block, and checks the block's metadata and the error land on `send_error`'s own transaction while the active one is restored and left untouched. In collector mode this confirms the active trace continues rather than being dropped or left open. Cover more behaviors in both modes: the `set_error` and `report_error` blocks, `set_empty_params!`, the `add_params`, `add_session_data`, `add_headers` and `add_custom_data` merge and block variants, `set_action` and `set_namespace` setting the value, `report_error` not completing the active transaction, and a transaction that reports a cause-less error after one with causes. Also add the one missing collector metric-coercion case, a symbol metric name, to the OpenTelemetry metrics backend spec.
1 parent b260823 commit e03b091

3 files changed

Lines changed: 445 additions & 120 deletions

File tree

spec/lib/appsignal/metrics/opentelemetry_backend_spec.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,14 @@ def snapshot_for(name)
4646
snapshot = snapshot_for("my_gauge")
4747
expect(snapshot.data_points.first.value).to eq(10.0)
4848
end
49+
50+
it "coerces a symbol metric name to a string" do
51+
described_class.set_gauge(:my_gauge, 1.0, {})
52+
53+
# snapshot_for matches on the string name, so this only finds the
54+
# snapshot if the symbol name was coerced.
55+
expect(snapshot_for("my_gauge")).not_to be_nil
56+
end
4957
end
5058

5159
describe ".increment_counter" do

spec/lib/appsignal/transaction_spec.rb

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3943,7 +3943,8 @@ def exception_event
39433943
)
39443944
end
39453945

3946-
it "does not keep error causes from previously set errors" do
3946+
it "does not keep error causes from previously set errors", :agent_mode do
3947+
start_agent(**start_agent_args)
39473948
transaction.send(:_set_error, error)
39483949
transaction.send(:_set_error, error_without_cause)
39493950

@@ -3956,6 +3957,24 @@ def exception_event
39563957
expect(transaction).to include_error_causes([])
39573958
end
39583959

3960+
it "records no causes for a later cause-less error in collector mode",
3961+
:collector_mode do
3962+
start_collector_agent
3963+
transaction.send(:_set_error, error)
3964+
transaction.send(:_set_error, error_without_cause)
3965+
transaction.complete
3966+
3967+
# Collector mode records each error as its own exception event rather
3968+
# than overwriting, so the later cause-less error's event carries no
3969+
# causes; the earlier error's causes do not leak onto it.
3970+
events = Array(root_span.events).select { |event| event.name == "exception" }
3971+
without_cause = events.find do |event|
3972+
event.attributes["exception.message"] == "error without cause"
3973+
end
3974+
expect(without_cause).not_to be_nil
3975+
expect(without_cause.attributes).not_to have_key("appsignal.error_causes")
3976+
end
3977+
39593978
describe "with app paths" do
39603979
let(:root_path) { project_fixture_path }
39613980
let(:error) do

0 commit comments

Comments
 (0)