From bce78eb0f2606774f23b2653374566fe2b369b7d Mon Sep 17 00:00:00 2001 From: Kelvin Jin Date: Tue, 7 Feb 2017 14:41:43 -0800 Subject: [PATCH 1/5] Add Transaction.createChildSpan --- src/trace-plugin-interface.js | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/trace-plugin-interface.js b/src/trace-plugin-interface.js index 643b78454..3d8405a0e 100644 --- a/src/trace-plugin-interface.js +++ b/src/trace-plugin-interface.js @@ -101,8 +101,8 @@ Transaction.prototype.getTraceContext = function() { }; /** - * Runs the given function in a child span, passing it an object that - * exposes an interface for adding labels and closing the span. + * Runs the given function in a child span nested in the underlying root span + * of this transaction. * @param {object} options An object that specifies options for how the child * span is created and propogated. * @param {string} options.name The name to apply to the child span. @@ -111,6 +111,20 @@ Transaction.prototype.getTraceContext = function() { * @param {?number} options.skipFrames The number of stack frames to skip when * collecting call stack information for the child span, starting from the top; * this should be set to avoid including frames in the plugin. Defaults to 0. + * @returns A new ChildSpan object. + */ +Transaction.prototype.createChildSpan = function(options, fn) { + options = options || {}; + var childContext = this.agent_.startSpan(options.name, {}, + options.skipFrames ? options.skipFrames + 1 : 1); + return new ChildSpan(this.agent_, childContext); +}; + +/** + * Runs the given function in a child span, passing it an object that + * exposes an interface for adding labels and closing the span. + * @param {object} options An object that specifies options for how the child + * span is created and propogated. @see Transaction.prototype.createChildSpan * @param {function(ChildSpan)} fn A function that will be called exactly * once, with a ChildSpan object exposing an interface operating on the child * span. From 5ff2a8493d6a0c6b2a2d557e9c590c5584f05a34 Mon Sep 17 00:00:00 2001 From: Kelvin Jin Date: Tue, 7 Feb 2017 14:47:05 -0800 Subject: [PATCH 2/5] Mirror runInChildSpan convenience method for createChildSpan --- src/trace-plugin-interface.js | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/src/trace-plugin-interface.js b/src/trace-plugin-interface.js index 3d8405a0e..d88ac080e 100644 --- a/src/trace-plugin-interface.js +++ b/src/trace-plugin-interface.js @@ -221,12 +221,34 @@ PluginAPI.prototype.runInRootSpan = function(options, fn) { }); }; +/** + * Convenience method which obtains a Transaction object with getTransaction() + * and creates a new child span nested within this transaction. If there is + * no current Transaction object, this function returns null. + * @param {object} options An object that specifies options for how the child + * span is created and propogated. @see Transaction.prototype.createChildSpan + * @returns A new ChildSpan object, or null if there is no active root span. + */ +PluginAPI.prototype.createChildSpan = function(options, fn) { + var transaction = this.getTransaction(); + if (transaction) { + options = options || {}; + var childContext = transaction.agent_.startSpan(options.name, {}, + options.skipFrames ? options.skipFrames + 1 : 1); + return new ChildSpan(transaction.agent_, childContext); + } else { + this.logger_.warn(options.name + ': Attempted to create child span ' + + 'without root'); + return null; + } +}; + /** * Convenience method which obtains a Transaction object with getTransaction() * and calls its runInChildSpan function on the given arguments. If there is * no current Transaction object, the provided function will be called with * null as an argument. - * @param {object} options An object that specifies options for how the root + * @param {object} options An object that specifies options for how the child * span is created and propogated. @see Transaction.prototype.runInChildSpan * @param {function(?Transaction)} fn A function that will be called exactly * once. @see Transaction.prototype.runInChildSpan From 146ccdce5f6d389f1e21adce96da9a8fb5b16bbc Mon Sep 17 00:00:00 2001 From: Kelvin Jin Date: Tue, 7 Feb 2017 16:33:21 -0800 Subject: [PATCH 3/5] remove runInChildSpan --- src/trace-plugin-interface.js | 42 ----------------------------------- 1 file changed, 42 deletions(-) diff --git a/src/trace-plugin-interface.js b/src/trace-plugin-interface.js index d88ac080e..8734f26fc 100644 --- a/src/trace-plugin-interface.js +++ b/src/trace-plugin-interface.js @@ -120,23 +120,6 @@ Transaction.prototype.createChildSpan = function(options, fn) { return new ChildSpan(this.agent_, childContext); }; -/** - * Runs the given function in a child span, passing it an object that - * exposes an interface for adding labels and closing the span. - * @param {object} options An object that specifies options for how the child - * span is created and propogated. @see Transaction.prototype.createChildSpan - * @param {function(ChildSpan)} fn A function that will be called exactly - * once, with a ChildSpan object exposing an interface operating on the child - * span. - * @returns The return value of calling fn. - */ -Transaction.prototype.runInChildSpan = function(options, fn) { - options = options || {}; - var childContext = this.agent_.startSpan(options.name, {}, - options.skipFrames ? options.skipFrames + 1 : 1); - return fn(new ChildSpan(this.agent_, childContext)); -}; - /** * PluginAPI constructor. Don't call directly - a plugin object will be passed to * plugin themselves @@ -243,31 +226,6 @@ PluginAPI.prototype.createChildSpan = function(options, fn) { } }; -/** - * Convenience method which obtains a Transaction object with getTransaction() - * and calls its runInChildSpan function on the given arguments. If there is - * no current Transaction object, the provided function will be called with - * null as an argument. - * @param {object} options An object that specifies options for how the child - * span is created and propogated. @see Transaction.prototype.runInChildSpan - * @param {function(?Transaction)} fn A function that will be called exactly - * once. @see Transaction.prototype.runInChildSpan - * @returns The return value of calling fn. - */ -PluginAPI.prototype.runInChildSpan = function(options, fn) { - var transaction = this.getTransaction(); - if (transaction) { - options = options || {}; - var childContext = transaction.agent_.startSpan(options.name, {}, - options.skipFrames ? options.skipFrames + 1 : 1); - return fn(new ChildSpan(transaction.agent_, childContext)); - } else { - this.logger_.warn(options.name + ': Attempted to run in child span ' + - 'without root'); - return fn(null); - } -}; - /** * Binds the trace context to the given function. * This is necessary in order to create child spans correctly in functions From 015e3d2c72a811f6d2ce3079054435f08eecca4b Mon Sep 17 00:00:00 2001 From: Kelvin Jin Date: Tue, 7 Feb 2017 16:37:00 -0800 Subject: [PATCH 4/5] Doc change --- src/trace-plugin-interface.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/trace-plugin-interface.js b/src/trace-plugin-interface.js index 8734f26fc..c35296f15 100644 --- a/src/trace-plugin-interface.js +++ b/src/trace-plugin-interface.js @@ -101,7 +101,7 @@ Transaction.prototype.getTraceContext = function() { }; /** - * Runs the given function in a child span nested in the underlying root span + * Creates a child span nested in the underlying root span * of this transaction. * @param {object} options An object that specifies options for how the child * span is created and propogated. From 007a64ae4a2c01575aaae24b924371ab97692549 Mon Sep 17 00:00:00 2001 From: Kelvin Jin Date: Tue, 7 Feb 2017 17:06:56 -0800 Subject: [PATCH 5/5] removed Transaction.prototype.createChildSpan entirely --- src/trace-plugin-interface.js | 26 +++----------------------- 1 file changed, 3 insertions(+), 23 deletions(-) diff --git a/src/trace-plugin-interface.js b/src/trace-plugin-interface.js index c35296f15..ae9a9412b 100644 --- a/src/trace-plugin-interface.js +++ b/src/trace-plugin-interface.js @@ -100,26 +100,6 @@ Transaction.prototype.getTraceContext = function() { return this.serializedTraceContext_; }; -/** - * Creates a child span nested in the underlying root span - * of this transaction. - * @param {object} options An object that specifies options for how the child - * span is created and propogated. - * @param {string} options.name The name to apply to the child span. - * @param {?string} options.traceContext The serialized form of an object that - * contains information about an existing trace context. - * @param {?number} options.skipFrames The number of stack frames to skip when - * collecting call stack information for the child span, starting from the top; - * this should be set to avoid including frames in the plugin. Defaults to 0. - * @returns A new ChildSpan object. - */ -Transaction.prototype.createChildSpan = function(options, fn) { - options = options || {}; - var childContext = this.agent_.startSpan(options.name, {}, - options.skipFrames ? options.skipFrames + 1 : 1); - return new ChildSpan(this.agent_, childContext); -}; - /** * PluginAPI constructor. Don't call directly - a plugin object will be passed to * plugin themselves @@ -212,13 +192,13 @@ PluginAPI.prototype.runInRootSpan = function(options, fn) { * span is created and propogated. @see Transaction.prototype.createChildSpan * @returns A new ChildSpan object, or null if there is no active root span. */ -PluginAPI.prototype.createChildSpan = function(options, fn) { +PluginAPI.prototype.createChildSpan = function(options) { var transaction = this.getTransaction(); if (transaction) { options = options || {}; - var childContext = transaction.agent_.startSpan(options.name, {}, + var childContext = this.agent_.startSpan(options.name, {}, options.skipFrames ? options.skipFrames + 1 : 1); - return new ChildSpan(transaction.agent_, childContext); + return new ChildSpan(this.agent_, childContext); } else { this.logger_.warn(options.name + ': Attempted to create child span ' + 'without root');