_startSpan()

in packages/rum-core/src/opentracing/tracer.js [52:102]


  _startSpan(name, options) {
    var spanOptions = { managed: true }
    if (options) {
      spanOptions.timestamp = options.startTime
      if (options.childOf) {
        spanOptions.parentId = options.childOf.id
      } else if (options.references && options.references.length > 0) {
        if (options.references.length > 1) {
          if (__DEV__) {
            this.loggingService.debug(
              // eslint-disable-next-line
              'Elastic APM OpenTracing: Unsupported number of references, only the first childOf reference will be recorded.'
            )
          }
        }

        var childRef = find(options.references, function (ref) {
          return ref.type() === REFERENCE_CHILD_OF
        })
        if (childRef) {
          spanOptions.parentId = childRef.referencedContext().id
        }
      }
    }

    var span
    var currentTransaction = this.transactionService.getCurrentTransaction()

    if (currentTransaction) {
      span = this.transactionService.startSpan(name, undefined, spanOptions)
    } else {
      span = this.transactionService.startTransaction(
        name,
        undefined,
        spanOptions
      )
    }

    if (!span) {
      return new NoopSpan()
    }

    if (spanOptions.timestamp) {
      span._start = spanOptions.timestamp - getTimeOrigin()
    }
    var otSpan = new Span(this, span)
    if (options && options.tags) {
      otSpan.addTags(options.tags)
    }
    return otSpan
  }