Skip to content

Instantly share code, notes, and snippets.

@leonmaia
Created November 18, 2015 20:20
Show Gist options
  • Save leonmaia/d1dd15a98417fa75e5f8 to your computer and use it in GitHub Desktop.
Save leonmaia/d1dd15a98417fa75e5f8 to your computer and use it in GitHub Desktop.
package com.lm.newrelic
import com.newrelic.api.agent.{NewRelic, Trace}
import scala.reflect.macros.whitebox
import language.experimental.macros
import scala.annotation.{compileTimeOnly, StaticAnnotation}
class transaction(category: String, name: String) extends StaticAnnotation {
def macroTransform(annottees: Any*) = macro traceMacro.transaction_impl
}
object traceMacro {
def transaction(annottees: Any*) = macro traceMacro.transaction_impl
def transaction_impl(c: whitebox.Context)(annottees: c.Expr[Any]*): c.Expr[Any] = {
import c.universe._
val category = annottees.head
val transaction = annottees.last
c.Expr(
q"""
import com.lm.newrelic.StatsTracing.set
set($category, $transaction)
""")
}
}
object StatsTracing {
@Trace(dispatcher = true)
def set(category: String, name: String): Unit = {
println(s".............Foooo! with $category and $name")
NewRelic.setTransactionName(category, name)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment