aboutsummaryrefslogtreecommitdiff
path: root/src/main/scala/Span.scala
blob: f5851f4708433f3a6560800c6b09076fd31e6b27 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
package xyz.driver.tracing

import java.time._
import java.util.UUID

case class Span(
    name: String,
    traceId: UUID = UUID.randomUUID(),
    spanId: UUID = UUID.randomUUID(),
    parentSpanId: Option[UUID] = None,
    labels: Map[String, String] = Map.empty,
    startTime: Instant = Instant.now,
    endTime: Instant = Instant.now
) {

  def start(clock: Clock = Clock.systemUTC): Span =
    this.copy(startTime = clock.instant())
  def end(clock: Clock = Clock.systemUTC): Span =
    this.copy(endTime = clock.instant())

  def withLabels(extraLabels: (String, String)*) =
    this.copy(labels = this.labels ++ extraLabels)

}