diff --git a/README.md b/README.md index 6ba81c87..4498c54c 100644 --- a/README.md +++ b/README.md @@ -9,3 +9,7 @@ Natchez is distributed tracing library for Scala. Please proceed to the [microsite](https://typelevel.org/natchez/) for more information. + +#### AWS Cloud Watch Log Group Name Configuration + +To add an AWS Cloud Watch log group name to the traces, add the `aws_group_name` key in the annotation with the value as log group name. \ No newline at end of file diff --git a/modules/xray/src/main/scala/natchez/xray/XRaySpan.scala b/modules/xray/src/main/scala/natchez/xray/XRaySpan.scala index b36bff69..933a08c5 100644 --- a/modules/xray/src/main/scala/natchez/xray/XRaySpan.scala +++ b/modules/xray/src/main/scala/natchez/xray/XRaySpan.scala @@ -115,7 +115,24 @@ private[xray] final case class XRaySpan[F[_]: Concurrent: Clock: Random]( (goodKeys + ("malformed_keys" -> badKeys.keys .mkString(",") .asJson)) ++ fixedAnnotations - + /* + * `aws_group_name` key in the annotations, when present, sets the AWS CloudWatch log group name. + * It is used to add log details to each trace. + */ + val logGroupValue = allAnnotations.get("aws_group_name") + val awsObject = logGroupValue + .map(lgValue => + JsonObject( + "aws" -> JsonObject( + "cloudwatch_logs" -> Json.arr( + JsonObject( + "log_group" -> lgValue + ).asJson + ) + ).asJson + ) + ) + .getOrElse(JsonObject.empty) JsonObject( "name" -> name.asJson, "id" -> segmentId.asJson, @@ -131,11 +148,12 @@ private[xray] final case class XRaySpan[F[_]: Concurrent: Clock: Random]( "links" -> options.links.asJson, "span.kind" -> options.spanKind.asJson ).asJson - ).deepMerge(exitCase match { - case Canceled => JsonObject.singleton("fault", true.asJson) - case Errored(e) => XRayException(id, e).asJsonObject - case Succeeded => JsonObject.empty - }) + ).deepMerge(awsObject) + .deepMerge(exitCase match { + case Canceled => JsonObject.singleton("fault", true.asJson) + case Errored(e) => XRayException(id, e).asJsonObject + case Succeeded => JsonObject.empty + }) } private def header: String =