MCPcopy
hub / github.com/vercel/next.js / NextTracerImpl

Class NextTracerImpl

packages/next/src/server/lib/trace/tracer.ts:202–509  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

200}
201
202class NextTracerImpl implements NextTracer {
203 /**
204 * Returns an instance to the trace with configured name.
205 * Since wrap / trace can be defined in any place prior to actual trace subscriber initialization,
206 * This should be lazily evaluated.
207 */
208 private getTracerInstance(): Tracer {
209 return trace.getTracer('next.js', '0.0.1')
210 }
211
212 public getContext(): ContextAPI {
213 return context
214 }
215
216 public getTracePropagationData(): ClientTraceDataEntry[] {
217 const activeContext = context.active()
218 const entries: ClientTraceDataEntry[] = []
219 propagation.inject(activeContext, entries, clientTraceDataSetter)
220 return entries
221 }
222
223 public getActiveScopeSpan(): Span | undefined {
224 return trace.getSpan(context?.active())
225 }
226
227 public withPropagatedContext<T, C>(
228 carrier: C,
229 fn: () => T,
230 getter?: TextMapGetter<C>,
231 force = false
232 ): T {
233 const activeContext = context.active()
234
235 if (force) {
236 const remoteContext = propagation.extract(ROOT_CONTEXT, carrier, getter)
237
238 if (trace.getSpanContext(remoteContext)) {
239 return context.with(remoteContext, fn)
240 }
241
242 // Preserve the current active span while still merging any extracted
243 // baggage/context values from the carrier.
244 const mergedContext = propagation.extract(activeContext, carrier, getter)
245 return context.with(mergedContext, fn)
246 }
247
248 if (trace.getSpanContext(activeContext)) {
249 // Active span is already set, too late to propagate.
250 return fn()
251 }
252
253 const remoteContext = propagation.extract(activeContext, carrier, getter)
254 return context.with(remoteContext, fn)
255 }
256
257 // Trace, wrap implementation is inspired by datadog trace implementation
258 // (https://datadoghq.dev/dd-trace-js/interfaces/tracer.html#trace).
259 public trace<T>(

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected