Created
November 18, 2015 20:20
-
-
Save leonmaia/d1dd15a98417fa75e5f8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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