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

limit size of message #293

Merged
merged 1 commit into from
Jun 28, 2018
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/sentry.ex
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ defmodule Sentry do
`opts` argument is passed as the second argument to `Sentry.send_event/2`.
"""
@spec capture_message(String.t(), Keyword.t()) :: send_result
def capture_message(message, opts \\ []) do
def capture_message(message, opts \\ []) when is_binary(message) do
opts
|> Keyword.put(:message, message)
|> Event.create_event()
Expand Down
4 changes: 3 additions & 1 deletion lib/sentry/client.ex
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
defmodule Sentry.Client do
@behaviour Sentry.HTTPClient
# Max message length per https://github.com/getsentry/sentry/blob/0fcec33ac94ad81a205f86f208072b0f57b39ff4/src/sentry/conf/server.py#L1021
@max_message_length 8_192

@moduledoc ~S"""
This module is the default client for sending an event to Sentry via HTTP.
Expand Down Expand Up @@ -286,7 +288,7 @@ defmodule Sentry.Client do
event_id: event.event_id,
culprit: event.culprit,
timestamp: event.timestamp,
message: event.message,
message: String.slice(event.message, 0, @max_message_length),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we show ... or [TRUNCATED] at the end? or do we not have guidance?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tags: event.tags,
level: event.level,
platform: event.platform,
Expand Down
4 changes: 2 additions & 2 deletions test/client_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,10 @@ defmodule Sentry.ClientTest do

test "errors when attempting to report invalid JSON" do
modify_env(:sentry, dsn: "http://public:secret@localhost:3000/1")
unencodable_tuple = {:a, :b, :c}
unencodable_event = %Sentry.Event{message: "error", level: {:a, :b}}

capture_log(fn ->
assert :error = Sentry.capture_message(unencodable_tuple)
assert :error = Sentry.Client.send_event(unencodable_event)
end)
end

Expand Down