-
Notifications
You must be signed in to change notification settings - Fork 156
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
Create one session/telemetry configuration per run #515
Conversation
@@ -20,15 +20,19 @@ | |||
private const string CommandLineEventName = "CommandLineInformation"; | |||
private const string AssemblyReferencesEventName = "AssemblyReferencesInformation"; | |||
|
|||
private readonly int ChunkSize; | |||
private readonly string sha256; | |||
private string Sha256 => context?.Hashes?.Sha256; |
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.
s_telemetryClient = telemetryClient; | ||
s_sessionId = TelemetryEnabled ? Guid.NewGuid().ToString() : null; | ||
ChunkSize = chunkSize; | ||
s_telemetryConfiguration ??= telemetryConfiguration; |
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.
@@ -20,15 +20,19 @@ public class CompilerDataLogger | |||
private const string CommandLineEventName = "CommandLineInformation"; | |||
private const string AssemblyReferencesEventName = "AssemblyReferencesInformation"; | |||
|
|||
private readonly int ChunkSize; | |||
private readonly string sha256; | |||
private string Sha256 => context?.Hashes?.Sha256; |
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.
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.
when we send a null to AppInsights, it won't render the key value pair. If we try to print it in console, a null is showed as an empty string.
so, in this case, we don't need to create a default to empty
|
||
private static string s_sessionId; | ||
internal static string s_sessionId; |
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.
please pull aside all the internal static properties (that are overridden by tests) and group them together.
we do this to improve the readability of code, i.e., that accessibility is a clue to the maintainer there is a special external caller (our tests) that update these values.
make sense? you are future-proofing this code to help whoever comes along when those tests fail. #Closed
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.
Got it!
thanks for the feedback!
s_telemetryClient = new TelemetryClient(s_telemetryConfiguration); | ||
lock (s_syncRoot) | ||
{ | ||
if (s_telemetryConfiguration == null && s_telemetryClient == null) |
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.
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.
session/configuration/client can be injected using the constructor but the session is always defined when we have the telemetry enabled.
It's why we don't need to make the configuration/client internal.
} | ||
} | ||
|
||
internal static void Reset() | ||
{ | ||
s_sessionId = null; |
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.
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.
Added some docs in this method. We don't need a lock because it will only be called during tests.
All the tests that requires this aren't running in parallel.
|
||
[assembly: AssemblyTitle("BinSkim SDK")] | ||
[assembly: AssemblyDescription("BinSkim SDK and utilities for authoring analysis checks")] | ||
|
||
[assembly: InternalsVisibleTo("Test.UnitTests.BinSkim.Driver")] |
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.
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.
fixed!
thanks!
s_sessionId = Guid.NewGuid().ToString(); | ||
s_telemetryConfiguration = new TelemetryConfiguration(instrumentationKey); | ||
s_telemetryClient = new TelemetryClient(s_telemetryConfiguration); | ||
lock (s_syncRoot) |
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.
when we changed from single thread to multi thread, we started to create multiple configurations/clients/sessions.
With that in mind, we must synchronize the threads to prevent this behavior.
|
||
private static string s_sessionId; | ||
private static bool s_printHeader = true; |
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.
private readonly string sha256; | ||
private string Sha256 => context?.Hashes?.Sha256; | ||
|
||
private readonly int chunkSize; | ||
private readonly string relativeFilePath; |
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.
s_telemetryClient = telemetryClient; | ||
s_sessionId = TelemetryEnabled ? Guid.NewGuid().ToString() : null; | ||
ChunkSize = chunkSize; | ||
s_telemetryConfiguration ??= telemetryConfiguration; |
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.
Description:
When we changed from single thread to multi-thread application, the reporting rule started to behave differently:
Fixes:
This PR will fix the following issues: