Skip to content
This repository has been archived by the owner on Aug 31, 2021. It is now read-only.

💥 add opentracing support to Remit #84

Merged
merged 13 commits into from
Mar 25, 2019
Merged

Conversation

jpwilliams
Copy link
Owner

@jpwilliams jpwilliams commented Jun 6, 2018

Adds OpenTracing support to Remit! 🎉

You can pass in any tracer under the tracer key when creating a Remit instance and it'll push spans to that tracer! Awesome!

// public libs
const Remit = require('remit')
const { initTracer } = require('jaeger-client')

// setup
const serviceName = 'my.service'
const tracer = initTracer({ serviceName })

const remit = Remit({
  tracer,
  name: serviceName
})

// all calls are now traced!
// ...

So far only tested with Jaeger and needs a lot more looking at to prove that it works as intended, as well as tests (OpenTracing's no-op default Tracer provides a report function that can help with this, perhaps?) and docs.

screen shot 2018-06-05 at 09 57 26

Tracers that are currently "officially" supported are:

Pass in a tracer as an option when creating a Remit instance and watch it fly!
@jpwilliams
Copy link
Owner Author

Because the lib currently uses jeff-lewis/cls-hooked for passing tracing context in-process, other pieces (Express, GraphQL, etc) will find it hard to communicate fully with Remit, as the parent context is decided via usage of this hook.

For that reason, it may also be pertinent to allow the passing of a namespace to Remit upon instantiation that'll be used to get/set contexts.

This might look something like:

// public libs
const { getNamespace } = require('cls-hooked')
const Remit = require('remit')

// setup
const session = getNamespace('tracing')
const remit = Remit({ namespace: session })

// Remit will use this same namespace to fetch the parent
// context of traces internally.
session.set('context', myParentContext)

Madness or something that'd be required for more complex traces (i.e. combining the tracing functionalities of multiple libraries)?

@jacktuck
Copy link
Collaborator

jacktuck commented Jun 7, 2018

@jpwilliams This looks solid by the way had a glance earlier need time to dig in a bit more though. As for your last comment. That's a super interesting question - a similar one is asked here opentracing/specification#23 - consensus seems to be that it's quite hard to do.

@jacktuck
Copy link
Collaborator

jacktuck commented Jun 7, 2018

More detailed examples here: https://github.com/opentracing/opentracing.io/blob/master/_docs/pages/instrumentation/common-use-cases.md#in-process-request-context-propagation . It seems you have to be more intentional about what metrics are sent which seems fine to me at least.

@jacktuck
Copy link
Collaborator

jacktuck commented Jun 7, 2018

Cheeky question: If we wanted Explicit Propagation would labelling blocks help at all for JS?

var str = "";

loop1:
for (var i = 0; i < 5; i++) {
  if (i === 1) {
    continue loop1;
  }
  str = str + i;
}

console.log(str);
// expected output: "0234"

Could we get a span for loop1 and associate it with the current process

@jpwilliams
Copy link
Owner Author

@jacktuck Great find on that OpenTracing spec ticket! Interesting to see that it's an ongoing concern. Will definitely stick with jeff-lewis/cls-hooked for now as it's nice for the user to not have to think about it at all. (In fact, we need this, otherwise users would have to explicitly pass in parent contexts to make tracing work, which just seems mad.)

With there being no set way to proceed, I'm tempted to allow the injection of a namespace as above and see how that goes; we can happily switch to a "standard" method if one comes along from OpenTracing.

Not sure I follow your labels example. Whatchya wanting to measure there?

@jacktuck
Copy link
Collaborator

jacktuck commented Jun 8, 2018

@jpwilliams Yeah ignore the labelled block thingy haha. I guess if remit exposes opentracing users can always insert their own spans to measure different parts within the same process.

@jpwilliams
Copy link
Owner Author

@jacktuck Yeah exactly that. Interesting. I'll add it in here when I have time and then test it out with some Express/GraphQL bits to see how easy it integrates.

@jackjacek
Copy link

Can't wait for this to be merged ❤️

This also allows users to pass in the namespace used for this, letting them sync up the usage across multiple libraries.
@jpwilliams
Copy link
Owner Author

This is looking pretty sorted to me. Can I get a review @jacktuck / @jackjacek?

The OpenTracing client provides a MockTracer that's intended to be used for debugging/testing purposes, but turns out it doesn't yet support inject or extract which are both pretty crucial to the cross-process nature of the tracing. If I can find a pretty solution that I can redo the old tracing tests with the new format and see that they line up.

Copy link
Collaborator

@jacktuck jacktuck left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just some observations which could be non-issues.

lib/Remit.js Show resolved Hide resolved
lib/Request.js Show resolved Hide resolved
lib/Request.js Show resolved Hide resolved
lib/Request.js Show resolved Hide resolved
@jpwilliams jpwilliams merged commit 7a3339d into master Mar 25, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants