Skip to content

Commit

Permalink
lwc-events: support enums as tag values (#1652)
Browse files Browse the repository at this point in the history
Add support for mapping Java Enum types to tag string values.
  • Loading branch information
brharrington authored Apr 10, 2024
1 parent b8af6f3 commit c75e8fb
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.*
Expand All @@ -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)
}
Expand Down Expand Up @@ -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)
}
}
Expand Down

0 comments on commit c75e8fb

Please sign in to comment.