-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
398e727
commit 9e355f3
Showing
10 changed files
with
115 additions
and
20 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
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
24 changes: 24 additions & 0 deletions
24
src/Agent/NewRelic/Agent/Core/Logging/UTCTimestampEnricher.cs
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 @@ | ||
// Copyright 2020 New Relic, Inc. All rights reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
using System; | ||
using NewRelic.Core.CodeAttributes; | ||
using Serilog.Core; | ||
using Serilog.Events; | ||
|
||
namespace NewRelic.Agent.Core | ||
{ | ||
/// <summary> | ||
/// Formats the current UTC time for logging in the agent | ||
/// </summary> | ||
[NrExcludeFromCodeCoverage] | ||
public class UTCTimestampEnricher : ILogEventEnricher | ||
{ | ||
public const string UTCTimestampPropertyName = "UTCTimestamp"; | ||
public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory) | ||
{ | ||
logEvent.AddPropertyIfAbsent(propertyFactory.CreateProperty(UTCTimestampPropertyName, | ||
$"{DateTimeOffset.UtcNow:yyy-MM-dd HH:mm:ss,fff}")); | ||
} | ||
} | ||
} |
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
52 changes: 52 additions & 0 deletions
52
tests/Agent/IntegrationTests/IntegrationTests/AgentLogs/LogFileFormatTests.cs
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,52 @@ | ||
// Copyright 2020 New Relic, Inc. All rights reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
using System.IO; | ||
using System.Linq; | ||
using System.Text.RegularExpressions; | ||
using NewRelic.Agent.IntegrationTestHelpers; | ||
using Xunit; | ||
using Xunit.Abstractions; | ||
|
||
namespace NewRelic.Agent.IntegrationTests.AgentLogs | ||
{ | ||
[NetFrameworkTest] | ||
public class LogFileFormatTests : NewRelicIntegrationTest<RemoteServiceFixtures.BasicMvcApplicationTestFixture> | ||
{ | ||
private readonly RemoteServiceFixtures.BasicMvcApplicationTestFixture _fixture; | ||
|
||
public LogFileFormatTests(RemoteServiceFixtures.BasicMvcApplicationTestFixture fixture, ITestOutputHelper output) : base(fixture) | ||
{ | ||
_fixture = fixture; | ||
_fixture.TestLogger = output; | ||
_fixture.Actions | ||
( | ||
setupConfiguration: () => | ||
{ | ||
var configPath = fixture.DestinationNewRelicConfigFilePath; | ||
var configModifier = new NewRelicConfigModifier(configPath); | ||
configModifier.ForceTransactionTraces(); | ||
}, | ||
exerciseApplication: () => | ||
{ | ||
_fixture.Get(); | ||
} | ||
); | ||
_fixture.Initialize(); | ||
} | ||
|
||
[Fact] | ||
public void Test() | ||
{ | ||
// get the first log line and validate it's in the expected format | ||
var firstLogLine = _fixture.AgentLog.GetFileLines().First(); | ||
|
||
var match = Regex.Match(firstLogLine, | ||
@"\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2},\d{3} NewRelic .{6}: \[pid: \d{1,}, tid: \d{1,}\] .*"); | ||
|
||
Assert.True(match.Success); | ||
Assert.Single(match.Groups); | ||
Assert.Equal(firstLogLine, match.Groups[0].Value); | ||
} | ||
} | ||
} |