-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
trace2: add infrastructure and initial events (#1045)
Add initial `TRACE2` functionality, including: 1. Small refactorings to make `TryGetAssemblyVersion` accessible outside of the `DiagnosticCommand` class and shared trace logic accessible from a `TraceUtils` class. 2. Addition of a `Trace2CollectorWriter` class, which handles writing to the Telemetry Tool/OTel collector and a `Trace2StreamWriter` class, which handles writing to stderr/files. 3. Basic `TRACE2` functionality, including the ability to add writers to different format targets, logic to send messages to these writers, and the ability to release these writers before application exit. 4. Support for session IDs. 5. Ability for users to enable normal/event format targets. 6. Writing `Version`, `Start`, and `Exit` events.
- Loading branch information
Showing
33 changed files
with
964 additions
and
99 deletions.
There are no files selected for viewing
This file contains 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 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 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 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,58 @@ | ||
using System; | ||
using System.Text.RegularExpressions; | ||
using GitCredentialManager.Tests.Objects; | ||
using Xunit; | ||
|
||
namespace GitCredentialManager.Tests; | ||
|
||
public class Trace2Tests | ||
{ | ||
[PlatformTheory(Platforms.Posix)] | ||
[InlineData("af_unix:foo", "foo")] | ||
[InlineData("af_unix:stream:foo-bar", "foo-bar")] | ||
[InlineData("af_unix:dgram:foo-bar-baz", "foo-bar-baz")] | ||
public void TryParseEventTarget_Posix_Returns_Expected_Value(string input, string expected) | ||
{ | ||
var environment = new TestEnvironment(); | ||
var settings = new TestSettings(); | ||
|
||
var trace2 = new Trace2(environment, settings.GetTrace2Settings(), new []{""}, DateTimeOffset.UtcNow); | ||
var isSuccessful = trace2.TryGetPipeName(input, out var actual); | ||
|
||
Assert.True(isSuccessful); | ||
Assert.Matches(actual, expected); | ||
} | ||
|
||
[PlatformTheory(Platforms.Windows)] | ||
[InlineData("\\\\.\\pipe\\git-foo", "git-foo")] | ||
[InlineData("\\\\.\\pipe\\git-foo-bar", "git-foo-bar")] | ||
[InlineData("\\\\.\\pipe\\foo\\git-bar", "git-bar")] | ||
public void TryParseEventTarget_Windows_Returns_Expected_Value(string input, string expected) | ||
{ | ||
var environment = new TestEnvironment(); | ||
var settings = new TestSettings(); | ||
|
||
var trace2 = new Trace2(environment, settings.GetTrace2Settings(), new []{""}, DateTimeOffset.UtcNow); | ||
var isSuccessful = trace2.TryGetPipeName(input, out var actual); | ||
|
||
Assert.True(isSuccessful); | ||
Assert.Matches(actual, expected); | ||
} | ||
|
||
[Theory] | ||
[InlineData("20190408T191610.507018Z-H9b68c35f-P000059a8")] | ||
[InlineData("")] | ||
public void SetSid_Envar_Returns_Expected_Value(string parentSid) | ||
{ | ||
Regex rx = new Regex(@$"{parentSid}\/[\d\w-]*"); | ||
|
||
var environment = new TestEnvironment(); | ||
environment.Variables.Add("GIT_TRACE2_PARENT_SID", parentSid); | ||
|
||
var settings = new TestSettings(); | ||
var trace2 = new Trace2(environment, settings.GetTrace2Settings(), new []{""}, DateTimeOffset.UtcNow); | ||
var sid = trace2.SetSid(); | ||
|
||
Assert.Matches(rx, sid); | ||
} | ||
} |
This file contains 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,18 @@ | ||
using System; | ||
using System.IO; | ||
using System.Text; | ||
using Xunit; | ||
|
||
namespace GitCredentialManager.Tests; | ||
|
||
public class TraceUtilsTests | ||
{ | ||
[Theory] | ||
[InlineData("/foo/bar/baz/boo", 10, "...baz/boo")] | ||
[InlineData("thisfileshouldbetruncated", 12, "...truncated")] | ||
public void FormatSource_ReturnsExpectedSourceValues(string path, int sourceColumnMaxWidth, string expectedSource) | ||
{ | ||
string actualSource = TraceUtils.FormatSource(path, sourceColumnMaxWidth); | ||
Assert.Equal(actualSource, expectedSource); | ||
} | ||
} |
This file contains 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 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,24 @@ | ||
using System.Reflection; | ||
|
||
namespace GitCredentialManager; | ||
|
||
public static class AssemblyUtils | ||
{ | ||
public static bool TryGetAssemblyVersion(out string version) | ||
{ | ||
try | ||
{ | ||
var assembly = Assembly.GetEntryAssembly() ?? Assembly.GetExecutingAssembly(); | ||
var assemblyVersionAttribute = assembly.GetCustomAttribute<AssemblyInformationalVersionAttribute>(); | ||
version = assemblyVersionAttribute is null | ||
? assembly.GetName().Version.ToString() | ||
: assemblyVersionAttribute.InformationalVersion; | ||
return true; | ||
} | ||
catch | ||
{ | ||
version = null; | ||
return false; | ||
} | ||
} | ||
} |
This file contains 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 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 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 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 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,10 @@ | ||
using System; | ||
|
||
namespace GitCredentialManager; | ||
|
||
public interface ITrace2Writer : IDisposable | ||
{ | ||
bool Failed { get; } | ||
|
||
void Write(Trace2Message message); | ||
} |
Oops, something went wrong.