Skip to content

Commit

Permalink
Merge pull request #293 from getsentry/limit-size
Browse files Browse the repository at this point in the history
limit size of message
  • Loading branch information
mitchellhenke authored Jun 28, 2018
2 parents 65ac26c + 382f94e commit 8c216dc
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
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),
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

0 comments on commit 8c216dc

Please sign in to comment.