Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Plugin API: Add createChildSpan #373

Merged
merged 5 commits into from
Feb 8, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 10 additions & 36 deletions src/trace-plugin-interface.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,29 +100,6 @@ Transaction.prototype.getTraceContext = function() {
return this.serializedTraceContext_;
};

/**
* 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.
* @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.
* @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
Expand Down Expand Up @@ -209,26 +186,23 @@ PluginAPI.prototype.runInRootSpan = 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 root
* 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.
* 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.runInChildSpan = 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 fn(new ChildSpan(transaction.agent_, childContext));
return new ChildSpan(this.agent_, childContext);
} else {
this.logger_.warn(options.name + ': Attempted to run in child span ' +
this.logger_.warn(options.name + ': Attempted to create child span ' +
'without root');
return fn(null);
return null;
}
};

Expand Down