Skip to content

Commit 538f959

Browse files
author
Jeel Mehta
committed
Adding a custom log to verify the validation
1 parent 427b4b1 commit 538f959

File tree

3 files changed

+18
-8
lines changed
  • sample-apps/python/django_frontend_service/frontend_service_app
  • validator/src/main

3 files changed

+18
-8
lines changed

sample-apps/python/django_frontend_service/frontend_service_app/views.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ def run_scheduler():
4747
run_local_root_client_call_recurring_service()
4848

4949
def healthcheck(request):
50+
logger.warn("This is a custom log for validation testing")
5051
return HttpResponse("healthcheck")
5152

5253
def aws_sdk_call(request):

validator/src/main/java/com/amazon/aoc/validators/CWLogValidator.java

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ public void validate() throws Exception {
6868
Map<String, Object> actualLog;
6969

7070
if (isOtlpSigV4Log(expectedAttributes)) {
71-
actualLog = this.getActualOtlpSigV4Log();
71+
String traceId = (String) expectedAttributes.get("traceId");
72+
actualLog = this.getActualOtlpSigV4Log(traceId);
7273
} else {
7374
String operation = (String) expectedAttributes.get("Operation");
7475
String remoteService = (String) expectedAttributes.get("RemoteService");
@@ -234,12 +235,20 @@ private Map<String, Object> getActualOtelSpanLog(String operation, String remote
234235
return JsonFlattener.flattenAsMap(retrievedLogs.get(0).getMessage());
235236
}
236237

237-
private Map<String, Object> getActualOtlpSigV4Log() throws Exception {
238-
// Filter pattern to match OTLP SigV4 logs
239-
String filterPattern = String.format(
240-
"{ ($.attributes.otelServiceName = \"%s\") }",
241-
context.getServiceName()
242-
);
238+
private Map<String, Object> getActualOtlpSigV4Log(String traceId) throws Exception {
239+
String filterPattern;
240+
if (traceId != null && !traceId.isEmpty()) {
241+
filterPattern = String.format(
242+
"{ ($.attributes.otelServiceName = \"%s\") && ($.traceId = \"%s\") && ($.body = \"This is a custom log for validation testing\") }",
243+
context.getServiceName(),
244+
traceId
245+
);
246+
} else {
247+
filterPattern = String.format(
248+
"{ ($.attributes.otelServiceName = \"%s\") && ($.body = \"This is a custom log for validation testing\") }",
249+
context.getServiceName()
250+
);
251+
}
243252
log.info("Filter Pattern for OTLP SigV4 Log Search: " + filterPattern);
244253

245254
List<FilteredLogEvent> retrievedLogs =

validator/src/main/resources/expected-data-template/python/ec2/adot-sigv4/logs/log.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
},
1212
"severityNumber": "^[0-9]+$",
1313
"severityText": "{{severityText}}",
14-
"body": "{{body}}",
14+
"body": "This is a custom log for validation testing",
1515
"traceId": "{{traceId}}",
1616
"spanId": "{{spanId}}",
1717
"attributes": {

0 commit comments

Comments
 (0)