Skip to content
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
3 changes: 1 addition & 2 deletions lib/sentry/client_report.ex
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ defmodule Sentry.ClientReport do
:insufficient_data,
:backpressure,
:send_error,
:internal_sdk_error,
:ignored
:internal_sdk_error
]

@typedoc """
Expand Down
6 changes: 4 additions & 2 deletions lib/sentry/config.ex
Original file line number Diff line number Diff line change
Expand Up @@ -382,8 +382,10 @@ defmodule Sentry.Config do
Defaults to `[404]`, so *404 Not Found* requests are not traced. Set it to `[]` to
trace them again.

Outgoing requests are not affected, and the trace is still propagated to the services
this one calls.
The transaction is dropped only once the response status is known, after the request
has been handled. The trace is still propagated as sampled, so services called while
handling the request still report their part of it. Dropped transactions are counted
in client reports with the `event_processor` reason. Outgoing requests are not affected.

*Available since 14.0.0*.
"""
Expand Down
19 changes: 13 additions & 6 deletions lib/sentry/opentelemetry/span_processor.ex
Original file line number Diff line number Diff line change
Expand Up @@ -187,13 +187,20 @@ if Sentry.OpenTelemetry.VersionChecker.tracing_compatible?() do
result
end

# Only incoming requests are matched. An outgoing call can become a
# transaction root of its own when it outlives the request that made it,
# and the option is not meant to drop those.
defp ignored_response_status?(%{kind: :server, attributes: attributes}) do
defp ignored_response_status?(%{kind: :server, attributes: attributes} = span_record) do
case Map.get(attributes, to_string(HTTPAttributes.http_response_status_code())) do
status when is_integer(status) ->
Enum.any?(Config.traces_ignore_http_status_codes(), &status_matches?(&1, status))
ignored? =
Enum.any?(Config.traces_ignore_http_status_codes(), &status_matches?(&1, status))

if ignored? do
LoggerUtils.debug(fn ->
"Discarding transaction #{span_record.name} (#{span_record.span_id}): " <>
"its response status #{status} is listed in :traces_ignore_http_status_codes"
end)
end

ignored?

_other ->
false
Expand All @@ -206,7 +213,7 @@ if Sentry.OpenTelemetry.VersionChecker.tracing_compatible?() do
defp status_matches?(code, status), do: code == status

defp discard_transaction(transaction) do
ClientReport.Sender.record_discarded_events(:ignored, [transaction])
ClientReport.Sender.record_discarded_events(:event_processor, [transaction])
true
end

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
defmodule PhoenixApp.IgnoredStatusTracesTest do
use ExUnit.Case, async: false

import ExUnit.CaptureLog
import Sentry.TestHelpers

@port 4102
Expand Down Expand Up @@ -71,16 +72,31 @@ defmodule PhoenixApp.IgnoredStatusTracesTest do
assert upstream_tx["transaction"] == "GET /upstream"
end

test "a request answered with an ignored status is reported as discarded telemetry", %{
test "a request answered with an ignored status is discarded by an event processor", %{
ref: ref,
client_report_sender: sender
} do
put_test_config(traces_ignore_http_status_codes: [410])
log_at_debug_level()

assert request("/responses/410") == 410
assert reported_transactions(ref) == []
log =
capture_log([level: :debug], fn ->
assert request("/responses/410") == 410
assert reported_transactions(ref) == []
end)

assert log =~ ~r/\[debug\]\s+Discarding transaction .*response status 410/

assert discarded_outcomes(sender, ref, "event_processor") == %{
"transaction" => 1,
"span" => 1
}
end

assert discarded_outcomes(sender, ref, "ignored") == %{"transaction" => 1, "span" => 1}
defp log_at_debug_level do
previous_level = Logger.level()
Logger.configure(level: :debug)
on_exit(fn -> Logger.configure(level: previous_level) end)
end

defp request(path) do
Expand Down
Loading