in lib/instrumentation/transaction.js [47:111]
function Transaction(agent, name, ...args) {
const opts =
typeof args[args.length - 1] === 'object' ? args.pop() || {} : {};
if (opts.timer) {
// Before 4.x this option could be passed in. It was never publicly documented.
delete opts.timer;
}
if (opts.tracestate) {
opts.tracestate = TraceState.fromStringFormatString(opts.tracestate);
}
if (opts.childOf) {
// Possibly restart the trace, depending on `traceContinuationStrategy`.
// Spec: https://github.com/elastic/apm/blob/main/specs/agents/trace-continuation.md
let traceContinuationStrategy = agent._conf.traceContinuationStrategy;
if (
traceContinuationStrategy === TRACE_CONTINUATION_STRATEGY_RESTART_EXTERNAL
) {
traceContinuationStrategy = TRACE_CONTINUATION_STRATEGY_RESTART;
if (opts.tracestate && opts.tracestate.toMap().has('es')) {
traceContinuationStrategy = TRACE_CONTINUATION_STRATEGY_CONTINUE;
}
}
if (traceContinuationStrategy === TRACE_CONTINUATION_STRATEGY_RESTART) {
if (!opts.links || !Array.isArray(opts.links)) {
opts.links = [];
}
opts.links.push({ context: opts.childOf });
delete opts.childOf; // restart the trace
delete opts.tracestate;
}
}
this.type = null;
this.setType(...args);
GenericSpan.call(this, agent, opts);
const verb = this.parentId ? 'continue' : 'start';
agent.logger.debug('%s trace %o', verb, {
trans: this.id,
parent: this.parentId,
trace: this.traceId,
sampled: this.sampled,
name: this.name,
type: this.type,
traceparent: this.traceparent,
});
this._defaultName = name || '';
this._customName = '';
this._user = null;
this._custom = null;
this._result = constants.RESULT_SUCCESS;
this._builtSpans = 0;
this._droppedSpans = 0;
this._breakdownTimings = new ObjectIdentityMap();
this._faas = undefined;
this._service = undefined;
this._message = undefined;
this._cloud = undefined;
this._droppedSpansStats = new DroppedSpansStats();
this.outcome = constants.OUTCOME_UNKNOWN;
}