MCPcopy Create free account
hub / github.com/getsentry/sentry-javascript / constructor

Method constructor

packages/core/src/tracing/sentrySpan.ts:84–118  ·  view source on GitHub ↗

* You should never call the constructor manually, always use `Sentry.startSpan()` * or other span methods. * @internal * @hideconstructor * @hidden

(spanContext: SentrySpanArguments = {})

Source from the content-addressed store, hash-verified

82 * @hidden
83 */
84 public constructor(spanContext: SentrySpanArguments = {}) {
85 this._traceId = spanContext.traceId || generateTraceId();
86 this._spanId = spanContext.spanId || generateSpanId();
87 this._startTime = spanContext.startTimestamp || timestampInSeconds();
88 this._links = spanContext.links;
89
90 this._attributes = {};
91 this.setAttributes({
92 [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'manual',
93 [SEMANTIC_ATTRIBUTE_SENTRY_OP]: spanContext.op,
94 ...spanContext.attributes,
95 });
96
97 this._name = spanContext.name;
98
99 if (spanContext.parentSpanId) {
100 this._parentSpanId = spanContext.parentSpanId;
101 }
102 // We want to include booleans as well here
103 if ('sampled' in spanContext) {
104 this._sampled = spanContext.sampled;
105 }
106 if (spanContext.endTimestamp) {
107 this._endTime = spanContext.endTimestamp;
108 }
109
110 this._events = [];
111
112 this._isStandaloneSpan = spanContext.isStandalone;
113
114 // If the span is already ended, ensure we finalize the span immediately
115 if (this._endTime) {
116 this._onSpanEnded();
117 }
118 }
119
120 /** @inheritDoc */
121 public addLink(link: SpanLink): this {

Callers

nothing calls this directly

Calls 5

setAttributesMethod · 0.95
_onSpanEndedMethod · 0.95
generateTraceIdFunction · 0.90
generateSpanIdFunction · 0.90
timestampInSecondsFunction · 0.90

Tested by

no test coverage detected