src/span-data.js
function SpanData(agent, trace, name, parentSpanId, isRoot, skipFrames) {
  var spanId = uid++;
  this.agent = agent;
  var spanName = traceUtil.truncate(name, constants.TRACE_SERVICE_SPAN_NAME_LIMIT);
  this.span = new TraceSpan(spanName, spanId, parentSpanId);
  this.trace = trace;
  this.isRoot = isRoot;
  trace.spans.push(this.span);
  if (agent.config().stackTraceLimit > 0) {
    // This is a mechanism to get the structured stack trace out of V8.
    // prepareStackTrace is called th first time the Error#stack property is
    // accessed. The original behavior is to format the stack as an exception
    // throw, which is not what we like. We customize it.
    //
    // See: https://code.google.com/p/v8-wiki/wiki/JavaScriptStackTraceApi
    //
    var origLimit = Error.stackTraceLimit;
    Error.stackTraceLimit = agent.config().stackTraceLimit + skipFrames;

    var origPrepare = Error.prepareStackTrace;
    Error.prepareStackTrace = function(error, structured) {
      return structured;
    };
    var e = {};
    Error.captureStackTrace(e, SpanData);

    var stackFrames = [];
    e.stack.forEach(function(callSite, i) {
      if (i < skipFrames) {
        return;
      }
      var functionName = callSite.getFunctionName();
      var methodName = callSite.getMethodName();
      var name = (methodName && functionName) ?
        functionName + ' [as ' + methodName + ']' :
        functionName || methodName || '<anonymous function>';
      stackFrames.push(new StackFrame(undefined, name,
        callSite.getFileName(), callSite.getLineNumber(),
        callSite.getColumnNumber()));
    });
    // Set the label on the trace span directly to bypass truncation to
    // config.maxLabelValueSize.
    this.span.setLabel(TraceLabels.STACK_TRACE_DETAILS_KEY,
      traceUtil.truncate(JSON.stringify({stack_frame: stackFrames}),
        constants.TRACE_SERVICE_LABEL_VALUE_LIMIT));

    Error.stackTraceLimit = origLimit;
    Error.prepareStackTrace = origPrepare;
  }
}
function SpanData(agent, trace, name, parentSpanId, isRoot, skipFrames) {
  var spanId = uid++;
  this.agent = agent;
  var spanName = traceUtil.truncate(name, constants.TRACE_SERVICE_SPAN_NAME_LIMIT);
  this.span = new TraceSpan(spanName, spanId, parentSpanId);
  this.trace = trace;
  this.isRoot = isRoot;
  trace.spans.push(this.span);
  if (agent.config().stackTraceLimit > 0) {
    // This is a mechanism to get the structured stack trace out of V8.
    // prepareStackTrace is called th first time the Error#stack property is
    // accessed. The original behavior is to format the stack as an exception
    // throw, which is not what we like. We customize it.
    //
    // See: https://code.google.com/p/v8-wiki/wiki/JavaScriptStackTraceApi
    //
    var origLimit = Error.stackTraceLimit;
    Error.stackTraceLimit = agent.config().stackTraceLimit + skipFrames;

    var origPrepare = Error.prepareStackTrace;
    Error.prepareStackTrace = function(error, structured) {
      return structured;
    };
    var e = {};
    Error.captureStackTrace(e, SpanData);

    var stackFrames = [];
    e.stack.forEach(function(callSite, i) {
      if (i < skipFrames) {
        return;
      }
      var functionName = callSite.getFunctionName();
      var methodName = callSite.getMethodName();
      var name = (methodName && functionName) ?
        functionName + ' [as ' + methodName + ']' :
        functionName || methodName || '<anonymous function>';
      stackFrames.push(new StackFrame(undefined, name,
        callSite.getFileName(), callSite.getLineNumber(),
        callSite.getColumnNumber()));
    });
    // Set the label on the trace span directly to bypass truncation to
    // config.maxLabelValueSize.
    this.span.setLabel(TraceLabels.STACK_TRACE_DETAILS_KEY,
      traceUtil.truncate(JSON.stringify({stack_frame: stackFrames}),
        constants.TRACE_SERVICE_LABEL_VALUE_LIMIT));

    Error.stackTraceLimit = origLimit;
    Error.prepareStackTrace = origPrepare;
  }
}
function SpanData ( agent , trace , name , parentSpanId , isRoot , skipFrames ) { var spanId = uid ++ ; this . agent = agent ; var spanName = traceUtil . truncate ( name , constants . TRACE_SERVICE_SPAN_NAME_LIMIT ) ; this . span = new TraceSpan ( spanName , spanId , parentSpanId ) ; this . trace = trace ; this . isRoot = isRoot ; trace . spans . push ( this . span ) ; if ( agent . config ( ) . stackTraceLimit > 0 ) { // This is a mechanism to get the structured stack trace out of V8. // prepareStackTrace is called th first time the Error#stack property is // accessed. The original behavior is to format the stack as an exception // throw, which is not what we like. We customize it. // // See: https://code.google.com/p/v8-wiki/wiki/JavaScriptStackTraceApi // var origLimit = Error . stackTraceLimit ; Error . stackTraceLimit = agent . config ( ) . stackTraceLimit + skipFrames ; var origPrepare = Error . prepareStackTrace ; Error . prepareStackTrace = function ( error , structured ) { return structured ; } ; var e = { } ; Error . captureStackTrace ( e , SpanData ) ; var stackFrames = [ ] ; e . stack . forEach ( function ( callSite , i ) { if ( i < skipFrames ) { return ; } var functionName = callSite . getFunctionName ( ) ; var methodName = callSite . getMethodName ( ) ; var name = ( methodName && functionName ) ? functionName + ' [as ' + methodName + ']' : functionName || methodName || '<anonymous function>' ; stackFrames . push ( new StackFrame ( undefined , name , callSite . getFileName ( ) , callSite . getLineNumber ( ) , callSite . getColumnNumber ( ) ) ) ; } ) ; // Set the label on the trace span directly to bypass truncation to // config.maxLabelValueSize. this . span . setLabel ( TraceLabels . STACK_TRACE_DETAILS_KEY , traceUtil . truncate ( JSON . stringify ( { stack_frame : stackFrames } ) , constants . TRACE_SERVICE_LABEL_VALUE_LIMIT ) ) ; Error . stackTraceLimit = origLimit ; Error . prepareStackTrace = origPrepare ; } }
Creates a trace context object.
@param {Trace} trace The object holding the spans comprising this trace.
@param {string} name The name of the span.
@param {number} parentSpanId The id of the parent span, 0 for root spans.
@param {boolean} isRoot Whether this is a root span.
@param {number} skipFrames the number of frames to remove from the top of the stack.
@constructor
Creates a trace context object .