Skip to content

Commit

Permalink
refactor event id in demo and tests (Azure#44797)
Browse files Browse the repository at this point in the history
  • Loading branch information
TimothyMothra authored Jul 1, 2024
1 parent 250b92c commit b9407b6
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ private static async Task GenerateTelemetry()

_logger?.Log(
logLevel: LogLevel.Information,
eventId: 0,
eventId: 1,
exception: null,
message: "Hello {name}.",
args: new object[] { "World" });
Expand All @@ -162,7 +162,7 @@ private static async Task GenerateTelemetry()
{
_logger?.Log(
logLevel: LogLevel.Error,
eventId: 0,
eventId: 2,
exception: ex,
message: "Hello {name}.",
args: new object[] { "World" });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ public static void AssertLog_As_ExceptionTelemetry(
string expectedSeverityLevel,
string expectedMessage,
string expectedTypeName,
IDictionary<string, string> expectedProperties,
string expectedCloudRole = "[testNamespace]/testName",
string expectedCloudInstance = "testInstance",
string expectedApplicationVersion = "testVersion")
Expand All @@ -93,6 +94,11 @@ public static void AssertLog_As_ExceptionTelemetry(
Assert.Equal(expectedTypeName, telemetryExceptionDetails.TypeName);
Assert.True(telemetryExceptionDetails.ParsedStack.Any());
Assert.Null(telemetryExceptionDetails.Stack);

foreach (var prop in expectedProperties)
{
Assert.Equal(prop.Value, telemetryExceptionData.Properties[prop.Key]);
}
}

public static void AssertActivity_As_DependencyTelemetry(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public void VerifyLog(LogLevel logLevel, string expectedSeverityLevel)
var logger = loggerFactory.CreateLogger(logCategoryName);
logger.Log(
logLevel: logLevel,
eventId: 0,
eventId: 1,
exception: null,
message: "Hello {name}.",
args: new object[] { "World" });
Expand All @@ -83,7 +83,7 @@ public void VerifyLog(LogLevel logLevel, string expectedSeverityLevel)
telemetryItem: telemetryItem!,
expectedSeverityLevel: expectedSeverityLevel,
expectedMessage: "Hello {name}.",
expectedMessageProperties: new Dictionary<string, string> { { "name", "World" }},
expectedMessageProperties: new Dictionary<string, string> { { "EventId", "1" }, { "name", "World" }},
expectedSpanId: null,
expectedTraceId: null);
}
Expand Down Expand Up @@ -126,7 +126,7 @@ public void VerifyException(LogLevel logLevel, string expectedSeverityLevel)
{
logger.Log(
logLevel: logLevel,
eventId: 0,
eventId: 1,
exception: ex,
message: "Hello {name}.",
args: new object[] { "World" });
Expand All @@ -144,7 +144,8 @@ public void VerifyException(LogLevel logLevel, string expectedSeverityLevel)
telemetryItem: telemetryItem!,
expectedSeverityLevel: expectedSeverityLevel,
expectedMessage: "Test Exception",
expectedTypeName: "System.Exception");
expectedTypeName: "System.Exception",
expectedProperties: new Dictionary<string, string> { { "EventId", "1" } });
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ public void VerifyLogWithinActivity(LogLevel logLevel, string expectedSeverityLe

logger.Log(
logLevel: logLevel,
eventId: 0,
eventId: 1,
exception: null,
message: "Hello {name}.",
args: new object[] { "World" });
Expand Down Expand Up @@ -295,7 +295,7 @@ public void VerifyLogWithinActivity(LogLevel logLevel, string expectedSeverityLe
telemetryItem: logTelemetryItem!,
expectedSeverityLevel: expectedSeverityLevel,
expectedMessage: "Hello {name}.",
expectedMessageProperties: new Dictionary<string, string> { { "name", "World" } },
expectedMessageProperties: new Dictionary<string, string> { {"EventId", "1" }, { "name", "World" } },
expectedSpanId: spanId,
expectedTraceId: traceId);
}
Expand Down

0 comments on commit b9407b6

Please sign in to comment.