-
Notifications
You must be signed in to change notification settings - Fork 31
Money in Scala
Money is built primarily with Scala (and Akka), so the Money Scala API provides constructs that take advantage of Functions to make it simple to add tracing to your code.
Add the Money Dependencies you need to your build. Money is cross-compiled for Scala 2.10 and Scala 2.11.
libraryDependencies += "com.comcast.money" %% "money-core" % "${money.version}"Money provides a standard function wrapper to allow you to start and stop spans around a block of code.
import com.comcast.money.core.Tracers._
def somethingMeaningful() = traced("something") {
... make it worthwhile ...
}"traced" is a simple wrapper function that does a "startSpan" and "stopSpan" around the code block.
Recording notes is simple, using the record functions on the Tracer object. The main tracer can be found on the Money object. You should use this Tracer for all of your tracing needs.
Just like Java, you can only record Strings, Longs, Boolean, and Double types
import com.comcast.money.core.Tracers._
import com.comcast.momey.core.Money.tracer
def somethingMeaningful(Long indexSize) = traced("something") {
// associate a note "meaningful" with a value indexSize with the span named "something"
tracer.record("meaningful", indexSize)
}Timers are a mechanism that allow you to capture the duration of some operation. The simplest way to use timers is to wrap the function that you want in a timed wrapper.
import com.comcast.money.core.Tracers._
def timeThisChumpie() = timed("chumpie") {
... do your stuff here
}Besides the timed function wrapper, you can manually use the Tracer.startTimer and Tracer.stopTimer APIs.
import com.comcast.money.core.Tracers._
import com.comcast.momey.core.Money.tracer
def doSomething(index:Seq[String]) = traced("chumpie") {
tracer.startTimer("fun-with-money")
}
def finishIt() {
tracer.stopTimer("fun-with-money")
}- Overview
- Configuration
- Logging Setup
- Performance Considerations
- Java Users Guide
- Scala Users Guide
- Modules
- Contributing