Skip to content

Fix a few issues with TRACE2 output #1909

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/shared/Core.Tests/Trace2MessageTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public void Event_Message_Without_Snake_Case_ToJson_Creates_Expected_Json()
ParameterizedMessage = "baz"
};

var expected = "{\"event\":\"error\",\"sid\":\"123\",\"thread\":\"main\",\"time\":\"0001-01-01T00:00:00+00:00\",\"file\":\"foo.cs\",\"line\":1,\"depth\":1,\"msg\":\"bar\",\"format\":\"baz\"}";
var expected = "{\"event\":\"error\",\"sid\":\"123\",\"thread\":\"main\",\"time\":\"0001-01-01T00:00:00+00:00\",\"file\":\"foo.cs\",\"line\":1,\"depth\":1,\"msg\":\"bar\",\"fmt\":\"baz\"}";
var actual = errorMessage.ToJson();

Assert.Equal(expected, actual);
Expand Down
11 changes: 6 additions & 5 deletions src/shared/Core.Tests/Trace2Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,26 @@ public class Trace2Tests
{
[PosixTheory]
[InlineData("af_unix:foo", "foo")]
[InlineData("af_unix:stream:foo-bar", "foo-bar")]
[InlineData("af_unix:dgram:foo-bar-baz", "foo-bar-baz")]
[InlineData("af_unix:foo/bar", "foo/bar")]
[InlineData("af_unix:stream:foo/bar", "foo/bar")]
[InlineData("af_unix:dgram:foo/bar/baz", "foo/bar/baz")]
public void TryGetPipeName_Posix_Returns_Expected_Value(string input, string expected)
{
var isSuccessful = Trace2.TryGetPipeName(input, out var actual);

Assert.True(isSuccessful);
Assert.Matches(actual, expected);
Assert.Equal(actual, expected);
}

[WindowsTheory]
[InlineData("\\\\.\\pipe\\git-foo", "git-foo")]
[InlineData("\\\\.\\pipe\\git-foo-bar", "git-foo-bar")]
[InlineData("\\\\.\\pipe\\foo\\git-bar", "git-bar")]
[InlineData("\\\\.\\pipe\\foo\\git-bar", "foo\\git-bar")]
public void TryGetPipeName_Windows_Returns_Expected_Value(string input, string expected)
{
var isSuccessful = Trace2.TryGetPipeName(input, out var actual);

Assert.True(isSuccessful);
Assert.Matches(actual, expected);
Assert.Equal(expected, actual);
}
}
13 changes: 8 additions & 5 deletions src/shared/Core/Trace2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -480,13 +480,16 @@ protected override void ReleaseManagedResources()
internal static bool TryGetPipeName(string eventTarget, out string name)
{
// Use prefixes to determine whether target is a named pipe/socket
if (eventTarget.Contains("af_unix:", StringComparison.OrdinalIgnoreCase) ||
eventTarget.Contains("\\\\.\\pipe\\", StringComparison.OrdinalIgnoreCase) ||
eventTarget.Contains("/./pipe/", StringComparison.OrdinalIgnoreCase))
if (eventTarget.StartsWith("af_unix:", StringComparison.OrdinalIgnoreCase) ||
eventTarget.StartsWith(@"\\.\pipe\", StringComparison.OrdinalIgnoreCase) ||
eventTarget.StartsWith("//./pipe/", StringComparison.OrdinalIgnoreCase))
{
name = PlatformUtils.IsWindows()
? eventTarget.TrimUntilLastIndexOf("\\")
: eventTarget.TrimUntilLastIndexOf(":");
? eventTarget.Replace('/', '\\')
.TrimUntilIndexOf(@"\\.\pipe\")
: eventTarget.Replace("af_unix:dgram:", "")
.Replace("af_unix:stream:", "")
.Replace("af_unix:", "");
return true;
}

Expand Down
2 changes: 1 addition & 1 deletion src/shared/Core/Trace2Message.cs
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ public class ErrorMessage : Trace2Message
[JsonPropertyOrder(8)]
public string Message { get; set; }

[JsonPropertyName("format")]
[JsonPropertyName("fmt")]
[JsonPropertyOrder(9)]
public string ParameterizedMessage { get; set; }

Expand Down