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

SYB 018/upgrade to 1.15.7 #34

Merged
merged 13 commits into from
Nov 15, 2023
17 changes: 11 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,23 @@ concurrency:

jobs:
lint-and-test:
env:
ELIXIR_VERSION: 1.12.3
OTP_VERSION: 24.2
runs-on: ubuntu-latest
name: OTP ${{matrix.otp}} / Elixir ${{matrix.elixir}}
strategy:
matrix:
include:
- otp: "26.1"
elixir: "1.15.7"
- otp: "24.2"
elixir: "1.12.3"
steps:
- name: Checkout Github repo
uses: actions/[email protected]
- name: Setup BEAM Env
uses: erlef/[email protected]
with:
otp-version: ${{ env.OTP_VERSION }}
elixir-version: ${{ env.ELIXIR_VERSION }}
otp-version: ${{matrix.otp}}
elixir-version: ${{matrix.elixir}}
- name: Setup Cache
uses: actions/[email protected]
id: mix-cache
Expand All @@ -35,7 +40,7 @@ jobs:
deps
_build
priv/plts
key: ${{ hashFiles('mix.lock') }}-${{ env.ELIXIR_VERSION }}-${{ env.OTP_VERSION }}
key: ${{ hashFiles('mix.lock') }}-${{ matrix.elixir }}-${{ matrix.otp }}
- if: steps.mix-cache.outputs.cache-hit != 'true'
run: mkdir -p priv/plts; mix deps.get; mix deps.compile
- run: mix lint
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ cover/
apps/**/cover/
priv/plts/
doc/
.direnv/
4 changes: 2 additions & 2 deletions .tool-versions
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
elixir 1.12
erlang 24.2
elixir 1.15.7-otp-26
erlang 26.1.2
61 changes: 61 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 32 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
flake-utils.url = "github:numtide/flake-utils";
};

outputs = { self, nixpkgs, flake-utils }:
flake-utils.lib.eachDefaultSystem (
system:
let
pkgs = import nixpkgs { inherit system; };

# `sha256` can be programmatically obtained via running the following:
# `nix-prefetch-url --unpack https://github.com/elixir-lang/elixir/archive/v${version}.tar.gz`
elixir_1_15_7 = (pkgs.beam.packagesWith pkgs.erlangR26).elixir_1_15.override {
version = "1.15.7";
sha256 = "0yfp16fm8v0796f1rf1m2r0m2nmgj3qr7478483yp1x5rk4xjrz8";
};
in
with pkgs; {
devShells.default = mkShell {
buildInputs = [ elixir_1_15_7 inotify-tools docker-compose ];
env = {
POSTGRES_PORT="5432";
POSTGRES_USER = "postgres";
POSTGRES_PASSWORD = "postgres";
POSTGRES_DB = "endo_repo";
};
};
}
);
}
13 changes: 10 additions & 3 deletions lib/sibyl/ast.ex
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,15 @@ defmodule Sibyl.AST do

For example, given: `{:__aliases, unused(), [Elixir, Enum]}`, returns: `Enum`.
"""
@spec module(alias(), env :: map()) :: module()
def module({:__aliases__, _metadata, _module_list} = ast, env \\ %{}) do
Macro.expand(ast, env)
@spec module(alias(), Macro.Env.t()) :: module()
def module({:__aliases__, _metadata, _module_list} = ast, env) do
case Macro.expand(ast, env) do
module when is_atom(module) ->
module

otherwise ->
otherwise = inspect(otherwise)
raise ArgumentError, "expected an alias expanding to a module, got: #{otherwise}"
end
end
end
4 changes: 2 additions & 2 deletions lib/sibyl/dynamic.ex
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ defmodule Sibyl.Dynamic do
:ok = put_handler!(handler)

# Flush :dbg in case it was already started prior to this.
:ok = :dbg.stop_clear()
:ok = :dbg.stop()
{:ok, _pid} = :dbg.start()

# This is the important bit; by default :dbg will just log what gets traced on stdout
Expand All @@ -46,7 +46,7 @@ defmodule Sibyl.Dynamic do

@spec disable() :: :ok
def disable do
:ok = :dbg.stop_clear()
:ok = :dbg.stop()
:ets.delete(@state)
:ok
rescue
Expand Down
4 changes: 3 additions & 1 deletion lib/sibyl/events.ex
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,11 @@ defmodule Sibyl.Events do
rescue
ArgumentError ->
:attributes
|> module.__info__()
|> module.module_info()
|> Keyword.get(:sibyl_telemetry_events, [])
end

# coveralls-ignore-start
rescue
_e in [FunctionClauseError, UndefinedFunctionError] ->
[]
Expand Down
14 changes: 10 additions & 4 deletions lib/sibyl/exceptions.ex
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ defmodule Sibyl.UndefinedEventError do

@impl Exception
def exception(event: event, module: module) do
module_string = inspect(module)

%Sibyl.UndefinedEventError{
event: event,
module: module,
message: """
Attempted to emit event `#{event}` defined in module `#{inspect(module)}` but no such event was defined.
Ensure `#{inspect(module)}` uses `define_event/1` to define `#{event}` before emission.
Attempted to emit event `#{event}` defined in module `#{module_string}` but no such event was defined.
Ensure `#{module_string}` uses `define_event/1` to define `#{event}` before emission.
"""
}
end
Expand All @@ -19,23 +21,27 @@ defmodule Sibyl.BadEmissionError do

@impl Exception
def exception(module: module) do
module_string = inspect(module)

%Sibyl.BadEmissionError{
message: """
An event belonging to `#{inspect(module)}` was attempted to be raised, but this module does not exist.
An event belonging to `#{module_string}` was attempted to be raised, but this module does not exist.

Please assert that any module you try to emit an event from exists prior to to attempting to emit any events from it.
"""
}
end

def exception(args: args) do
args = inspect(args)

%Sibyl.BadEmissionError{
message: """
Emitting events must be done either by `Sibyl.emit/4` or `Sibyl.emit/3` where:
- `Sibyl.emit/4` takes a module alias as a first parameter, followed by an atom denoting the event name, an optional map of "measurements", and an optional map of "metadata".
- `Sibyl.emit/3` takes either a bare atom or list of atoms (an event name), an optional map of "measurements", and an optional map of "metadata".

No other argument combination is supported, but got: `#{inspect(args)}`.
No other argument combination is supported, but got: `#{args}`.
"""
}
end
Expand Down
6 changes: 4 additions & 2 deletions lib/sibyl/handlers.ex
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,14 @@ defmodule Sibyl.Handlers do
name

nil ->
Logger.warn("Sibyl can attach without a name but it is recommended to pass one in.")
Logger.warning("Sibyl can attach without a name but it is recommended to pass one in.")
inspect(make_ref())

otherwise ->
error_payload = inspect(otherwise)

raise ArgumentError,
message: "opts[:name] should be of type `String.t()`, got: `#{inspect(otherwise)}`"
message: "opts[:name] should be of type `String.t()`, got: `#{error_payload}`"
end
end
end
10 changes: 7 additions & 3 deletions lib/sibyl/handlers/logger.ex
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,20 @@ defmodule Sibyl.Handlers.Logger do
def handle_event(event, measurement, metadata, config) do
name = Keyword.get(config, :name)

event_string = inspect(event)
measurement_string = inspect(measurement)
metadata_string = inspect(metadata)

config
|> Keyword.get(:level, :info)
|> Logger.log(fn ->
"""
Captured event `#{inspect(event)}` in handler name `#{name}` which reports the following:
Captured event `#{event_string}` in handler name `#{name}` which reports the following:
- Measurements:
#{inspect(measurement)}
#{measurement_string}

- Metadata:
#{inspect(metadata)}
#{metadata_string}
"""
end)
end
Expand Down
2 changes: 1 addition & 1 deletion lib/sibyl/handlers/open_telemetry.ex
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ defmodule Sibyl.Handlers.OpenTelemetry do
:ok = set_attributes(measurement)

# Handle `rescue` from Elixir or `throw` from Erlang
if Exception.exception?(exception) do
if is_exception(exception) do
Span.record_exception(ctx, exception, stacktrace, duration: duration)
else
:otel_span.record_exception(ctx, kind, reason, stacktrace, duration: duration)
Expand Down
2 changes: 2 additions & 0 deletions lib/sibyl/plugin.ex
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ defmodule Sibyl.Plugin do
|> Enum.map(
&(&1
|> String.downcase()
# NOTE: the following is done at compile time so should be safe
# credo:disable-for-next-line Credo.Check.Warning.UnsafeToAtom
|> String.to_atom())
)

Expand Down
4 changes: 3 additions & 1 deletion lib/sibyl/plugins/absinthe.ex
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,9 @@ defmodule Sibyl.Plugins.Absinthe do
defp parse_event([:absinthe, :middleware, :batch | _rest], metadata) do
arity = 2
[module, function | _rest] = Tuple.to_list(metadata.batch_fun)
mfa = "#{inspect(module)}.#{function}/#{arity}"
module_string = inspect(module)

mfa = "#{module_string}.#{function}/#{arity}"

%{event_name: "batch:" <> mfa, mfa: mfa, args: metadata.batch_data}
end
Expand Down
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ defmodule Sibyl.MixProject do
def project do
[
app: :sibyl,
version: "0.1.8",
version: "0.1.9",
elixir: "~> 1.12",
start_permanent: Mix.env() == :prod,
deps: deps(),
Expand Down
Loading
Loading