# frozen_string_literal: true require "rack/mock" module Appsignal # {Appsignal::Demo} is a way to send demonstration / test samples for a # exception and a performance issue. # # @example Send example transactions # Appsignal::Demo.transmit # # @since 2.0.0 # @see Appsignal::CLI::Demo # @api private class Demo # Error type used to create demonstration exception. class TestError < StandardError; end class << self # Starts AppSignal and transmits the demonstration samples to AppSignal # using the loaded configuration. # # @return [Boolean] # - returns `false` if Appsignal is not active. def transmit Appsignal.start return false unless Appsignal.active? create_example_error_request create_example_performance_request true end private def create_example_error_request transaction = Appsignal::Transaction.create(Appsignal::Transaction::HTTP_REQUEST) begin raise TestError, "Hello world! This is an error used for demonstration purposes." rescue => error Appsignal.set_error(error) end add_params_to(transaction) add_headers_to(transaction) transaction.set_metadata("path", "/hello") transaction.set_metadata("method", "GET") transaction.set_action("DemoController#hello") add_demo_metadata_to transaction Appsignal::Transaction.complete_current! end def create_example_performance_request transaction = Appsignal::Transaction.create(Appsignal::Transaction::HTTP_REQUEST) Appsignal.instrument "action_view.render", "Render hello.html.erb", "