Repository navigation
fix(serilog): logs from application namespaces beginning with "Sentry" are discarded #5456
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| namespace Sentry.Internal; | ||
|
|
||
| /// <summary> | ||
| /// Identifies logger names that belong to the Sentry SDK itself, so the logging integrations can | ||
| /// skip them rather than feeding the SDK's own output back into Sentry. | ||
| /// </summary> | ||
| /// <remarks> | ||
| /// The <c>PackageRoots</c> half of this class is generated from <c>.craft.yml</c> - see the | ||
| /// <c>GenerateSentrySdkNamespaces</c> target in <c>Sentry.csproj</c>. | ||
| /// </remarks> | ||
| internal static partial class SentrySdkNamespaces | ||
| { | ||
| private const string Prefix = "Sentry"; | ||
|
|
||
| /// <summary> | ||
| /// The core <c>Sentry</c> package can't be matched by prefix the way the other packages can: | ||
| /// all of its types live directly under <c>Sentry.</c>, and so does application code that | ||
| /// happens to use that namespace (<c>Sentry.Samples.*</c>, <c>Sentry.MyApp.*</c>). Matching on | ||
| /// <c>Sentry.</c> would therefore silently discard the user's own logs. | ||
| /// | ||
| /// Core has no logging dependency of its own, so the only name it ever logs under is the one | ||
| /// <c>MelDiagnosticLogger</c> (in Sentry.Extensions.Logging) gets from | ||
| /// <c>ILogger<ISentryClient></c>. Matching that exactly is enough. | ||
| /// </summary> | ||
| private static readonly string[] CoreNames = { Prefix, "Sentry.ISentryClient" }; | ||
|
|
||
| /// <summary> | ||
| /// Whether <paramref name="loggerName"/> - a Serilog <c>SourceContext</c>, a | ||
| /// <c>Microsoft.Extensions.Logging</c> category, or an equivalent from another framework - | ||
| /// belongs to the Sentry SDK. | ||
| /// </summary> | ||
| internal static bool IsSentrySdk(string? loggerName) | ||
| { | ||
| if (loggerName is null || !loggerName.StartsWith(Prefix, StringComparison.Ordinal)) | ||
| { | ||
| return false; | ||
| } | ||
|
|
||
| foreach (var name in CoreNames) | ||
| { | ||
| if (string.Equals(loggerName, name, StringComparison.Ordinal)) | ||
| { | ||
| return true; | ||
| } | ||
| } | ||
|
|
||
| foreach (var root in PackageRoots) | ||
| { | ||
| // Either the package's own namespace, or something nested inside it. Comparing the | ||
| // character after the root keeps a package named e.g. 'Sentry.Maui' from matching an | ||
| // unrelated 'Sentry.MauiSomething'. | ||
| if (loggerName.StartsWith(root, StringComparison.Ordinal) && | ||
| (loggerName.Length == root.Length || loggerName[root.Length] == '.')) | ||
| { | ||
| return true; | ||
| } | ||
| } | ||
|
|
||
| return false; | ||
| } | ||
| } |
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.