| 176 | * it may just be a non-recording span if the span is not sampled or if tracing is disabled. |
| 177 | */ |
| 178 | export function startInactiveSpan(options: StartSpanOptions): Span { |
| 179 | const acs = getAcs(); |
| 180 | if (acs.startInactiveSpan) { |
| 181 | return acs.startInactiveSpan(options); |
| 182 | } |
| 183 | |
| 184 | const spanArguments = parseSentrySpanArguments(options); |
| 185 | const { forceTransaction, parentSpan: customParentSpan } = options; |
| 186 | |
| 187 | // If `options.scope` is defined, we use this as as a wrapper, |
| 188 | // If `options.parentSpan` is defined, we want to wrap the callback in `withActiveSpan` |
| 189 | const wrapper = options.scope |
| 190 | ? (callback: () => Span) => withScope(options.scope, callback) |
| 191 | : customParentSpan !== undefined |
| 192 | ? (callback: () => Span) => withActiveSpan(customParentSpan, callback) |
| 193 | : (callback: () => Span) => callback(); |
| 194 | |
| 195 | return wrapper(() => { |
| 196 | const scope = getCurrentScope(); |
| 197 | const parentSpan = getParentSpan(scope, customParentSpan); |
| 198 | const client = getClient(); |
| 199 | |
| 200 | const missingRequiredParent = options.onlyIfParent && !parentSpan; |
| 201 | |
| 202 | if (missingRequiredParent) { |
| 203 | return startMissingRequiredParentSpan(scope, client); |
| 204 | } |
| 205 | |
| 206 | return createChildOrRootSpan({ |
| 207 | parentSpan, |
| 208 | spanArguments, |
| 209 | forceTransaction, |
| 210 | scope, |
| 211 | }); |
| 212 | }); |
| 213 | } |
| 214 | |
| 215 | /** |
| 216 | * Continue a trace from `sentry-trace` and `baggage` values. |