Skip to content

Commit 1375eeb

Browse files
committed
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 25bde21 commit 1375eeb

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
@@ -3959,7 +3959,8 @@ def exception_event
39593959
)
39603960
end
39613961

3962-
it "does not keep error causes from previously set errors" do
3962+
it "does not keep error causes from previously set errors", :agent_mode do
3963+
start_agent(**start_agent_args)
39633964
transaction.send(:_set_error, error)
39643965
transaction.send(:_set_error, error_without_cause)
39653966

@@ -3972,6 +3973,24 @@ def exception_event
39723973
expect(transaction).to include_error_causes([])
39733974
end
39743975

3976+
it "records no causes for a later cause-less error in collector mode",
3977+
:collector_mode do
3978+
start_collector_agent
3979+
transaction.send(:_set_error, error)
3980+
transaction.send(:_set_error, error_without_cause)
3981+
transaction.complete
3982+
3983+
# Collector mode records each error as its own exception event rather
3984+
# than overwriting, so the later cause-less error's event carries no
3985+
# causes; the earlier error's causes do not leak onto it.
3986+
events = Array(root_span.events).select { |event| event.name == "exception" }
3987+
without_cause = events.find do |event|
3988+
event.attributes["exception.message"] == "error without cause"
3989+
end
3990+
expect(without_cause).not_to be_nil
3991+
expect(without_cause.attributes).not_to have_key("appsignal.error_causes")
3992+
end
3993+
39753994
describe "with app paths" do
39763995
let(:root_path) { project_fixture_path }
39773996
let(:error) do

0 commit comments

Comments
 (0)