rochdev / datadog-tracer-js

[DEPRECATED] OpenTracing tracer implementation for Datadog in JavaScript.
MIT License
39 stars 8 forks source link

Examples of linking spans together #35

Closed bizob2828 closed 7 years ago

bizob2828 commented 7 years ago

I'm trying to wrap my head around creating relationships to spans. This mentions passing the context https://github.com/opentracing/specification/blob/master/specification.md. do you have any recommendations here? Do you just create a span and then pass the instance to the respective modules you want to relate to that span? I see this https://github.com/opentracing/opentracing-javascript/blob/master/src/examples/demo/demo.ts but it's too trivial and not reflective of an actual use case of tracing the db calls down the stack

rochdev commented 7 years ago

@bizob2828 See https://opentracing-javascript.surge.sh/classes/tracer.html#startspan for a simple yet complete example of span relationships.

Basically when calling startSpan to create the child you have to pass either the parent span or parent span context as a childOf option.

References are for more advanced use cases where you want the second span to be related to the first span yet not as a child (for example starting an asynchronous job without waiting for its result).

If the parent span depends on the result of the child span to finish, then definitely use childOf.

Hope this helps. I will try to add a more complete example this weekend.

rochdev commented 7 years ago

@bizob2828 Were you able to resolve your issue? If not please provide more details on your exact use case and I will build an example around it.

rochdev commented 7 years ago

@bizob2828 I'll close this for now as I'm not sure how I could provide a better example without the specific use case. I'll reopen the issue if you still feel it's needed.

bizob2828 commented 7 years ago

No problem. I've moved on and use new relic. I know data dog is working on their node.js apm and plan on using it when it's available. I was able to whip some stuff up for this but not sure if they are in a branch or not.

rochdev commented 7 years ago

@bizob2828 May I ask what made NewRelic easier to implement? I will try to improve this library in the same fashion.

Also, do you have more information about the official node.js Datadog library? I was unable to find anything on that and would be interested to join effort with them.

bizob2828 commented 7 years ago

They have a fully supported APM for many common npm modules. So there is no custom tracing required. Also they have a simple module to instrument other modules they don't support. It's all on https://blog.newrelic.com/2014/09/16/nodejs-custom-instrumentation/. I was told Q3 datadog npm module. You may want to take at new relic's custom tracer because it's a lower point of entry because it wraps lower level apis to know when a call finished first manually adding spans. Also if you look at newrelic or opbeat apm they use a lib called shimmer, seems easier than relying on this opentracing spec