-
Notifications
You must be signed in to change notification settings - Fork 81
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add appsignal.demo task As currently present in our Ruby gem as well: appsignal/appsignal-ruby#199 The "appsignal.demo" command is useful for debugging AppSignal and testing AppSignal. It sends a demonstration sample for an error and a performance issue. They will show up on AppSignal.com as demonstration samples with a small special UI attached to them describing their purpose. Debugging manual referencing the "demo" command: http://docs.appsignal.com/support/debugging.html * Use Application.ensure_all_started/1 in demo task * Remove Appsignal.Demo.transmit/0, move calls to mix task * Don't use ErrorHandler.format_stack/1 in Demo * Pipe transaction through functions in Demo.create_transaction_error_request * Wrap environment data in an environment map in Demo * Print message after sending demo data * Link to the full URL in the demo task * Fix Elixir 1.4 compilation warnings
- Loading branch information
Showing
6 changed files
with
99 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
defmodule Appsignal.Demo do | ||
import Appsignal.Instrumentation.Helpers, only: [instrument: 4] | ||
|
||
@doc false | ||
def create_transaction_error_request do | ||
create_demo_transaction() | ||
|> Appsignal.Transaction.set_error( | ||
"TestError", | ||
"Hello world! This is an error used for demonstration purposes.", | ||
System.stacktrace | ||
) | ||
|> finish_demo_transaction() | ||
end | ||
|
||
@doc false | ||
def create_transaction_performance_request do | ||
transaction = create_demo_transaction() | ||
|
||
instrument(transaction, "template.render", "Rendering something slow", fn() -> | ||
:timer.sleep(1000) | ||
instrument(transaction, "ecto.query", "Slow query", fn() -> | ||
:timer.sleep(300) | ||
end) | ||
instrument(transaction, "ecto.query", "Slow query", fn() -> | ||
:timer.sleep(500) | ||
end) | ||
instrument(transaction, "template.render", "Rendering something slow", fn() -> | ||
:timer.sleep(100) | ||
end) | ||
end) | ||
|
||
finish_demo_transaction(transaction) | ||
end | ||
|
||
defp create_demo_transaction do | ||
Appsignal.Transaction.start( | ||
Appsignal.Transaction.generate_id, | ||
:http_request | ||
) | ||
|> Appsignal.Transaction.set_action("DemoController#hello") | ||
|> Appsignal.Transaction.set_meta_data("demo_sample", "true") | ||
|> Appsignal.Transaction.set_sample_data( | ||
"environment", %{request_path: "/hello", method: "GET"} | ||
) | ||
end | ||
|
||
defp finish_demo_transaction(transaction) do | ||
Appsignal.Transaction.finish(transaction) | ||
:ok = Appsignal.Transaction.complete(transaction) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
defmodule Mix.Tasks.Appsignal.Demo do | ||
require Logger | ||
use Mix.Task | ||
|
||
@shortdoc "Perform and send a demonstration error and performance issue to AppSignal." | ||
|
||
def run(_args) do | ||
{:ok, _} = Application.ensure_all_started(:appsignal) | ||
Appsignal.Demo.create_transaction_performance_request | ||
Appsignal.Demo.create_transaction_error_request | ||
Appsignal.stop(nil) | ||
Logger.info("Demonstration sample data sent!") | ||
Logger.info("It may take about a minute for the data to appear on https://appsignal.com/accounts") | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
defmodule AppsignalDemoTest do | ||
use ExUnit.Case | ||
import Mock | ||
alias Appsignal.{Transaction, TransactionRegistry} | ||
|
||
test_with_mock "sends a demonstration error", Appsignal.Transaction, [:passthrough], [] do | ||
Appsignal.Demo.create_transaction_error_request | ||
|
||
t = %Transaction{} = TransactionRegistry.lookup(self()) | ||
assert called Appsignal.Transaction.set_action(t, "DemoController#hello") | ||
assert called Appsignal.Transaction.set_error(t, "TestError", "Hello world! This is an error used for demonstration purposes.", []) | ||
assert called Appsignal.Transaction.set_meta_data(t, "demo_sample", "true") | ||
assert called Appsignal.Transaction.finish(t) | ||
assert called Appsignal.Transaction.complete(t) | ||
end | ||
|
||
test_with_mock "sends a performance issue", Appsignal.Transaction, [:passthrough], [] do | ||
Appsignal.Demo.create_transaction_performance_request | ||
|
||
t = %Transaction{} = TransactionRegistry.lookup(self()) | ||
assert called Appsignal.Transaction.set_action(t, "DemoController#hello") | ||
assert called Appsignal.Transaction.set_meta_data(t, "demo_sample", "true") | ||
assert called Appsignal.Transaction.start_event(t) | ||
assert called Appsignal.Transaction.finish_event(t, "template.render", "Rendering something slow", "", 0) | ||
assert called Appsignal.Transaction.finish(t) | ||
assert called Appsignal.Transaction.complete(t) | ||
end | ||
end |