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

Make debug diagnostic logger obsolete and add Trace diagnostic logger. #1048

Merged
merged 13 commits into from
Jun 18, 2021

Conversation

lucas-zimerman
Copy link
Collaborator

@lucas-zimerman lucas-zimerman commented Jun 8, 2021

DebugDiagnosticLogger only works with projects inside Sentry.NET.snl since Release builds remove the Debug code, making it useless to the end-user.
Another approach is to use Trace as a replacement, it's not as simple as the good old DebugDiagnosticLogger but it should work just fine even in Release mode.

Close #1040.

It would be great if I could simply use Trace.Write but it seems like the compiler gets rid of it if not called from the current process.

EDIT: Validated on

  • .NET 5 Console
  • .NET Core with IIS
  • .NET Native UWP

@lucas-zimerman lucas-zimerman added the Feature New feature or request label Jun 8, 2021
@codecov-commenter
Copy link

codecov-commenter commented Jun 8, 2021

Codecov Report

Merging #1048 (ee449fe) into main (93b93dc) will decrease coverage by 0.15%.
The diff coverage is 16.66%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #1048      +/-   ##
==========================================
- Coverage   81.33%   81.17%   -0.16%     
==========================================
  Files         193      194       +1     
  Lines        6338     6349      +11     
  Branches     1528     1530       +2     
==========================================
- Hits         5155     5154       -1     
- Misses        747      758      +11     
- Partials      436      437       +1     
Impacted Files Coverage Δ
src/Sentry/Infrastructure/DebugDiagnosticLogger.cs 0.00% <ø> (-50.00%) ⬇️
src/Sentry/Infrastructure/TraceDiagnosticLogger.cs 9.09% <9.09%> (ø)
src/Sentry.AspNet/SentryAspNetOptionsExtensions.cs 90.00% <100.00%> (ø)
src/Sentry/Internal/BackgroundWorker.cs 84.24% <0.00%> (-0.69%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 93b93dc...ee449fe. Read the comment docs.

private static TraceListener? GetFirstOrDefaultListener()
{
var listeners = Trace.Listeners;
return listeners.Count > 0 ? listeners[0] : null;
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It works, not a fan of this line and linq doesn't work with listeners.

Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe we should write to all listeners, not just one?

@@ -7,7 +7,7 @@
<RootNamespace>Sentry</RootNamespace>
<Description>Official SDK for Sentry - Open-source error tracking that helps developers monitor and fix crashes in real time.</Description>
<NoWarn Condition="$(TargetFramework) == 'netstandard2.0'">$(NoWarn);RS0017</NoWarn>
<DefineConstants>$(AdditionalConstants)</DefineConstants>
<DefineConstants>$(AdditionalConstants);TRACE</DefineConstants>
Copy link
Contributor

Choose a reason for hiding this comment

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

Does the trace logger not work without TRACE constant?

Copy link
Member

Choose a reason for hiding this comment

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

I wonder if we're adding overhead to the SDK by setting this. We're not explicitly adding anything that depends on TRACE constant being defined so I assume it wouldn't matter but it does make me wonder. Does it affect the size of the binary at all for example?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Trace.Write/WriteLine doesn't work without the TRACE trace constant. Trace.Listeners are exposed with or without the TRACE constant, but in my opinion, it's better to use set the TRACE constant and using the build-in Trace.Write instead of reinventing the wheel.

The package sizes are:
1,076,098 bytes with the TRACE constant
1,076,158 bytes without the TRACE constant and without the Trace Logger file
1,077,102 bytes without it.
1,077,858 bytes without the trace constant with the addition of a loop to write to all listeners.
1,080,993 bytes adding the DEBUG constant (out of curiosity, this allows the debug diagnostic logger to work properly in release)

CHANGELOG.md Outdated Show resolved Hide resolved
@@ -7,7 +7,7 @@
<RootNamespace>Sentry</RootNamespace>
<Description>Official SDK for Sentry - Open-source error tracking that helps developers monitor and fix crashes in real time.</Description>
<NoWarn Condition="$(TargetFramework) == 'netstandard2.0'">$(NoWarn);RS0017</NoWarn>
<DefineConstants>$(AdditionalConstants)</DefineConstants>
<DefineConstants>$(AdditionalConstants);TRACE</DefineConstants>
Copy link
Member

Choose a reason for hiding this comment

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

I wonder if we're adding overhead to the SDK by setting this. We're not explicitly adding anything that depends on TRACE constant being defined so I assume it wouldn't matter but it does make me wonder. Does it affect the size of the binary at all for example?

lucas-zimerman and others added 2 commits June 15, 2021 17:36
@bruno-garcia
Copy link
Member

@lucas-zimerman and I talked on a call and decided to drop the constant and use the listeners. This is a logger for debug purposes and we don't wanta to add a trace constant to a release build

@bruno-garcia bruno-garcia merged commit 97ef30f into main Jun 18, 2021
@bruno-garcia bruno-garcia deleted the feat/add-trace-diagnostic-logger branch June 18, 2021 12:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Usage of DebugDiagnosticLogger in the shipped SDK will be no-op
4 participants