-
Notifications
You must be signed in to change notification settings - Fork 2.4k
trace2: add infrastructure and initial events #1045
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
trace2: add infrastructure and initial events #1045
Conversation
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.
Thanks for helping me refresh my C#. Lots of good stuff in here.
This looks like a good start. Thanks for all your work on this. |
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.
Looking good so far! I have some comments about simplifying the collector/queue, going all in on GIT_
variables, and how we're instantiating Trace2
and the stopwatch.
I just responded to all of Matthew's questions that I had an opinion on. |
0e52b93
to
a74b9c0
Compare
Changes since v1:
|
a74b9c0
to
f402706
Compare
public static void Main(string[] args) | ||
{ | ||
// Set up timer for TRACE2 | ||
var applicationStartTime = DateTimeOffset.UtcNow.ToUnixTimeSeconds(); |
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.
I just made a comment in Trace2.c about moving all of the time-math into it, but I wanted to say that we should be careful converting UTC times to seconds -- we're measuring mili- and micro-second times and here we're lopping of the time to integer seconds. There is a To...Milliseconds() method that would be better (inside the WriteFOO() events).
That is assuming that there isn't a way to have the WriteFOO() methods subtract two DateTime values directly and get an elapsed TimeSpan expressed in a microsecond value and then format that as a time-in-seconds floating point value in the JSON event.
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.
I think I've got an extension method that's doing what we want here. Let me know what you think.
f402706
to
72fd03f
Compare
Changes since v2:
|
0bee0da
to
b1052e5
Compare
23e683e
to
74916cd
Compare
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.
A few comments I have so far
463f3f4
to
3b22601
Compare
The implementation of TRACE2 tracing will require use of the TryGetAssemblyVersion method. To prepare for this, move this method out of the DiagnoseCommand class and into its own static class.
The implementation of TRACE2 tracing will require truncation of long file names just as TRACE does. To prepare for this, move this logic out of the TRACE class and into its own method in a new static TraceUtils class. Additionally, add a unit test to validate this logic.
Add initial TRACE2 functionality, including: 1. The ability to add writers (which will eventually write to Normal, Perf, and Event format targets). 2. An abstract Trace2Message class. 3. Logic to send Trace2Messages to writers. 4. Ability to release writers prior to application exit.
Add the Trace2CollectorWriter class to accept Trace2 messages in the event target format and write them to the OTel Collector/Telemetry Service.
Add Trace2StreamWriter class which will be used to write to stderr or a file, based on the TextWriter that is passed to it. It will also adapt the output format based on the format target that is passed to it.
3b22601
to
9688226
Compare
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.
I took a quick look through, and only had some nitpicks along the way.
However, one thing I was looking forward to seeing was a test that could demonstrate that the git-credential-manager
executable would output the trace2 output (in event or normal form) as much as possible. The event form creates a JSON event on a per-line basis, so being able to parse that JSON even and checking that it has the necessary items would be helpful. (Any issues with extra items?)
A key component of Git's TRACE2 tracing system is the session id (sid). This identifies the process instance to allow all events emitted by it to be identified. We check to see if a parent sid (i.e. from a Git process) exists. If so, we separate this sid from the GCM sid (a GUID) using a "/". If there is no parent sid, we simply generate a GUID for the GCM sid and use that. The above also requires addition of a new SetEnvironmentVariable() method in EnvironmentBase.cs to set the GCM-specific SID variable.
Add the infrastructure to detect whether a user has enabled the TRACE2 event format or normal format targets. This implementation has been designed to be extended to include the perf format target in a future series. Additionally it involved some refactoring/cleanup to set the Application Path and InstallationDirectory in the CommandContext, rather than in GCM/UI helper Program.cs files.
9688226
to
995d6b7
Compare
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.
Looks like a strong foundation and anything from here on out can be forward-fixed as we get more use out of it (and an end-to-end testing framework).
Write the TRACE2 version event, which identifies the event format version (currently hardcoded as 3 as it is in Git) and the version of GCM. Additionally, write the TRACE2 start event, which reflects the elapsed time and application arguments (including the application name). These are paired because the telemetry tool/OTel collector require both these events to be sent for a given session.
Add TRACE2 exit event, following the pattern established with the version and start events.
995d6b7
to
028ad46
Compare
You merged it as I was about to push the approve button.... :-) |
Add initial
TRACE2
functionality, including:TryGetAssemblyVersion
accessibleoutside of the
DiagnosticCommand
class and shared trace logicaccessible from a
TraceUtils
class.Trace2CollectorWriter
class, which handles writingto the Telemetry Tool/OTel collector and a
Trace2StreamWriter
class,which handles writing to stderr/files.
TRACE2
functionality, including the ability to add writers todifferent format targets, logic to send messages to these writers, and
the ability to release these writers before application exit.
Version
,Start
, andExit
events.While this patch series does not represent all the
TRACE2
events we planto implement, it does provide the opportunity to review and suggest changes
to the foundation these events are built on. It also provides the general pattern
that additional patches will use to implement new events, just in case that
needs to be tweaked.