From c75e8fb8470653235ac8d36ebd4dd4f097a3b13a Mon Sep 17 00:00:00 2001 From: brharrington Date: Wed, 10 Apr 2024 16:16:09 -0500 Subject: [PATCH] lwc-events: support enums as tag values (#1652) Add support for mapping Java Enum types to tag string values. --- .../main/scala/com/netflix/atlas/lwc/events/LwcEvent.scala | 5 +++-- .../scala/com/netflix/atlas/lwc/events/LwcEventSuite.scala | 7 +++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/atlas-lwc-events/src/main/scala/com/netflix/atlas/lwc/events/LwcEvent.scala b/atlas-lwc-events/src/main/scala/com/netflix/atlas/lwc/events/LwcEvent.scala index 3f3da1d1b..00fb7daae 100644 --- a/atlas-lwc-events/src/main/scala/com/netflix/atlas/lwc/events/LwcEvent.scala +++ b/atlas-lwc-events/src/main/scala/com/netflix/atlas/lwc/events/LwcEvent.scala @@ -43,8 +43,9 @@ trait LwcEvent { */ def tagValue(key: String): String = { extractValue(key) match { - case v: String => v - case _ => null + case v: String => v + case e: Enum[_] => e.name() + case _ => null } } diff --git a/atlas-lwc-events/src/test/scala/com/netflix/atlas/lwc/events/LwcEventSuite.scala b/atlas-lwc-events/src/test/scala/com/netflix/atlas/lwc/events/LwcEventSuite.scala index 2c711723f..7d88b4b1d 100644 --- a/atlas-lwc-events/src/test/scala/com/netflix/atlas/lwc/events/LwcEventSuite.scala +++ b/atlas-lwc-events/src/test/scala/com/netflix/atlas/lwc/events/LwcEventSuite.scala @@ -18,6 +18,8 @@ package com.netflix.atlas.lwc.events import com.netflix.atlas.core.util.SortedTagMap import munit.FunSuite +import java.lang.System.Logger + class LwcEventSuite extends FunSuite { import LwcEventSuite.* @@ -33,6 +35,10 @@ class LwcEventSuite extends FunSuite { assertEquals(sampleLwcEvent.tagValue("node"), "i-123") } + test("tagValue: enum") { + assertEquals(sampleLwcEvent.tagValue("level"), "TRACE") + } + test("tagValue: missing") { assertEquals(sampleLwcEvent.tagValue("foo"), null) } @@ -80,6 +86,7 @@ object LwcEventSuite { key match { case "tags" => span.tags case "duration" => span.duration + case "level" => Logger.Level.TRACE case k => span.tags.getOrElse(k, null) } }