Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use :channels namespace in Appsignal.Phoenix.Channel #197

Merged
merged 1 commit into from
Apr 11, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/appsignal/phoenix/channel.ex
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ if Appsignal.phoenix? do
def channel_action(module, name, %Phoenix.Socket{} = socket, function) do
alias Appsignal.Transaction

transaction = Transaction.start(Transaction.generate_id(), :background_job)
transaction = Transaction.start(Transaction.generate_id(), :channel)

action_str = "#{module}##{name}"
<<"Elixir.", action :: binary>> = action_str
Expand Down
20 changes: 5 additions & 15 deletions lib/appsignal/transaction.ex
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
defmodule Appsignal.TransactionBehaviour do
@type namespace :: :http_request | :background_job

@callback start(String.t, namespace) :: Appsignal.Transaction.t
@callback start(String.t, String.t) :: Appsignal.Transaction.t
@callback start_event() :: Appsignal.Transaction.t
@callback finish_event(Appsignal.Transaction.t | nil, String.t, String.t, any, integer) :: Appsignal.Transaction.t
@callback finish() :: :sample | :no_sample
Expand Down Expand Up @@ -45,22 +43,14 @@ defmodule Appsignal.Transaction do
"""
@type t :: %Transaction{}

@typedoc """
The transaction's namespace
"""
@type namespace :: :http_request | :background_job

@valid_namespaces [:http_request, :background_job]


@doc """
Start a transaction

Call this when a transaction such as a http request or background job starts.

Parameters:
- `transaction_id` The unique identifier of this transaction
- `namespace` The namespace of this transaction. Must be one of `:http_request`, `:background_job`.
- `transaction_id` The unique identifier of this transaction.
- `namespace` The namespace of this transaction. Defaults to :background_job.

The function returns a `%Transaction{}` struct for use with the
other transaction functions in this module.
Expand All @@ -71,8 +61,8 @@ defmodule Appsignal.Transaction do
`Appsignal.TransactionRegistry`.

"""
@spec start(String.t, namespace) :: Transaction.t
def start(transaction_id, namespace) when is_binary(transaction_id) and namespace in @valid_namespaces do
@spec start(String.t, String.t) :: Transaction.t
def start(transaction_id, namespace) when is_binary(transaction_id) do
{:ok, resource} = Nif.start_transaction(transaction_id, Atom.to_string(namespace))
transaction = %Appsignal.Transaction{resource: resource, id: transaction_id}
TransactionRegistry.register(transaction)
Expand Down
4 changes: 2 additions & 2 deletions test/phoenix/channel_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ defmodule Appsignal.Phoenix.ChannelTest do
test_with_mock "channel_action function decorator", Appsignal.Transaction, [:passthrough], [] do
SomeApp.MyChannel.handle_in("ping", :payload, %Socket{})
t = Appsignal.TransactionRegistry.lookup(self())
assert called Transaction.start(t.id, :background_job)
assert called Transaction.start(t.id, :channel)
assert called Transaction.set_action(t, "Appsignal.Phoenix.ChannelTest.SomeApp.MyChannel#ping")
assert called Transaction.finish(t)
assert called Transaction.complete(t)
Expand All @@ -36,7 +36,7 @@ defmodule Appsignal.Phoenix.ChannelTest do
test_with_mock "direct calling of channel_action function", Appsignal.Transaction, [:passthrough], [] do
SomeApp.MyChannel.handle_in("pong", :payload, %Socket{})
t = Appsignal.TransactionRegistry.lookup(self())
assert called Transaction.start(t.id, :background_job)
assert called Transaction.start(t.id, :channel)
assert called Transaction.set_action(t, "Appsignal.Phoenix.ChannelTest.SomeApp.MyChannel#pong")
assert called Transaction.finish(t)
assert called Transaction.complete(t)
Expand Down