-
Notifications
You must be signed in to change notification settings - Fork 29
feat: add before send callback #161
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,6 +3,8 @@ defmodule PostHog do | |
| Main API for working with PostHog | ||
| """ | ||
|
|
||
| require Logger | ||
|
|
||
| @typedoc "Name under which an instance of PostHog supervision tree is registered." | ||
| @type supervisor_name() :: atom() | ||
|
|
||
|
|
@@ -78,7 +80,36 @@ defmodule PostHog do | |
| properties: properties | ||
| } | ||
|
|
||
| PostHog.Sender.send(event, name) | ||
| case run_before_send(Map.get(config, :before_send), event) do | ||
| nil -> :ok | ||
| event -> PostHog.Sender.send(event, name) | ||
| end | ||
| end | ||
|
|
||
| defp run_before_send(nil, event), do: event | ||
|
|
||
| defp run_before_send(before_send, event) when is_function(before_send, 1) do | ||
| case before_send.(event) do | ||
| nil -> | ||
| nil | ||
|
|
||
| %{} = event -> | ||
| event | ||
|
|
||
| other -> | ||
| Logger.error( | ||
| "PostHog before_send callback returned #{inspect(other)} instead of an event map or nil; dropping event" | ||
| ) | ||
|
|
||
| nil | ||
| end | ||
| rescue | ||
| exception -> | ||
| Logger.error( | ||
| "PostHog before_send callback raised; dropping event: #{Exception.message(exception)}" | ||
| ) | ||
|
|
||
| nil | ||
| end | ||
|
Comment on lines
+91
to
113
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Context Used: Do not attempt to comment on incorrect alphabetica... (source) |
||
|
|
||
| @doc false | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Map.get(config, :before_send)is inconsistent with how all other config keys are accessed inbare_capture(e.g.,config.global_properties). Sincebefore_sendalways exists in the validated config (defaulting tonil), dot-access is sufficient and matches the surrounding style.Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!