Skip to content

Commit

Permalink
Updates applicationLogging level to be log.level (#1045)
Browse files Browse the repository at this point in the history
* Updates applicationLogging level to be log.level

* One missed test
  • Loading branch information
jaffinito authored Apr 4, 2022
1 parent 06cf43c commit 55863b8
Show file tree
Hide file tree
Showing 11 changed files with 26 additions and 26 deletions.
10 changes: 5 additions & 5 deletions src/Agent/NewRelic/Agent/Core/Agent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -410,17 +410,17 @@ public void RecordLogMessage(string frameworkName, object logEvent, Func<object,
{
_agentHealthReporter.ReportLogForwardingFramework(frameworkName);

var normalizedLevel = string.Empty;
var normalizedLogLevel = string.Empty;
if (_configurationService.Configuration.LogMetricsCollectorEnabled ||
_configurationService.Configuration.LogEventCollectorEnabled)
{
var logLevel = getLogLevel(logEvent).ToString();
normalizedLevel = string.IsNullOrWhiteSpace(logLevel) ? "UNKNOWN" : logLevel.ToUpper();
normalizedLogLevel = string.IsNullOrWhiteSpace(logLevel) ? "UNKNOWN" : logLevel.ToUpper();
}

if (_configurationService.Configuration.LogMetricsCollectorEnabled)
{
_agentHealthReporter.IncrementLogLinesCount(normalizedLevel);
_agentHealthReporter.IncrementLogLinesCount(normalizedLogLevel);
}

// IOC container defaults to singleton so this will access the same aggregator
Expand All @@ -437,13 +437,13 @@ public void RecordLogMessage(string frameworkName, object logEvent, Func<object,
if (transaction != null && transaction.IsValid)
{
// use transaction batching for messages in transactions
transaction.LogEvents.Add(new LogEventWireModel(timestamp, logMessage, normalizedLevel, spanId, traceId));
transaction.LogEvents.Add(new LogEventWireModel(timestamp, logMessage, normalizedLogLevel, spanId, traceId));
return;
}

// non-transaction messages with proper sanitized priority value
_logEventAggregator.Collect(new LogEventWireModel(timestamp,
logMessage, normalizedLevel, spanId, traceId, _transactionService.CreatePriority()));
logMessage, normalizedLogLevel, spanId, traceId, _transactionService.CreatePriority()));
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class LogEventWireModelCollectionJsonConverter : JsonConverter<LogEventWi
private const string Logs = "logs";
private const string TimeStamp = "timestamp";
private const string Message = "message";
private const string Level = "level";
private const string LogLevel = "log.level";
private const string SpanId = "span.id";
private const string TraceId = "trace.id";

Expand Down Expand Up @@ -59,8 +59,8 @@ private static void WriteJsonImpl(JsonWriter jsonWriter, LogEventWireModelCollec
jsonWriter.WriteValue(logEvent.TimeStamp);
jsonWriter.WritePropertyName(Message);
jsonWriter.WriteValue(logEvent.Message);
jsonWriter.WritePropertyName(Level);
jsonWriter.WriteValue(logEvent.Level);
jsonWriter.WritePropertyName(LogLevel);
jsonWriter.WriteValue(logEvent.LogLevel);

jsonWriter.WritePropertyName(Attributes);
jsonWriter.WriteStartObject();
Expand Down
10 changes: 5 additions & 5 deletions src/Agent/NewRelic/Agent/Core/WireModels/LogEventWireModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class LogEventWireModel : IHasPriority
/// <summary>
/// The log level.
/// </summary>
public string Level { get; }
public string LogLevel { get; }

/// <summary>
/// The span id of the segment.
Expand Down Expand Up @@ -52,20 +52,20 @@ public float Priority
}
}

public LogEventWireModel(long unixTimestampMS, string message, string level, string spanId, string traceId)
public LogEventWireModel(long unixTimestampMS, string message, string logLevel, string spanId, string traceId)
{
TimeStamp = unixTimestampMS;
Message = message.TruncateUnicodeStringByBytes(MaxMessageLengthInBytes);
Level = level;
LogLevel = logLevel;
SpanId = spanId;
TraceId = traceId;
}

public LogEventWireModel(long unixTimestampMS, string message, string level, string spanId, string traceId, float priority)
public LogEventWireModel(long unixTimestampMS, string message, string logLevel, string spanId, string traceId, float priority)
{
TimeStamp = unixTimestampMS;
Message = message.TruncateUnicodeStringByBytes(MaxMessageLengthInBytes);
Level = level;
LogLevel = logLevel;
SpanId = spanId;
TraceId = traceId;
Priority = priority;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -598,7 +598,7 @@ private static LogLine TryFindLogLine(ExpectedLogLine expectedLogLine, IEnumerab
{
foreach (var actualLogLine in actualLogLines)
{
if (expectedLogLine.LogLevel != actualLogLine.Level)
if (expectedLogLine.LogLevel != actualLogLine.LogLevel)
continue;
if (expectedLogLine.LogMessage != actualLogLine.Message)
continue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ public class LogLine
[JsonProperty("message")]
public string Message { get; set; }

[JsonProperty("level")]
public string Level { get; set; }
[JsonProperty("log.level")]
public string LogLevel { get; set; }

[JsonProperty("attributes")]
public LogAttributes Attributes { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public void OnlyOneLogLineIsSent()
Assert.Single(logData.Logs);
var logLine = logData.Logs[0];
Assert.False(string.IsNullOrWhiteSpace(logLine.Message));
Assert.False(string.IsNullOrWhiteSpace(logLine.Level));
Assert.False(string.IsNullOrWhiteSpace(logLine.LogLevel));
Assert.NotEqual(0, logLine.Timestamp);

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ public void CountsAndValuesAreAsExpected()
foreach (var logLine in logLines)
{
Assert.False(string.IsNullOrWhiteSpace(logLine.Message));
Assert.False(string.IsNullOrWhiteSpace(logLine.Level));
Assert.False(string.IsNullOrWhiteSpace(logLine.LogLevel));
Assert.NotEqual(0, logLine.Timestamp);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public void LogEventWireModelCollectionIsJsonSerializable()
"hostname",
new List<LogEventWireModel>()
{
new LogEventWireModel(1, "message", "level", "spanId", "traceId")
new LogEventWireModel(1, "message", "log.level", "spanId", "traceId")
{
Priority = 33.3f
}
Expand All @@ -30,7 +30,7 @@ public void LogEventWireModelCollectionIsJsonSerializable()

Assert.AreEqual(
"{\"common\":{\"attributes\":{\"entity.name\":\"myApplicationName\",\"entity.guid\":\"guid\",\"hostname\":\"hostname\"}}," +
"\"logs\":[{\"timestamp\":1,\"message\":\"message\",\"level\":\"level\"," +
"\"logs\":[{\"timestamp\":1,\"message\":\"message\",\"log.level\":\"log.level\"," +
"\"attributes\":{\"span.id\":\"spanId\",\"trace.id\":\"traceId\"}}]}",
serialized);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public void ConstructorTest()
var loggingEvent = objectUnderTest.LoggingEvents[0];
Assert.AreEqual(1, loggingEvent.TimeStamp);
Assert.AreEqual("TestMessage", loggingEvent.Message);
Assert.AreEqual("TestLevel", loggingEvent.Level);
Assert.AreEqual("TestLevel", loggingEvent.LogLevel);
Assert.AreEqual("TestSpanId", loggingEvent.SpanId);
Assert.AreEqual("TestTraceId", loggingEvent.TraceId);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,17 @@ public void ConstructorTest()
{
var expectedTimestamp = 1234L;
var expectedMessage = "Log Message FTW!";
var expectedLevel = "TestLogLevel";
var expectedLogLevel = "TestLogLevel";
var expectedSpanId = "TestSpanId";
var expectedTraceId = "ExpectedTraceId";
float expectedPriority = 0;

var objectUnderTest = new LogEventWireModel(expectedTimestamp, expectedMessage, expectedLevel, expectedSpanId, expectedTraceId);
var objectUnderTest = new LogEventWireModel(expectedTimestamp, expectedMessage, expectedLogLevel, expectedSpanId, expectedTraceId);

Assert.NotNull(objectUnderTest);
Assert.AreEqual(expectedTimestamp, objectUnderTest.TimeStamp);
Assert.AreEqual(expectedMessage, objectUnderTest.Message);
Assert.AreEqual(expectedLevel, objectUnderTest.Level);
Assert.AreEqual(expectedLogLevel, objectUnderTest.LogLevel);
Assert.AreEqual(expectedSpanId, objectUnderTest.SpanId);
Assert.AreEqual(expectedTraceId, objectUnderTest.TraceId);
Assert.AreEqual(expectedPriority, objectUnderTest.Priority);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1348,7 +1348,7 @@ public void RecordLogMessage_NoTransaction_Success()
Assert.AreEqual(1, logEvents.Count);
Assert.IsNotNull(logEvent);
Assert.AreEqual(timestampUnix, logEvent.TimeStamp);
Assert.AreEqual(level, logEvent.Level);
Assert.AreEqual(level, logEvent.LogLevel);
Assert.AreEqual(message, logEvent.Message);
Assert.AreEqual(spanId, logEvent.SpanId);
Assert.AreEqual(traceId, logEvent.TraceId);
Expand Down Expand Up @@ -1385,7 +1385,7 @@ public void RecordLogMessage_WithTransaction_Success()
Assert.AreEqual(1, transaction.LogEvents.Count);
Assert.IsNotNull(logEvent);
Assert.AreEqual(timestampUnix, logEvent.TimeStamp);
Assert.AreEqual(level, logEvent.Level);
Assert.AreEqual(level, logEvent.LogLevel);
Assert.AreEqual(message, logEvent.Message);
Assert.AreEqual(spanId, logEvent.SpanId);
Assert.AreEqual(traceId, logEvent.TraceId);
Expand Down

0 comments on commit 55863b8

Please sign in to comment.