-
Notifications
You must be signed in to change notification settings - Fork 28
fix(handler): add synthetic logger stacktrace #152
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
base: main
Are you sure you want to change the base?
Changes from all commits
8302f05
52d3e5c
b164400
9807b3e
0fbd5a4
aa8bdc9
1798800
01e366f
7401b8e
1d312ca
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 |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| hex/posthog: patch | ||
| --- | ||
|
|
||
| Add source location stacktrace frames for plain Logger messages. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -25,7 +25,7 @@ defmodule PostHog.HandlerTest do | |
| properties: %{ | ||
| "$exception_list": [ | ||
| %{ | ||
| type: "Hello World", | ||
| type: "Logger.info", | ||
| value: "Hello World", | ||
| mechanism: %{handled: true, type: "generic"} | ||
| } | ||
|
|
@@ -53,7 +53,7 @@ defmodule PostHog.HandlerTest do | |
| foo: "bar", | ||
| "$exception_list": [ | ||
| %{ | ||
| type: "Hello World", | ||
| type: "Logger.info", | ||
| value: "Hello World", | ||
| mechanism: %{handled: true, type: "generic"} | ||
| } | ||
|
|
@@ -62,6 +62,52 @@ defmodule PostHog.HandlerTest do | |
| } = event | ||
| end | ||
|
|
||
| test "adds synthetic stacktrace frame for plain logger messages", %{ | ||
| handler_ref: ref, | ||
| config: %{supervisor_name: supervisor_name} | ||
| } do | ||
| expected_line = log_plain_message() | ||
| LoggerHandlerKit.Assert.assert_logged(ref) | ||
|
|
||
| assert [event] = all_captured(supervisor_name) | ||
|
|
||
| assert %{ | ||
| properties: %{ | ||
| "$exception_list": [ | ||
| %{ | ||
| type: "Logger.info", | ||
| value: "Hello World", | ||
| stacktrace: %{ | ||
| type: "raw", | ||
| frames: [ | ||
| %{ | ||
| platform: "custom", | ||
| lang: "elixir", | ||
| filename: filename, | ||
| function: function, | ||
| lineno: ^expected_line, | ||
| module: "PostHog.HandlerTest", | ||
| in_app: false, | ||
| resolved: true, | ||
| synthetic: true | ||
| } | ||
| ] | ||
| } | ||
| } | ||
| ] | ||
| } | ||
| } = event | ||
|
|
||
| assert filename == "test/posthog/handler_test.exs" | ||
| assert function == "PostHog.HandlerTest.log_plain_message/0" | ||
| end | ||
|
|
||
| defp log_plain_message do | ||
| expected_line = __ENV__.line + 1 | ||
| Logger.info("Hello World") | ||
| expected_line | ||
| end | ||
|
|
||
| @tag config: [capture_level: :warning] | ||
| test "ignores messages lower than capture_level", %{ | ||
| handler_ref: ref, | ||
|
|
@@ -1487,7 +1533,7 @@ defmodule PostHog.HandlerTest do | |
| extra: "Foo", | ||
| "$exception_list": [ | ||
| %{ | ||
| type: "Error with metadata", | ||
| type: "Logger.error", | ||
|
Contributor
Author
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. I switched to Logger.#{level} here, because the error message could be dynamic and cause undergrouping as we always use the exception type in fp.
Contributor
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. Oof, that's a whole different topic to be honest. Perhaps it's be best to keep this PR focused on synthetic stacktrace and not change error type logic here? |
||
| value: "Error with metadata", | ||
| mechanism: %{handled: true} | ||
| } | ||
|
|
@@ -1518,7 +1564,7 @@ defmodule PostHog.HandlerTest do | |
| should: "work", | ||
| "$exception_list": [ | ||
| %{ | ||
| type: "Error with metadata", | ||
| type: "Logger.error", | ||
| value: "Error with metadata", | ||
| mechanism: %{handled: true} | ||
| } | ||
|
|
@@ -1607,7 +1653,7 @@ defmodule PostHog.HandlerTest do | |
| foo: "bar", | ||
| "$exception_list": [ | ||
| %{ | ||
| type: "Error with metadata", | ||
| type: "Logger.error", | ||
| value: "Error with metadata", | ||
| mechanism: %{handled: true, type: "generic"} | ||
| } | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.