Repository navigation
feat(tracing): [Ignore HTTP Status 3] Filter configured incoming HTTP statuses #6566
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
Open
adinauer
wants to merge
4
commits into
feat/ignore404-options
Choose a base branch
from
feat/ignore404-filter
base: feat/ignore404-options
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+388
−1
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
a018c68
feat(tracing): Filter configured incoming HTTP statuses
adinauer 199172d
chore: Link HTTP status filter changelog entry
adinauer 8eb7843
Merge branch 'feat/ignore404-options' into feat/ignore404-filter
adinauer 2a02d6d
Format code
getsentry-bot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,6 +21,7 @@ | |
| import io.sentry.transport.RateLimiter; | ||
| import io.sentry.util.*; | ||
| import java.io.Closeable; | ||
| import java.io.File; | ||
| import java.io.IOException; | ||
| import java.util.ArrayList; | ||
| import java.util.Collection; | ||
|
|
@@ -1024,6 +1025,30 @@ public void captureSession(final @NotNull Session session, final @Nullable Hint | |
| return SentryId.EMPTY_ID; | ||
| } | ||
|
|
||
| final @Nullable Integer ignoredHttpStatusCode = getIgnoredHttpStatusCode(transaction); | ||
| if (ignoredHttpStatusCode != null) { | ||
| options | ||
| .getLogger() | ||
| .log( | ||
| SentryLevel.DEBUG, | ||
| "Transaction was dropped as HTTP status code %d is ignored", | ||
| ignoredHttpStatusCode); | ||
| options | ||
| .getClientReportRecorder() | ||
| .recordLostEvent(DiscardReason.EVENT_PROCESSOR, DataCategory.Transaction); | ||
| options | ||
| .getClientReportRecorder() | ||
| .recordLostEvent( | ||
| DiscardReason.EVENT_PROCESSOR, DataCategory.Span, transaction.getSpans().size() + 1); | ||
| if (profilingTraceData != null) { | ||
| options | ||
| .getClientReportRecorder() | ||
| .recordLostEvent(DiscardReason.EVENT_PROCESSOR, DataCategory.Profile); | ||
| } | ||
| deleteProfilingTraceFile(profilingTraceData); | ||
| return SentryId.EMPTY_ID; | ||
| } | ||
|
|
||
| SentryId sentryId = SentryId.EMPTY_ID; | ||
| if (transaction.getEventId() != null) { | ||
| sentryId = transaction.getEventId(); | ||
|
|
@@ -1096,6 +1121,71 @@ public void captureSession(final @NotNull Session session, final @Nullable Hint | |
| return sentryId; | ||
| } | ||
|
|
||
| private @Nullable Integer getIgnoredHttpStatusCode(final @NotNull SentryTransaction transaction) { | ||
| final @Nullable List<HttpStatusCodeRange> ignoredHttpStatusCodes = | ||
| options.getTraceIgnoreStatusCodes(); | ||
| if (ignoredHttpStatusCodes == null || ignoredHttpStatusCodes.isEmpty()) { | ||
| return null; | ||
| } | ||
|
|
||
| final @Nullable SpanContext trace = transaction.getContexts().getTrace(); | ||
| if (trace == null | ||
| || !"server".equals(trace.getData().get(SpanDataConvention.SENTRY_KIND_KEY))) { | ||
| return null; | ||
| } | ||
|
|
||
| final @Nullable Object httpStatusCodeValue = | ||
| trace.getData().get(SpanDataConvention.HTTP_STATUS_CODE_KEY); | ||
| final int httpStatusCode; | ||
| if (httpStatusCodeValue instanceof Integer) { | ||
| httpStatusCode = (Integer) httpStatusCodeValue; | ||
|
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. nit: my agents says this can be collapsed with |
||
| } else if (httpStatusCodeValue instanceof Long) { | ||
| final long longHttpStatusCode = (Long) httpStatusCodeValue; | ||
| if (longHttpStatusCode < 100 || longHttpStatusCode > 599) { | ||
| return null; | ||
| } | ||
| httpStatusCode = (int) longHttpStatusCode; | ||
| } else { | ||
| return null; | ||
| } | ||
|
|
||
| if (httpStatusCode < 100 || httpStatusCode > 599) { | ||
| return null; | ||
| } | ||
| for (final @Nullable HttpStatusCodeRange ignoredHttpStatusCode : ignoredHttpStatusCodes) { | ||
| if (ignoredHttpStatusCode != null && ignoredHttpStatusCode.isInRange(httpStatusCode)) { | ||
| return httpStatusCode; | ||
| } | ||
| } | ||
| return null; | ||
| } | ||
|
|
||
| private void deleteProfilingTraceFile(final @Nullable ProfilingTraceData profilingTraceData) { | ||
| if (profilingTraceData == null) { | ||
| return; | ||
| } | ||
|
|
||
| final @NotNull File traceFile = profilingTraceData.getTraceFile(); | ||
| try { | ||
| if (!traceFile.delete()) { | ||
| options | ||
| .getLogger() | ||
| .log( | ||
| SentryLevel.WARNING, | ||
| "Failed to delete profiling trace file %s for an ignored transaction", | ||
| traceFile.getPath()); | ||
| } | ||
| } catch (SecurityException e) { | ||
| options | ||
| .getLogger() | ||
| .log( | ||
| SentryLevel.WARNING, | ||
| e, | ||
| "Failed to delete profiling trace file %s for an ignored transaction", | ||
| traceFile.getPath()); | ||
| } | ||
| } | ||
|
|
||
| @ApiStatus.Internal | ||
| @Override | ||
| public @NotNull SentryId captureProfileChunk( | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
nit: my agent tells me that a lot of this logic is very similar to that on 1010. so maybe we can use a private helper for it?