Skip to content
This repository has been archived by the owner on Oct 23, 2019. It is now read-only.

Parent not nesting lower traces #100

Closed
AkhilJ876 opened this issue Jun 10, 2016 · 1 comment
Closed

Parent not nesting lower traces #100

AkhilJ876 opened this issue Jun 10, 2016 · 1 comment

Comments

@AkhilJ876
Copy link

Build.sbt:

scalaVersion := "2.11.8"

///////////////////////////////////////////////////////////////////////////////
//     DEPENDENCIES

libraryDependencies ++= Seq(
  "com.twitter" %% "finagle-http" % "6.34.0",
  "com.twitter.common"   %  "metrics"           %   "0.0.37",
  "com.twitter"                     %%  "twitter-server"           %  "1.19.0",
  "com.twitter"                     %%  "finagle-zipkin"          %   "6.34.0"
)

And the code for the same:

object ZipkinTestServer extends App {
  val tracer = ZipkinTracer.mk(host = "192.168.99.100", port = 9410, statsReceiver = new NullStatsReceiver, sampleRate = 1.0F)
  val myService = new UserResponse
  val server = Http.server.withTracer(tracer).configured(Label("ZipkinTestServer")).serve(":8081", myService)
  Await.ready(server)

}

class UserResponse extends Service[Request, Response] {
  def apply(request: Request) = {

    val response = Response(Version.Http11, Status.Ok)
    val responseString = futureFunc1(request)

    println(responseString)
    twitter2ScalaFuture[Response].invert(responseString map {
      case a =>
        println("Inside Success" + a)
        response.setContentString(a)
        response
    })

  }

  def futureFunc1(req: Request): SFuture[String] = {
    Trace.letId(Trace.nextId) {
      Trace.recordServiceName(s"Function:UserResponse")
      Trace.recordRpc(req.path)
      Trace.record(Annotation.ClientSend())

      // Call to lower Function/Service
      val func2String = futureFunc2()
      if (Trace.isActivelyTracing) {

        func2String.onSuccess {
          case _ => Trace.record(Annotation.ClientRecv())
        }
        func2String.onFailure {
          case t => Trace.record(Annotation.ClientRecvError(t.getMessage))
        }
      }
      func2String
    }
  }

  def futureFunc2(): SFuture[String] = {
    SFuture {
      val str = "Hello World"
      str
    }
  }
}

As we can see that parent completes before the lower services.And hence nesting is not done properly.Any pointers what is done wrong here?

image

@AkhilJ876
Copy link
Author

It seems like i was trying to complicate the issue..
We just needed to do something like this:

Trace.traceService("Function1","Test")

image

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant