-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
312 additions
and
115 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
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 |
---|---|---|
|
@@ -24,5 +24,4 @@ ecto_job_scheduler-*.tar | |
.elixir_ls/* | ||
|
||
# Dialyzer | ||
/priv/plts/*.plt | ||
/priv/plts/*.plt.hash | ||
_dialyzer/* |
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 |
---|---|---|
@@ -1,30 +1,38 @@ | ||
# Changelog | ||
|
||
All notable changes to this project will be documented in this file. | ||
|
||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), | ||
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). | ||
|
||
## [Unreleased] | ||
|
||
## [1.1.0] | ||
|
||
## Added | ||
|
||
- Support for new_relic instrumentation for the jobs | ||
|
||
## [1.0.2] - 2020-02-18 | ||
|
||
### Fixes | ||
### Fixes | ||
|
||
- Perform result | ||
|
||
## [1.0.1] - 2020-02-11 | ||
|
||
### Fixes | ||
### Fixes | ||
|
||
- Allow MFA tuple to be given sanitizer config | ||
|
||
## [1.0.0] - 2020-01-22 | ||
|
||
### Added | ||
### Added | ||
|
||
- Added support for ecto_job 3 | ||
|
||
[Unreleased]: https://github.com/rai200890/ecto-job-scheduler/compare/v1.0.2...HEAD | ||
[Unreleased]: https://github.com/rai200890/ecto-job-scheduler/compare/v1.1.0...HEAD | ||
[1.1.0]: https://github.com/rai200890/ecto-job-scheduler/compare/v1.0.2...1.1.0 | ||
[1.0.2]: https://github.com/rai200890/ecto-job-scheduler/compare/v1.0.1...v1.0.2 | ||
[1.0.1]: https://github.com/rai200890/ecto-job-scheduler/compare/v1.0.0...v1.0.1 | ||
[1.0.0]: https://github.com/rai200890/ecto-job-scheduler/compare/v0.7.0...v1.0.0 | ||
[1.0.0]: https://github.com/rai200890/ecto-job-scheduler/compare/v0.7.0...v1.0.0 |
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 |
---|---|---|
@@ -1 +1 @@ | ||
1.0.4 | ||
1.1.0 |
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,78 @@ | ||
defmodule EctoJobScheduler.NewRelic.JobInstrumenter do | ||
@moduledoc """ | ||
Tool for capture metrics to NewRelic. | ||
""" | ||
|
||
@doc """ | ||
Execute a function and capture metrics to NewRelic from it. | ||
The metrics is grouped with name parameter. | ||
Example of use: | ||
NewRelic.JobInstrumenter.transaction("job/1", fn -> | ||
... | ||
end) | ||
""" | ||
@spec transaction( | ||
name :: String.t(), | ||
function :: (() -> {:error, term()} | any() | no_return()) | ||
) :: | ||
term() | ||
def transaction(name, function) do | ||
start() | ||
|
||
add_attributes( | ||
other_transaction_name: name, | ||
request_id: get_request_id() | ||
) | ||
|
||
case function.() do | ||
{:error, reason} -> | ||
{:current_stacktrace, stack} = Process.info(self(), :current_stacktrace) | ||
fail(:error, reason, stack) | ||
complete() | ||
{:error, reason} | ||
|
||
result -> | ||
complete() | ||
result | ||
end | ||
rescue | ||
exception -> | ||
fail(exception.__struct__, Exception.message(exception), __STACKTRACE__) | ||
complete() | ||
reraise exception, __STACKTRACE__ | ||
end | ||
|
||
defp start do | ||
reporter().start() | ||
end | ||
|
||
defp add_attributes(attributes) do | ||
reporter().add_attributes(attributes) | ||
end | ||
|
||
defp fail(kind, reason, stack) do | ||
reporter().fail(self(), %{ | ||
kind: kind, | ||
reason: reason, | ||
stack: stack | ||
}) | ||
end | ||
|
||
defp complete do | ||
transaction().stop_transaction() | ||
end | ||
|
||
defp get_request_id do | ||
Keyword.get(Logger.metadata(), :request_id) | ||
end | ||
|
||
defp reporter, | ||
do: | ||
Application.get_env(:ecto_job_scheduler, __MODULE__)[:reporter] || | ||
NewRelic.Transaction.Reporter | ||
|
||
defp transaction, | ||
do: Application.get_env(:ecto_job_scheduler, __MODULE__)[:transaction] || NewRelic.Transaction | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
defmodule EctoJobScheduler.NewRelic.Reporter do | ||
@moduledoc false | ||
|
||
@callback start() :: term() | ||
|
||
@callback add_attributes(keyword()) :: term() | ||
|
||
@callback fail(pid(), map()) :: term() | ||
|
||
@callback complete(pid(), atom()) :: term() | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
defmodule EctoJobScheduler.NewRelic.TransactionBehaviour do | ||
@moduledoc false | ||
|
||
@callback stop_transaction() :: :ok | ||
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
Oops, something went wrong.