Skip to content

Commit

Permalink
lwc: add timestamp accessor (Netflix#1542)
Browse files Browse the repository at this point in the history
When mapping to time series data points, we need to know
the timestamp for an event. For events like spans that
have a start and end, the end time is used. This is similar
behvavior to a timer which would get updated at the end when
the latency is known.
  • Loading branch information
brharrington authored and manolama committed May 22, 2024
1 parent 1e75979 commit 6300b4b
Showing 1 changed file with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ trait LwcEvent {
/** Raw event object that is being considered. */
def rawEvent: Any

/**
* Timestamp for the event. If it is an event such as a span that has a start and end,
* the timestamp should be for the end of the event.
*/
def timestamp: Long

/**
* Extract a tag value for a given key. Returns `null` if there is no value for
* the key or the value is not a string. By default it will delegate to `extractValue`
Expand Down Expand Up @@ -86,7 +92,8 @@ trait LwcEvent {
object LwcEvent {

/**
* Wrap an object as an LWC event.
* Wrap an object as an LWC event. The timestamp will be the time when the event is
* wrapped.
*
* @param rawEvent
* Raw event object to wrap.
Expand All @@ -102,6 +109,8 @@ object LwcEvent {

private case class BasicLwcEvent(rawEvent: Any, extractor: String => Any) extends LwcEvent {

override val timestamp: Long = System.currentTimeMillis()

override def extractValue(key: String): Any = extractor(key)

override def encode(gen: JsonGenerator): Unit = {
Expand Down

0 comments on commit 6300b4b

Please sign in to comment.