next 16.0.2-canary.10 → 16.0.2-canary.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. package/dist/bin/next +1 -1
  2. package/dist/build/index.js +3 -3
  3. package/dist/build/swc/index.js +1 -1
  4. package/dist/build/templates/app-page.js +7 -1
  5. package/dist/build/templates/app-page.js.map +1 -1
  6. package/dist/build/webpack-config.js +2 -2
  7. package/dist/client/app-bootstrap.js +1 -1
  8. package/dist/client/index.js +1 -1
  9. package/dist/compiled/@next/font/dist/google/font-data.json +63 -0
  10. package/dist/compiled/@next/font/dist/google/index.d.ts +40 -0
  11. package/dist/compiled/next-server/pages-api-turbo.runtime.dev.js +1 -1
  12. package/dist/compiled/next-server/pages-api-turbo.runtime.dev.js.map +1 -1
  13. package/dist/compiled/next-server/pages-api-turbo.runtime.prod.js +1 -1
  14. package/dist/compiled/next-server/pages-api-turbo.runtime.prod.js.map +1 -1
  15. package/dist/compiled/next-server/pages-api.runtime.dev.js +1 -1
  16. package/dist/compiled/next-server/pages-api.runtime.dev.js.map +1 -1
  17. package/dist/compiled/next-server/pages-turbo.runtime.dev.js +1 -1
  18. package/dist/compiled/next-server/pages-turbo.runtime.dev.js.map +1 -1
  19. package/dist/compiled/next-server/pages-turbo.runtime.prod.js +1 -1
  20. package/dist/compiled/next-server/pages-turbo.runtime.prod.js.map +1 -1
  21. package/dist/compiled/next-server/pages.runtime.dev.js +1 -1
  22. package/dist/compiled/next-server/pages.runtime.dev.js.map +1 -1
  23. package/dist/esm/build/index.js +3 -3
  24. package/dist/esm/build/swc/index.js +1 -1
  25. package/dist/esm/build/templates/app-page.js +7 -1
  26. package/dist/esm/build/templates/app-page.js.map +1 -1
  27. package/dist/esm/build/webpack-config.js +2 -2
  28. package/dist/esm/client/app-bootstrap.js +1 -1
  29. package/dist/esm/client/index.js +1 -1
  30. package/dist/esm/server/dev/hot-reloader-turbopack.js +1 -1
  31. package/dist/esm/server/dev/hot-reloader-webpack.js +1 -1
  32. package/dist/esm/server/lib/app-info-log.js +1 -1
  33. package/dist/esm/server/lib/start-server.js +1 -1
  34. package/dist/esm/server/lib/trace/tracer.js +6 -5
  35. package/dist/esm/server/lib/trace/tracer.js.map +1 -1
  36. package/dist/esm/shared/lib/errors/canary-only-config-error.js +1 -1
  37. package/dist/server/dev/hot-reloader-turbopack.js +1 -1
  38. package/dist/server/dev/hot-reloader-webpack.js +1 -1
  39. package/dist/server/lib/app-info-log.js +1 -1
  40. package/dist/server/lib/start-server.js +1 -1
  41. package/dist/server/lib/trace/tracer.js +6 -5
  42. package/dist/server/lib/trace/tracer.js.map +1 -1
  43. package/dist/shared/lib/errors/canary-only-config-error.js +1 -1
  44. package/dist/telemetry/anonymous-meta.js +1 -1
  45. package/dist/telemetry/events/session-stopped.js +2 -2
  46. package/dist/telemetry/events/version.js +2 -2
  47. package/package.json +15 -15
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../src/server/lib/trace/tracer.ts"],"sourcesContent":["import type { FetchEventResult } from '../../web/types'\nimport type { TextMapSetter } from '@opentelemetry/api'\nimport type { SpanTypes } from './constants'\nimport { LogSpanAllowList, NextVanillaSpanAllowlist } from './constants'\n\nimport type {\n ContextAPI,\n Span,\n SpanOptions,\n Tracer,\n AttributeValue,\n TextMapGetter,\n} from 'next/dist/compiled/@opentelemetry/api'\nimport { isThenable } from '../../../shared/lib/is-thenable'\n\nconst NEXT_OTEL_PERFORMANCE_PREFIX = process.env.NEXT_OTEL_PERFORMANCE_PREFIX\n\nlet api: typeof import('next/dist/compiled/@opentelemetry/api')\n\n// we want to allow users to use their own version of @opentelemetry/api if they\n// want to, so we try to require it first, and if it fails we fall back to the\n// version that is bundled with Next.js\n// this is because @opentelemetry/api has to be synced with the version of\n// @opentelemetry/tracing that is used, and we don't want to force users to use\n// the version that is bundled with Next.js.\n// the API is ~stable, so this should be fine\nif (process.env.NEXT_RUNTIME === 'edge') {\n api = require('@opentelemetry/api') as typeof import('@opentelemetry/api')\n} else {\n try {\n api = require('@opentelemetry/api') as typeof import('@opentelemetry/api')\n } catch (err) {\n api =\n require('next/dist/compiled/@opentelemetry/api') as typeof import('next/dist/compiled/@opentelemetry/api')\n }\n}\n\nconst { context, propagation, trace, SpanStatusCode, SpanKind, ROOT_CONTEXT } =\n api\n\nexport class BubbledError extends Error {\n constructor(\n public readonly bubble?: boolean,\n public readonly result?: FetchEventResult\n ) {\n super()\n }\n}\n\nexport function isBubbledError(error: unknown): error is BubbledError {\n if (typeof error !== 'object' || error === null) return false\n return error instanceof BubbledError\n}\n\nconst closeSpanWithError = (span: Span, error?: Error) => {\n if (isBubbledError(error) && error.bubble) {\n span.setAttribute('next.bubble', true)\n } else {\n if (error) {\n span.recordException(error)\n span.setAttribute('error.type', error.name)\n }\n span.setStatus({ code: SpanStatusCode.ERROR, message: error?.message })\n }\n span.end()\n}\n\ntype TracerSpanOptions = Omit<SpanOptions, 'attributes'> & {\n parentSpan?: Span\n spanName?: string\n attributes?: Partial<Record<AttributeNames, AttributeValue | undefined>>\n hideSpan?: boolean\n}\n\ninterface NextTracer {\n getContext(): ContextAPI\n\n /**\n * Instruments a function by automatically creating a span activated on its\n * scope.\n *\n * The span will automatically be finished when one of these conditions is\n * met:\n *\n * * The function returns a promise, in which case the span will finish when\n * the promise is resolved or rejected.\n * * The function takes a callback as its second parameter, in which case the\n * span will finish when that callback is called.\n * * The function doesn't accept a callback and doesn't return a promise, in\n * which case the span will finish at the end of the function execution.\n *\n */\n trace<T>(\n type: SpanTypes,\n fn: (span?: Span, done?: (error?: Error) => any) => Promise<T>\n ): Promise<T>\n trace<T>(\n type: SpanTypes,\n fn: (span?: Span, done?: (error?: Error) => any) => T\n ): T\n trace<T>(\n type: SpanTypes,\n options: TracerSpanOptions,\n fn: (span?: Span, done?: (error?: Error) => any) => Promise<T>\n ): Promise<T>\n trace<T>(\n type: SpanTypes,\n options: TracerSpanOptions,\n fn: (span?: Span, done?: (error?: Error) => any) => T\n ): T\n\n /**\n * Wrap a function to automatically create a span activated on its\n * scope when it's called.\n *\n * The span will automatically be finished when one of these conditions is\n * met:\n *\n * * The function returns a promise, in which case the span will finish when\n * the promise is resolved or rejected.\n * * The function takes a callback as its last parameter, in which case the\n * span will finish when that callback is called.\n * * The function doesn't accept a callback and doesn't return a promise, in\n * which case the span will finish at the end of the function execution.\n */\n wrap<T = (...args: Array<any>) => any>(type: SpanTypes, fn: T): T\n wrap<T = (...args: Array<any>) => any>(\n type: SpanTypes,\n options: TracerSpanOptions,\n fn: T\n ): T\n wrap<T = (...args: Array<any>) => any>(\n type: SpanTypes,\n options: (...args: any[]) => TracerSpanOptions,\n fn: T\n ): T\n\n /**\n * Starts and returns a new Span representing a logical unit of work.\n *\n * This method do NOT modify the current Context by default. In result, any inner span will not\n * automatically set its parent context to the span created by this method unless manually activate\n * context via `tracer.getContext().with`. `trace`, or `wrap` is generally recommended as it gracefully\n * handles context activation. (ref: https://github.com/open-telemetry/opentelemetry-js/issues/1923)\n */\n startSpan(type: SpanTypes): Span\n startSpan(type: SpanTypes, options: TracerSpanOptions): Span\n\n /**\n * Returns currently activated span if current context is in the scope of the span.\n * Returns undefined otherwise.\n */\n getActiveScopeSpan(): Span | undefined\n\n /**\n * Returns trace propagation data for the currently active context. The format is equal to data provided\n * through the OpenTelemetry propagator API.\n */\n getTracePropagationData(): ClientTraceDataEntry[]\n}\n\ntype NextAttributeNames =\n | 'next.route'\n | 'next.page'\n | 'next.rsc'\n | 'next.segment'\n | 'next.span_name'\n | 'next.span_type'\n | 'next.clientComponentLoadCount'\ntype OTELAttributeNames = `http.${string}` | `net.${string}`\ntype AttributeNames = NextAttributeNames | OTELAttributeNames\n\n/** we use this map to propagate attributes from nested spans to the top span */\nconst rootSpanAttributesStore = new Map<\n number,\n Map<AttributeNames, AttributeValue | undefined>\n>()\nconst rootSpanIdKey = api.createContextKey('next.rootSpanId')\nlet lastSpanId = 0\nconst getSpanId = () => lastSpanId++\n\nexport interface ClientTraceDataEntry {\n key: string\n value: string\n}\n\nconst clientTraceDataSetter: TextMapSetter<ClientTraceDataEntry[]> = {\n set(carrier, key, value) {\n carrier.push({\n key,\n value,\n })\n },\n}\n\nclass NextTracerImpl implements NextTracer {\n /**\n * Returns an instance to the trace with configured name.\n * Since wrap / trace can be defined in any place prior to actual trace subscriber initialization,\n * This should be lazily evaluated.\n */\n private getTracerInstance(): Tracer {\n return trace.getTracer('next.js', '0.0.1')\n }\n\n public getContext(): ContextAPI {\n return context\n }\n\n public getTracePropagationData(): ClientTraceDataEntry[] {\n const activeContext = context.active()\n const entries: ClientTraceDataEntry[] = []\n propagation.inject(activeContext, entries, clientTraceDataSetter)\n return entries\n }\n\n public getActiveScopeSpan(): Span | undefined {\n return trace.getSpan(context?.active())\n }\n\n public withPropagatedContext<T, C>(\n carrier: C,\n fn: () => T,\n getter?: TextMapGetter<C>\n ): T {\n const activeContext = context.active()\n if (trace.getSpanContext(activeContext)) {\n // Active span is already set, too late to propagate.\n return fn()\n }\n const remoteContext = propagation.extract(activeContext, carrier, getter)\n return context.with(remoteContext, fn)\n }\n\n // Trace, wrap implementation is inspired by datadog trace implementation\n // (https://datadoghq.dev/dd-trace-js/interfaces/tracer.html#trace).\n public trace<T>(\n type: SpanTypes,\n fn: (span?: Span, done?: (error?: Error) => any) => Promise<T>\n ): Promise<T>\n public trace<T>(\n type: SpanTypes,\n fn: (span?: Span, done?: (error?: Error) => any) => T\n ): T\n public trace<T>(\n type: SpanTypes,\n options: TracerSpanOptions,\n fn: (span?: Span, done?: (error?: Error) => any) => Promise<T>\n ): Promise<T>\n public trace<T>(\n type: SpanTypes,\n options: TracerSpanOptions,\n fn: (span?: Span, done?: (error?: Error) => any) => T\n ): T\n public trace<T>(...args: Array<any>) {\n const [type, fnOrOptions, fnOrEmpty] = args\n\n // coerce options form overload\n const {\n fn,\n options,\n }: {\n fn: (span?: Span, done?: (error?: Error) => any) => T | Promise<T>\n options: TracerSpanOptions\n } =\n typeof fnOrOptions === 'function'\n ? {\n fn: fnOrOptions,\n options: {},\n }\n : {\n fn: fnOrEmpty,\n options: { ...fnOrOptions },\n }\n\n const spanName = options.spanName ?? type\n\n if (\n (!NextVanillaSpanAllowlist.has(type) &&\n process.env.NEXT_OTEL_VERBOSE !== '1') ||\n options.hideSpan\n ) {\n return fn()\n }\n\n // Trying to get active scoped span to assign parent. If option specifies parent span manually, will try to use it.\n let spanContext = this.getSpanContext(\n options?.parentSpan ?? this.getActiveScopeSpan()\n )\n let isRootSpan = false\n\n if (!spanContext) {\n spanContext = context?.active() ?? ROOT_CONTEXT\n isRootSpan = true\n } else if (trace.getSpanContext(spanContext)?.isRemote) {\n isRootSpan = true\n }\n\n const spanId = getSpanId()\n\n options.attributes = {\n 'next.span_name': spanName,\n 'next.span_type': type,\n ...options.attributes,\n }\n\n return context.with(spanContext.setValue(rootSpanIdKey, spanId), () =>\n this.getTracerInstance().startActiveSpan(\n spanName,\n options,\n (span: Span) => {\n let startTime: number | undefined\n if (\n NEXT_OTEL_PERFORMANCE_PREFIX &&\n type &&\n LogSpanAllowList.has(type)\n ) {\n startTime =\n 'performance' in globalThis && 'measure' in performance\n ? globalThis.performance.now()\n : undefined\n }\n\n let cleanedUp = false\n const onCleanup = () => {\n if (cleanedUp) return\n cleanedUp = true\n rootSpanAttributesStore.delete(spanId)\n if (startTime) {\n performance.measure(\n `${NEXT_OTEL_PERFORMANCE_PREFIX}:next-${(\n type.split('.').pop() || ''\n ).replace(\n /[A-Z]/g,\n (match: string) => '-' + match.toLowerCase()\n )}`,\n {\n start: startTime,\n end: performance.now(),\n }\n )\n }\n }\n\n if (isRootSpan) {\n rootSpanAttributesStore.set(\n spanId,\n new Map(\n Object.entries(options.attributes ?? {}) as [\n AttributeNames,\n AttributeValue | undefined,\n ][]\n )\n )\n }\n if (fn.length > 1) {\n try {\n return fn(span, (err) => closeSpanWithError(span, err))\n } catch (err: any) {\n closeSpanWithError(span, err)\n throw err\n } finally {\n onCleanup()\n }\n }\n\n try {\n const result = fn(span)\n if (isThenable(result)) {\n // If there's error make sure it throws\n return result\n .then((res) => {\n span.end()\n // Need to pass down the promise result,\n // it could be react stream response with error { error, stream }\n return res\n })\n .catch((err) => {\n closeSpanWithError(span, err)\n throw err\n })\n .finally(onCleanup)\n } else {\n span.end()\n onCleanup()\n }\n\n return result\n } catch (err: any) {\n closeSpanWithError(span, err)\n onCleanup()\n throw err\n }\n }\n )\n )\n }\n\n public wrap<T = (...args: Array<any>) => any>(type: SpanTypes, fn: T): T\n public wrap<T = (...args: Array<any>) => any>(\n type: SpanTypes,\n options: TracerSpanOptions,\n fn: T\n ): T\n public wrap<T = (...args: Array<any>) => any>(\n type: SpanTypes,\n options: (...args: any[]) => TracerSpanOptions,\n fn: T\n ): T\n public wrap(...args: Array<any>) {\n const tracer = this\n const [name, options, fn] =\n args.length === 3 ? args : [args[0], {}, args[1]]\n\n if (\n !NextVanillaSpanAllowlist.has(name) &&\n process.env.NEXT_OTEL_VERBOSE !== '1'\n ) {\n return fn\n }\n\n return function (this: any) {\n let optionsObj = options\n if (typeof optionsObj === 'function' && typeof fn === 'function') {\n optionsObj = optionsObj.apply(this, arguments)\n }\n\n const lastArgId = arguments.length - 1\n const cb = arguments[lastArgId]\n\n if (typeof cb === 'function') {\n const scopeBoundCb = tracer.getContext().bind(context.active(), cb)\n return tracer.trace(name, optionsObj, (_span, done) => {\n arguments[lastArgId] = function (err: any) {\n done?.(err)\n return scopeBoundCb.apply(this, arguments)\n }\n\n return fn.apply(this, arguments)\n })\n } else {\n return tracer.trace(name, optionsObj, () => fn.apply(this, arguments))\n }\n }\n }\n\n public startSpan(type: SpanTypes): Span\n public startSpan(type: SpanTypes, options: TracerSpanOptions): Span\n public startSpan(...args: Array<any>): Span {\n const [type, options]: [string, TracerSpanOptions | undefined] = args as any\n\n const spanContext = this.getSpanContext(\n options?.parentSpan ?? this.getActiveScopeSpan()\n )\n return this.getTracerInstance().startSpan(type, options, spanContext)\n }\n\n private getSpanContext(parentSpan?: Span) {\n const spanContext = parentSpan\n ? trace.setSpan(context.active(), parentSpan)\n : undefined\n\n return spanContext\n }\n\n public getRootSpanAttributes() {\n const spanId = context.active().getValue(rootSpanIdKey) as number\n return rootSpanAttributesStore.get(spanId)\n }\n\n public setRootSpanAttribute(key: AttributeNames, value: AttributeValue) {\n const spanId = context.active().getValue(rootSpanIdKey) as number\n const attributes = rootSpanAttributesStore.get(spanId)\n if (attributes && !attributes.has(key)) {\n attributes.set(key, value)\n }\n }\n}\n\nconst getTracer = (() => {\n const tracer = new NextTracerImpl()\n\n return () => tracer\n})()\n\nexport { getTracer, SpanStatusCode, SpanKind }\nexport type { NextTracer, Span, SpanOptions, ContextAPI, TracerSpanOptions }\n"],"names":["LogSpanAllowList","NextVanillaSpanAllowlist","isThenable","NEXT_OTEL_PERFORMANCE_PREFIX","process","env","api","NEXT_RUNTIME","require","err","context","propagation","trace","SpanStatusCode","SpanKind","ROOT_CONTEXT","BubbledError","Error","constructor","bubble","result","isBubbledError","error","closeSpanWithError","span","setAttribute","recordException","name","setStatus","code","ERROR","message","end","rootSpanAttributesStore","Map","rootSpanIdKey","createContextKey","lastSpanId","getSpanId","clientTraceDataSetter","set","carrier","key","value","push","NextTracerImpl","getTracerInstance","getTracer","getContext","getTracePropagationData","activeContext","active","entries","inject","getActiveScopeSpan","getSpan","withPropagatedContext","fn","getter","getSpanContext","remoteContext","extract","with","args","type","fnOrOptions","fnOrEmpty","options","spanName","has","NEXT_OTEL_VERBOSE","hideSpan","spanContext","parentSpan","isRootSpan","isRemote","spanId","attributes","setValue","startActiveSpan","startTime","globalThis","performance","now","undefined","cleanedUp","onCleanup","delete","measure","split","pop","replace","match","toLowerCase","start","Object","length","then","res","catch","finally","wrap","tracer","optionsObj","apply","arguments","lastArgId","cb","scopeBoundCb","bind","_span","done","startSpan","setSpan","getRootSpanAttributes","getValue","get","setRootSpanAttribute"],"mappings":"AAGA,SAASA,gBAAgB,EAAEC,wBAAwB,QAAQ,cAAa;AAUxE,SA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CAAA;IACjB,MAAMuD,SAAS,IAAIzD;IAEnB,OAAO,IAAMyD;AACf,CAAA;AAEA,SAASvD,SAAS,EAAElC,cAAc,EAAEC,QAAQ,GAAE","ignoreList":[0]}
1
+ {"version":3,"sources":["../../../../../src/server/lib/trace/tracer.ts"],"sourcesContent":["import type { FetchEventResult } from '../../web/types'\nimport type { TextMapSetter } from '@opentelemetry/api'\nimport type { SpanTypes } from './constants'\nimport { LogSpanAllowList, NextVanillaSpanAllowlist } from './constants'\n\nimport type {\n ContextAPI,\n Span,\n SpanOptions,\n Tracer,\n AttributeValue,\n TextMapGetter,\n} from 'next/dist/compiled/@opentelemetry/api'\nimport { isThenable } from '../../../shared/lib/is-thenable'\n\nconst NEXT_OTEL_PERFORMANCE_PREFIX = process.env.NEXT_OTEL_PERFORMANCE_PREFIX\n\nlet api: typeof import('next/dist/compiled/@opentelemetry/api')\n\n// we want to allow users to use their own version of @opentelemetry/api if they\n// want to, so we try to require it first, and if it fails we fall back to the\n// version that is bundled with Next.js\n// this is because @opentelemetry/api has to be synced with the version of\n// @opentelemetry/tracing that is used, and we don't want to force users to use\n// the version that is bundled with Next.js.\n// the API is ~stable, so this should be fine\nif (process.env.NEXT_RUNTIME === 'edge') {\n api = require('@opentelemetry/api') as typeof import('@opentelemetry/api')\n} else {\n try {\n api = require('@opentelemetry/api') as typeof import('@opentelemetry/api')\n } catch (err) {\n api =\n require('next/dist/compiled/@opentelemetry/api') as typeof import('next/dist/compiled/@opentelemetry/api')\n }\n}\n\nconst { context, propagation, trace, SpanStatusCode, SpanKind, ROOT_CONTEXT } =\n api\n\nexport class BubbledError extends Error {\n constructor(\n public readonly bubble?: boolean,\n public readonly result?: FetchEventResult\n ) {\n super()\n }\n}\n\nexport function isBubbledError(error: unknown): error is BubbledError {\n if (typeof error !== 'object' || error === null) return false\n return error instanceof BubbledError\n}\n\nconst closeSpanWithError = (span: Span, error?: Error) => {\n if (isBubbledError(error) && error.bubble) {\n span.setAttribute('next.bubble', true)\n } else {\n if (error) {\n span.recordException(error)\n span.setAttribute('error.type', error.name)\n }\n span.setStatus({ code: SpanStatusCode.ERROR, message: error?.message })\n }\n span.end()\n}\n\ntype TracerSpanOptions = Omit<SpanOptions, 'attributes'> & {\n parentSpan?: Span\n spanName?: string\n attributes?: Partial<Record<AttributeNames, AttributeValue | undefined>>\n hideSpan?: boolean\n}\n\ninterface NextTracer {\n getContext(): ContextAPI\n\n /**\n * Instruments a function by automatically creating a span activated on its\n * scope.\n *\n * The span will automatically be finished when one of these conditions is\n * met:\n *\n * * The function returns a promise, in which case the span will finish when\n * the promise is resolved or rejected.\n * * The function takes a callback as its second parameter, in which case the\n * span will finish when that callback is called.\n * * The function doesn't accept a callback and doesn't return a promise, in\n * which case the span will finish at the end of the function execution.\n *\n */\n trace<T>(\n type: SpanTypes,\n fn: (span?: Span, done?: (error?: Error) => any) => Promise<T>\n ): Promise<T>\n trace<T>(\n type: SpanTypes,\n fn: (span?: Span, done?: (error?: Error) => any) => T\n ): T\n trace<T>(\n type: SpanTypes,\n options: TracerSpanOptions,\n fn: (span?: Span, done?: (error?: Error) => any) => Promise<T>\n ): Promise<T>\n trace<T>(\n type: SpanTypes,\n options: TracerSpanOptions,\n fn: (span?: Span, done?: (error?: Error) => any) => T\n ): T\n\n /**\n * Wrap a function to automatically create a span activated on its\n * scope when it's called.\n *\n * The span will automatically be finished when one of these conditions is\n * met:\n *\n * * The function returns a promise, in which case the span will finish when\n * the promise is resolved or rejected.\n * * The function takes a callback as its last parameter, in which case the\n * span will finish when that callback is called.\n * * The function doesn't accept a callback and doesn't return a promise, in\n * which case the span will finish at the end of the function execution.\n */\n wrap<T = (...args: Array<any>) => any>(type: SpanTypes, fn: T): T\n wrap<T = (...args: Array<any>) => any>(\n type: SpanTypes,\n options: TracerSpanOptions,\n fn: T\n ): T\n wrap<T = (...args: Array<any>) => any>(\n type: SpanTypes,\n options: (...args: any[]) => TracerSpanOptions,\n fn: T\n ): T\n\n /**\n * Starts and returns a new Span representing a logical unit of work.\n *\n * This method do NOT modify the current Context by default. In result, any inner span will not\n * automatically set its parent context to the span created by this method unless manually activate\n * context via `tracer.getContext().with`. `trace`, or `wrap` is generally recommended as it gracefully\n * handles context activation. (ref: https://github.com/open-telemetry/opentelemetry-js/issues/1923)\n */\n startSpan(type: SpanTypes): Span\n startSpan(type: SpanTypes, options: TracerSpanOptions): Span\n\n /**\n * Returns currently activated span if current context is in the scope of the span.\n * Returns undefined otherwise.\n */\n getActiveScopeSpan(): Span | undefined\n\n /**\n * Returns trace propagation data for the currently active context. The format is equal to data provided\n * through the OpenTelemetry propagator API.\n */\n getTracePropagationData(): ClientTraceDataEntry[]\n}\n\ntype NextAttributeNames =\n | 'next.route'\n | 'next.page'\n | 'next.rsc'\n | 'next.segment'\n | 'next.span_name'\n | 'next.span_type'\n | 'next.clientComponentLoadCount'\ntype OTELAttributeNames = `http.${string}` | `net.${string}`\ntype AttributeNames = NextAttributeNames | OTELAttributeNames\n\n/** we use this map to propagate attributes from nested spans to the top span */\nconst rootSpanAttributesStore = new Map<\n number,\n Map<AttributeNames, AttributeValue | undefined>\n>()\nconst rootSpanIdKey = api.createContextKey('next.rootSpanId')\nlet lastSpanId = 0\nconst getSpanId = () => lastSpanId++\n\nexport interface ClientTraceDataEntry {\n key: string\n value: string\n}\n\nconst clientTraceDataSetter: TextMapSetter<ClientTraceDataEntry[]> = {\n set(carrier, key, value) {\n carrier.push({\n key,\n value,\n })\n },\n}\n\nclass NextTracerImpl implements NextTracer {\n /**\n * Returns an instance to the trace with configured name.\n * Since wrap / trace can be defined in any place prior to actual trace subscriber initialization,\n * This should be lazily evaluated.\n */\n private getTracerInstance(): Tracer {\n return trace.getTracer('next.js', '0.0.1')\n }\n\n public getContext(): ContextAPI {\n return context\n }\n\n public getTracePropagationData(): ClientTraceDataEntry[] {\n const activeContext = context.active()\n const entries: ClientTraceDataEntry[] = []\n propagation.inject(activeContext, entries, clientTraceDataSetter)\n return entries\n }\n\n public getActiveScopeSpan(): Span | undefined {\n return trace.getSpan(context?.active())\n }\n\n public withPropagatedContext<T, C>(\n carrier: C,\n fn: () => T,\n getter?: TextMapGetter<C>\n ): T {\n const activeContext = context.active()\n if (trace.getSpanContext(activeContext)) {\n // Active span is already set, too late to propagate.\n return fn()\n }\n const remoteContext = propagation.extract(activeContext, carrier, getter)\n return context.with(remoteContext, fn)\n }\n\n // Trace, wrap implementation is inspired by datadog trace implementation\n // (https://datadoghq.dev/dd-trace-js/interfaces/tracer.html#trace).\n public trace<T>(\n type: SpanTypes,\n fn: (span?: Span, done?: (error?: Error) => any) => Promise<T>\n ): Promise<T>\n public trace<T>(\n type: SpanTypes,\n fn: (span?: Span, done?: (error?: Error) => any) => T\n ): T\n public trace<T>(\n type: SpanTypes,\n options: TracerSpanOptions,\n fn: (span?: Span, done?: (error?: Error) => any) => Promise<T>\n ): Promise<T>\n public trace<T>(\n type: SpanTypes,\n options: TracerSpanOptions,\n fn: (span?: Span, done?: (error?: Error) => any) => T\n ): T\n public trace<T>(...args: Array<any>) {\n const [type, fnOrOptions, fnOrEmpty] = args\n\n // coerce options form overload\n const {\n fn,\n options,\n }: {\n fn: (span?: Span, done?: (error?: Error) => any) => T | Promise<T>\n options: TracerSpanOptions\n } =\n typeof fnOrOptions === 'function'\n ? {\n fn: fnOrOptions,\n options: {},\n }\n : {\n fn: fnOrEmpty,\n options: { ...fnOrOptions },\n }\n\n const spanName = options.spanName ?? type\n\n if (\n (!NextVanillaSpanAllowlist.has(type) &&\n process.env.NEXT_OTEL_VERBOSE !== '1') ||\n options.hideSpan\n ) {\n return fn()\n }\n\n // Trying to get active scoped span to assign parent. If option specifies parent span manually, will try to use it.\n let spanContext = this.getSpanContext(\n options?.parentSpan ?? this.getActiveScopeSpan()\n )\n\n if (!spanContext) {\n spanContext = context?.active() ?? ROOT_CONTEXT\n }\n // Check if there's already a root span in the store for this trace\n // We are intentionally not checking whether there is an active context\n // from outside of nextjs to ensure that we can provide the same level\n // of telemetry when using a custom server\n const existingRootSpanId = spanContext.getValue(rootSpanIdKey)\n const isRootSpan =\n typeof existingRootSpanId !== 'number' ||\n !rootSpanAttributesStore.has(existingRootSpanId)\n\n const spanId = getSpanId()\n\n options.attributes = {\n 'next.span_name': spanName,\n 'next.span_type': type,\n ...options.attributes,\n }\n\n return context.with(spanContext.setValue(rootSpanIdKey, spanId), () =>\n this.getTracerInstance().startActiveSpan(\n spanName,\n options,\n (span: Span) => {\n let startTime: number | undefined\n if (\n NEXT_OTEL_PERFORMANCE_PREFIX &&\n type &&\n LogSpanAllowList.has(type)\n ) {\n startTime =\n 'performance' in globalThis && 'measure' in performance\n ? globalThis.performance.now()\n : undefined\n }\n\n let cleanedUp = false\n const onCleanup = () => {\n if (cleanedUp) return\n cleanedUp = true\n rootSpanAttributesStore.delete(spanId)\n if (startTime) {\n performance.measure(\n `${NEXT_OTEL_PERFORMANCE_PREFIX}:next-${(\n type.split('.').pop() || ''\n ).replace(\n /[A-Z]/g,\n (match: string) => '-' + match.toLowerCase()\n )}`,\n {\n start: startTime,\n end: performance.now(),\n }\n )\n }\n }\n\n if (isRootSpan) {\n rootSpanAttributesStore.set(\n spanId,\n new Map(\n Object.entries(options.attributes ?? {}) as [\n AttributeNames,\n AttributeValue | undefined,\n ][]\n )\n )\n }\n if (fn.length > 1) {\n try {\n return fn(span, (err) => closeSpanWithError(span, err))\n } catch (err: any) {\n closeSpanWithError(span, err)\n throw err\n } finally {\n onCleanup()\n }\n }\n\n try {\n const result = fn(span)\n if (isThenable(result)) {\n // If there's error make sure it throws\n return result\n .then((res) => {\n span.end()\n // Need to pass down the promise result,\n // it could be react stream response with error { error, stream }\n return res\n })\n .catch((err) => {\n closeSpanWithError(span, err)\n throw err\n })\n .finally(onCleanup)\n } else {\n span.end()\n onCleanup()\n }\n\n return result\n } catch (err: any) {\n closeSpanWithError(span, err)\n onCleanup()\n throw err\n }\n }\n )\n )\n }\n\n public wrap<T = (...args: Array<any>) => any>(type: SpanTypes, fn: T): T\n public wrap<T = (...args: Array<any>) => any>(\n type: SpanTypes,\n options: TracerSpanOptions,\n fn: T\n ): T\n public wrap<T = (...args: Array<any>) => any>(\n type: SpanTypes,\n options: (...args: any[]) => TracerSpanOptions,\n fn: T\n ): T\n public wrap(...args: Array<any>) {\n const tracer = this\n const [name, options, fn] =\n args.length === 3 ? args : [args[0], {}, args[1]]\n\n if (\n !NextVanillaSpanAllowlist.has(name) &&\n process.env.NEXT_OTEL_VERBOSE !== '1'\n ) {\n return fn\n }\n\n return function (this: any) {\n let optionsObj = options\n if (typeof optionsObj === 'function' && typeof fn === 'function') {\n optionsObj = optionsObj.apply(this, arguments)\n }\n\n const lastArgId = arguments.length - 1\n const cb = arguments[lastArgId]\n\n if (typeof cb === 'function') {\n const scopeBoundCb = tracer.getContext().bind(context.active(), cb)\n return tracer.trace(name, optionsObj, (_span, done) => {\n arguments[lastArgId] = function (err: any) {\n done?.(err)\n return scopeBoundCb.apply(this, arguments)\n }\n\n return fn.apply(this, arguments)\n })\n } else {\n return tracer.trace(name, optionsObj, () => fn.apply(this, arguments))\n }\n }\n }\n\n public startSpan(type: SpanTypes): Span\n public startSpan(type: SpanTypes, options: TracerSpanOptions): Span\n public startSpan(...args: Array<any>): Span {\n const [type, options]: [string, TracerSpanOptions | undefined] = args as any\n\n const spanContext = this.getSpanContext(\n options?.parentSpan ?? this.getActiveScopeSpan()\n )\n return this.getTracerInstance().startSpan(type, options, spanContext)\n }\n\n private getSpanContext(parentSpan?: Span) {\n const spanContext = parentSpan\n ? trace.setSpan(context.active(), parentSpan)\n : undefined\n\n return spanContext\n }\n\n public getRootSpanAttributes() {\n const spanId = context.active().getValue(rootSpanIdKey) as number\n return rootSpanAttributesStore.get(spanId)\n }\n\n public setRootSpanAttribute(key: AttributeNames, value: AttributeValue) {\n const spanId = context.active().getValue(rootSpanIdKey) as number\n const attributes = rootSpanAttributesStore.get(spanId)\n if (attributes && !attributes.has(key)) {\n attributes.set(key, value)\n }\n }\n}\n\nconst getTracer = (() => {\n const tracer = new NextTracerImpl()\n\n return () => tracer\n})()\n\nexport { getTracer, SpanStatusCode, SpanKind }\nexport type { NextTracer, Span, SpanOptions, ContextAPI, TracerSpanOptions }\n"],"names":["LogSpanAllowList","NextVanillaSpanAllowlist","isThenable","NEXT_OTEL_PERFORMANCE_PREFIX","process","env","api","NEXT_RUNTIME","require","err","context","propagation","trace","SpanStatusCode","SpanKind","ROOT_CONTEXT","BubbledError","Error","constructor","bubble","result","isBubbledError","error","closeSpanWithError","span","setAttribute","recordException","name","setStatus","code","ERROR","message","end","rootSpanAttributesStore","Map","rootSpanIdKey","createContextKey","lastSpanId","getSpanId","clientTraceDataSetter","set","carrier","key","value","push","NextTracerImpl","getTracerInstance","getTracer","getContext","getTracePropagationData","activeContext","active","entries","inject","getActiveScopeSpan","getSpan","withPropagatedContext","fn","getter","getSpanContext","remoteContext","extract","with","args","type","fnOrOptions","fnOrEmpty","options","spanName","has","NEXT_OTEL_VERBOSE","hideSpan","spanContext","parentSpan","existingRootSpanId","getValue","isRootSpan","spanId","attributes","setValue","startActiveSpan","startTime","globalThis","performance","now","undefined","cleanedUp","onCleanup","delete","measure","split","pop","replace","match","toLowerCase","start","Object","length","then","res","catch","finally","wrap","tracer","optionsObj","apply","arguments","lastArgId","cb","scopeBoundCb","bind","_span","done","startSpan","setSpan","getRootSpanAttributes","get","setRootSpanAttribute"],"mappings":"AAGA,SAASA,gBAAgB,EAAEC,wBAAwB,QAAQ,cAAa;AAUxE,SAASC,UAAU,QAAQ,kCAAiC;AAE5D,MAAMC,+BAA+BC,QAAQC,GAAG,CAACF,4BAA4B;AAE7E,IAAIG;AAEJ,gFAAgF;AAChF,8EAA8E;AAC9E,uCAAuC;AACvC,0EAA0E;AAC1E,+EAA+E;AAC/E,4CAA4C;AAC5C,6CAA6C;AAC7C,IAAIF,QAAQC,GAAG,CAACE,YAAY,KAAK,QAAQ;IACvCD,MAAME,QAAQ;AAChB,OAAO;IACL,IAAI;QACFF,MAAME,QAAQ;IAChB,EA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GAAGgD,KAAK,CAAC,IAAI,EAAEC;gBACxB;YACF,OAAO;gBACL,OAAOH,OAAO3F,KAAK,CAACe,MAAM6E,YAAY,IAAM/C,GAAGgD,KAAK,CAAC,IAAI,EAAEC;YAC7D;QACF;IACF;IAIOO,UAAU,GAAGlD,IAAgB,EAAQ;QAC1C,MAAM,CAACC,MAAMG,QAAQ,GAA4CJ;QAEjE,MAAMS,cAAc,IAAI,CAACb,cAAc,CACrCQ,CAAAA,2BAAAA,QAASM,UAAU,KAAI,IAAI,CAACnB,kBAAkB;QAEhD,OAAO,IAAI,CAACR,iBAAiB,GAAGmE,SAAS,CAACjD,MAAMG,SAASK;IAC3D;IAEQb,eAAec,UAAiB,EAAE;QACxC,MAAMD,cAAcC,aAChB7D,MAAMsG,OAAO,CAACxG,QAAQyC,MAAM,IAAIsB,cAChCY;QAEJ,OAAOb;IACT;IAEO2C,wBAAwB;QAC7B,MAAMtC,SAASnE,QAAQyC,MAAM,GAAGwB,QAAQ,CAACxC;QACzC,OAAOF,wBAAwBmF,GAAG,CAACvC;IACrC;IAEOwC,qBAAqB3E,GAAmB,EAAEC,KAAqB,EAAE;QACtE,MAAMkC,SAASnE,QAAQyC,MAAM,GAAGwB,QAAQ,CAACxC;QACzC,MAAM2C,aAAa7C,wBAAwBmF,GAAG,CAACvC;QAC/C,IAAIC,cAAc,CAACA,WAAWT,GAAG,CAAC3B,MAAM;YACtCoC,WAAWtC,GAAG,CAACE,KAAKC;QACtB;IACF;AACF;AAEA,MAAMI,YAAY,AAAC,CAAA;IACjB,MAAMwD,SAAS,IAAI1D;IAEnB,OAAO,IAAM0D;AACf,CAAA;AAEA,SAASxD,SAAS,EAAElC,cAAc,EAAEC,QAAQ,GAAE","ignoreList":[0]}
@@ -1,5 +1,5 @@
1
1
  export function isStableBuild() {
2
- return !"16.0.2-canary.10"?.includes('canary') && !process.env.__NEXT_TEST_MODE && !process.env.NEXT_PRIVATE_LOCAL_DEV;
2
+ return !"16.0.2-canary.11"?.includes('canary') && !process.env.__NEXT_TEST_MODE && !process.env.NEXT_PRIVATE_LOCAL_DEV;
3
3
  }
4
4
  export class CanaryOnlyConfigError extends Error {
5
5
  constructor(arg){
@@ -152,7 +152,7 @@ async function createHotReloaderTurbopack(opts, serverFields, distDir, resetFetc
152
152
  }
153
153
  const hasRewrites = opts.fsChecker.rewrites.afterFiles.length > 0 || opts.fsChecker.rewrites.beforeFiles.length > 0 || opts.fsChecker.rewrites.fallback.length > 0;
154
154
  const hotReloaderSpan = (0, _trace.trace)('hot-reloader', undefined, {
155
- version: "16.0.2-canary.10"
155
+ version: "16.0.2-canary.11"
156
156
  });
157
157
  // Ensure the hotReloaderSpan is flushed immediately as it's the parentSpan for all processing
158
158
  // of the current `next dev` invocation.
@@ -231,7 +231,7 @@ class HotReloaderWebpack {
231
231
  this.previewProps = previewProps;
232
232
  this.rewrites = rewrites;
233
233
  this.hotReloaderSpan = (0, _trace.trace)('hot-reloader', undefined, {
234
- version: "16.0.2-canary.10"
234
+ version: "16.0.2-canary.11"
235
235
  });
236
236
  // Ensure the hotReloaderSpan is flushed immediately as it's the parentSpan for all processing
237
237
  // of the current `next dev` invocation.
@@ -91,7 +91,7 @@ function logStartInfo({ networkUrl, appUrl, envInfo, experimentalFeatures, logBu
91
91
  if (parts.length > 0) {
92
92
  versionSuffix = ` (${parts.join(', ')})`;
93
93
  }
94
- _log.bootstrap(`${(0, _picocolors.bold)((0, _picocolors.purple)(`${_log.prefixes.ready} Next.js ${"16.0.2-canary.10"}`))}${versionSuffix}`);
94
+ _log.bootstrap(`${(0, _picocolors.bold)((0, _picocolors.purple)(`${_log.prefixes.ready} Next.js ${"16.0.2-canary.11"}`))}${versionSuffix}`);
95
95
  if (appUrl) {
96
96
  _log.bootstrap(`- Local: ${appUrl}`);
97
97
  }
@@ -179,7 +179,7 @@ async function getRequestHandlers({ dir, port, isDev, onDevServerCleanup, server
179
179
  async function startServer(serverOptions) {
180
180
  const { dir, isDev, hostname, minimalMode, allowRetry, keepAliveTimeout, selfSignedCertificate } = serverOptions;
181
181
  let { port } = serverOptions;
182
- process.title = `next-server (v${"16.0.2-canary.10"})`;
182
+ process.title = `next-server (v${"16.0.2-canary.11"})`;
183
183
  let handlersReady = ()=>{};
184
184
  let handlersError = ()=>{};
185
185
  let handlersPromise = new Promise((resolve, reject)=>{
@@ -119,7 +119,6 @@ class NextTracerImpl {
119
119
  return context.with(remoteContext, fn);
120
120
  }
121
121
  trace(...args) {
122
- var _trace_getSpanContext;
123
122
  const [type, fnOrOptions, fnOrEmpty] = args;
124
123
  // coerce options form overload
125
124
  const { fn, options } = typeof fnOrOptions === 'function' ? {
@@ -137,13 +136,15 @@ class NextTracerImpl {
137
136
  }
138
137
  // Trying to get active scoped span to assign parent. If option specifies parent span manually, will try to use it.
139
138
  let spanContext = this.getSpanContext((options == null ? void 0 : options.parentSpan) ?? this.getActiveScopeSpan());
140
- let isRootSpan = false;
141
139
  if (!spanContext) {
142
140
  spanContext = (context == null ? void 0 : context.active()) ?? ROOT_CONTEXT;
143
- isRootSpan = true;
144
- } else if ((_trace_getSpanContext = trace.getSpanContext(spanContext)) == null ? void 0 : _trace_getSpanContext.isRemote) {
145
- isRootSpan = true;
146
141
  }
142
+ // Check if there's already a root span in the store for this trace
143
+ // We are intentionally not checking whether there is an active context
144
+ // from outside of nextjs to ensure that we can provide the same level
145
+ // of telemetry when using a custom server
146
+ const existingRootSpanId = spanContext.getValue(rootSpanIdKey);
147
+ const isRootSpan = typeof existingRootSpanId !== 'number' || !rootSpanAttributesStore.has(existingRootSpanId);
147
148
  const spanId = getSpanId();
148
149
  options.attributes = {
149
150
  'next.span_name': spanName,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/server/lib/trace/tracer.ts"],"sourcesContent":["import type { FetchEventResult } from '../../web/types'\nimport type { TextMapSetter } from '@opentelemetry/api'\nimport type { SpanTypes } from './constants'\nimport { LogSpanAllowList, NextVanillaSpanAllowlist } from './constants'\n\nimport type {\n ContextAPI,\n Span,\n SpanOptions,\n Tracer,\n AttributeValue,\n TextMapGetter,\n} from 'next/dist/compiled/@opentelemetry/api'\nimport { isThenable } from '../../../shared/lib/is-thenable'\n\nconst NEXT_OTEL_PERFORMANCE_PREFIX = process.env.NEXT_OTEL_PERFORMANCE_PREFIX\n\nlet api: typeof import('next/dist/compiled/@opentelemetry/api')\n\n// we want to allow users to use their own version of @opentelemetry/api if they\n// want to, so we try to require it first, and if it fails we fall back to the\n// version that is bundled with Next.js\n// this is because @opentelemetry/api has to be synced with the version of\n// @opentelemetry/tracing that is used, and we don't want to force users to use\n// the version that is bundled with Next.js.\n// the API is ~stable, so this should be fine\nif (process.env.NEXT_RUNTIME === 'edge') {\n api = require('@opentelemetry/api') as typeof import('@opentelemetry/api')\n} else {\n try {\n api = require('@opentelemetry/api') as typeof import('@opentelemetry/api')\n } catch (err) {\n api =\n require('next/dist/compiled/@opentelemetry/api') as typeof import('next/dist/compiled/@opentelemetry/api')\n }\n}\n\nconst { context, propagation, trace, SpanStatusCode, SpanKind, ROOT_CONTEXT } =\n api\n\nexport class BubbledError extends Error {\n constructor(\n public readonly bubble?: boolean,\n public readonly result?: FetchEventResult\n ) {\n super()\n }\n}\n\nexport function isBubbledError(error: unknown): error is BubbledError {\n if (typeof error !== 'object' || error === null) return false\n return error instanceof BubbledError\n}\n\nconst closeSpanWithError = (span: Span, error?: Error) => {\n if (isBubbledError(error) && error.bubble) {\n span.setAttribute('next.bubble', true)\n } else {\n if (error) {\n span.recordException(error)\n span.setAttribute('error.type', error.name)\n }\n span.setStatus({ code: SpanStatusCode.ERROR, message: error?.message })\n }\n span.end()\n}\n\ntype TracerSpanOptions = Omit<SpanOptions, 'attributes'> & {\n parentSpan?: Span\n spanName?: string\n attributes?: Partial<Record<AttributeNames, AttributeValue | undefined>>\n hideSpan?: boolean\n}\n\ninterface NextTracer {\n getContext(): ContextAPI\n\n /**\n * Instruments a function by automatically creating a span activated on its\n * scope.\n *\n * The span will automatically be finished when one of these conditions is\n * met:\n *\n * * The function returns a promise, in which case the span will finish when\n * the promise is resolved or rejected.\n * * The function takes a callback as its second parameter, in which case the\n * span will finish when that callback is called.\n * * The function doesn't accept a callback and doesn't return a promise, in\n * which case the span will finish at the end of the function execution.\n *\n */\n trace<T>(\n type: SpanTypes,\n fn: (span?: Span, done?: (error?: Error) => any) => Promise<T>\n ): Promise<T>\n trace<T>(\n type: SpanTypes,\n fn: (span?: Span, done?: (error?: Error) => any) => T\n ): T\n trace<T>(\n type: SpanTypes,\n options: TracerSpanOptions,\n fn: (span?: Span, done?: (error?: Error) => any) => Promise<T>\n ): Promise<T>\n trace<T>(\n type: SpanTypes,\n options: TracerSpanOptions,\n fn: (span?: Span, done?: (error?: Error) => any) => T\n ): T\n\n /**\n * Wrap a function to automatically create a span activated on its\n * scope when it's called.\n *\n * The span will automatically be finished when one of these conditions is\n * met:\n *\n * * The function returns a promise, in which case the span will finish when\n * the promise is resolved or rejected.\n * * The function takes a callback as its last parameter, in which case the\n * span will finish when that callback is called.\n * * The function doesn't accept a callback and doesn't return a promise, in\n * which case the span will finish at the end of the function execution.\n */\n wrap<T = (...args: Array<any>) => any>(type: SpanTypes, fn: T): T\n wrap<T = (...args: Array<any>) => any>(\n type: SpanTypes,\n options: TracerSpanOptions,\n fn: T\n ): T\n wrap<T = (...args: Array<any>) => any>(\n type: SpanTypes,\n options: (...args: any[]) => TracerSpanOptions,\n fn: T\n ): T\n\n /**\n * Starts and returns a new Span representing a logical unit of work.\n *\n * This method do NOT modify the current Context by default. In result, any inner span will not\n * automatically set its parent context to the span created by this method unless manually activate\n * context via `tracer.getContext().with`. `trace`, or `wrap` is generally recommended as it gracefully\n * handles context activation. (ref: https://github.com/open-telemetry/opentelemetry-js/issues/1923)\n */\n startSpan(type: SpanTypes): Span\n startSpan(type: SpanTypes, options: TracerSpanOptions): Span\n\n /**\n * Returns currently activated span if current context is in the scope of the span.\n * Returns undefined otherwise.\n */\n getActiveScopeSpan(): Span | undefined\n\n /**\n * Returns trace propagation data for the currently active context. The format is equal to data provided\n * through the OpenTelemetry propagator API.\n */\n getTracePropagationData(): ClientTraceDataEntry[]\n}\n\ntype NextAttributeNames =\n | 'next.route'\n | 'next.page'\n | 'next.rsc'\n | 'next.segment'\n | 'next.span_name'\n | 'next.span_type'\n | 'next.clientComponentLoadCount'\ntype OTELAttributeNames = `http.${string}` | `net.${string}`\ntype AttributeNames = NextAttributeNames | OTELAttributeNames\n\n/** we use this map to propagate attributes from nested spans to the top span */\nconst rootSpanAttributesStore = new Map<\n number,\n Map<AttributeNames, AttributeValue | undefined>\n>()\nconst rootSpanIdKey = api.createContextKey('next.rootSpanId')\nlet lastSpanId = 0\nconst getSpanId = () => lastSpanId++\n\nexport interface ClientTraceDataEntry {\n key: string\n value: string\n}\n\nconst clientTraceDataSetter: TextMapSetter<ClientTraceDataEntry[]> = {\n set(carrier, key, value) {\n carrier.push({\n key,\n value,\n })\n },\n}\n\nclass NextTracerImpl implements NextTracer {\n /**\n * Returns an instance to the trace with configured name.\n * Since wrap / trace can be defined in any place prior to actual trace subscriber initialization,\n * This should be lazily evaluated.\n */\n private getTracerInstance(): Tracer {\n return trace.getTracer('next.js', '0.0.1')\n }\n\n public getContext(): ContextAPI {\n return context\n }\n\n public getTracePropagationData(): ClientTraceDataEntry[] {\n const activeContext = context.active()\n const entries: ClientTraceDataEntry[] = []\n propagation.inject(activeContext, entries, clientTraceDataSetter)\n return entries\n }\n\n public getActiveScopeSpan(): Span | undefined {\n return trace.getSpan(context?.active())\n }\n\n public withPropagatedContext<T, C>(\n carrier: C,\n fn: () => T,\n getter?: TextMapGetter<C>\n ): T {\n const activeContext = context.active()\n if (trace.getSpanContext(activeContext)) {\n // Active span is already set, too late to propagate.\n return fn()\n }\n const remoteContext = propagation.extract(activeContext, carrier, getter)\n return context.with(remoteContext, fn)\n }\n\n // Trace, wrap implementation is inspired by datadog trace implementation\n // (https://datadoghq.dev/dd-trace-js/interfaces/tracer.html#trace).\n public trace<T>(\n type: SpanTypes,\n fn: (span?: Span, done?: (error?: Error) => any) => Promise<T>\n ): Promise<T>\n public trace<T>(\n type: SpanTypes,\n fn: (span?: Span, done?: (error?: Error) => any) => T\n ): T\n public trace<T>(\n type: SpanTypes,\n options: TracerSpanOptions,\n fn: (span?: Span, done?: (error?: Error) => any) => Promise<T>\n ): Promise<T>\n public trace<T>(\n type: SpanTypes,\n options: TracerSpanOptions,\n fn: (span?: Span, done?: (error?: Error) => any) => T\n ): T\n public trace<T>(...args: Array<any>) {\n const [type, fnOrOptions, fnOrEmpty] = args\n\n // coerce options form overload\n const {\n fn,\n options,\n }: {\n fn: (span?: Span, done?: (error?: Error) => any) => T | Promise<T>\n options: TracerSpanOptions\n } =\n typeof fnOrOptions === 'function'\n ? {\n fn: fnOrOptions,\n options: {},\n }\n : {\n fn: fnOrEmpty,\n options: { ...fnOrOptions },\n }\n\n const spanName = options.spanName ?? type\n\n if (\n (!NextVanillaSpanAllowlist.has(type) &&\n process.env.NEXT_OTEL_VERBOSE !== '1') ||\n options.hideSpan\n ) {\n return fn()\n }\n\n // Trying to get active scoped span to assign parent. If option specifies parent span manually, will try to use it.\n let spanContext = this.getSpanContext(\n options?.parentSpan ?? this.getActiveScopeSpan()\n )\n let isRootSpan = false\n\n if (!spanContext) {\n spanContext = context?.active() ?? ROOT_CONTEXT\n isRootSpan = true\n } else if (trace.getSpanContext(spanContext)?.isRemote) {\n isRootSpan = true\n }\n\n const spanId = getSpanId()\n\n options.attributes = {\n 'next.span_name': spanName,\n 'next.span_type': type,\n ...options.attributes,\n }\n\n return context.with(spanContext.setValue(rootSpanIdKey, spanId), () =>\n this.getTracerInstance().startActiveSpan(\n spanName,\n options,\n (span: Span) => {\n let startTime: number | undefined\n if (\n NEXT_OTEL_PERFORMANCE_PREFIX &&\n type &&\n LogSpanAllowList.has(type)\n ) {\n startTime =\n 'performance' in globalThis && 'measure' in performance\n ? globalThis.performance.now()\n : undefined\n }\n\n let cleanedUp = false\n const onCleanup = () => {\n if (cleanedUp) return\n cleanedUp = true\n rootSpanAttributesStore.delete(spanId)\n if (startTime) {\n performance.measure(\n `${NEXT_OTEL_PERFORMANCE_PREFIX}:next-${(\n type.split('.').pop() || ''\n ).replace(\n /[A-Z]/g,\n (match: string) => '-' + match.toLowerCase()\n )}`,\n {\n start: startTime,\n end: performance.now(),\n }\n )\n }\n }\n\n if (isRootSpan) {\n rootSpanAttributesStore.set(\n spanId,\n new Map(\n Object.entries(options.attributes ?? {}) as [\n AttributeNames,\n AttributeValue | undefined,\n ][]\n )\n )\n }\n if (fn.length > 1) {\n try {\n return fn(span, (err) => closeSpanWithError(span, err))\n } catch (err: any) {\n closeSpanWithError(span, err)\n throw err\n } finally {\n onCleanup()\n }\n }\n\n try {\n const result = fn(span)\n if (isThenable(result)) {\n // If there's error make sure it throws\n return result\n .then((res) => {\n span.end()\n // Need to pass down the promise result,\n // it could be react stream response with error { error, stream }\n return res\n })\n .catch((err) => {\n closeSpanWithError(span, err)\n throw err\n })\n .finally(onCleanup)\n } else {\n span.end()\n onCleanup()\n }\n\n return result\n } catch (err: any) {\n closeSpanWithError(span, err)\n onCleanup()\n throw err\n }\n }\n )\n )\n }\n\n public wrap<T = (...args: Array<any>) => any>(type: SpanTypes, fn: T): T\n public wrap<T = (...args: Array<any>) => any>(\n type: SpanTypes,\n options: TracerSpanOptions,\n fn: T\n ): T\n public wrap<T = (...args: Array<any>) => any>(\n type: SpanTypes,\n options: (...args: any[]) => TracerSpanOptions,\n fn: T\n ): T\n public wrap(...args: Array<any>) {\n const tracer = this\n const [name, options, fn] =\n args.length === 3 ? args : [args[0], {}, args[1]]\n\n if (\n !NextVanillaSpanAllowlist.has(name) &&\n process.env.NEXT_OTEL_VERBOSE !== '1'\n ) {\n return fn\n }\n\n return function (this: any) {\n let optionsObj = options\n if (typeof optionsObj === 'function' && typeof fn === 'function') {\n optionsObj = optionsObj.apply(this, arguments)\n }\n\n const lastArgId = arguments.length - 1\n const cb = arguments[lastArgId]\n\n if (typeof cb === 'function') {\n const scopeBoundCb = tracer.getContext().bind(context.active(), cb)\n return tracer.trace(name, optionsObj, (_span, done) => {\n arguments[lastArgId] = function (err: any) {\n done?.(err)\n return scopeBoundCb.apply(this, arguments)\n }\n\n return fn.apply(this, arguments)\n })\n } else {\n return tracer.trace(name, optionsObj, () => fn.apply(this, arguments))\n }\n }\n }\n\n public startSpan(type: SpanTypes): Span\n public startSpan(type: SpanTypes, options: TracerSpanOptions): Span\n public startSpan(...args: Array<any>): Span {\n const [type, options]: [string, TracerSpanOptions | undefined] = args as any\n\n const spanContext = this.getSpanContext(\n options?.parentSpan ?? this.getActiveScopeSpan()\n )\n return this.getTracerInstance().startSpan(type, options, spanContext)\n }\n\n private getSpanContext(parentSpan?: Span) {\n const spanContext = parentSpan\n ? trace.setSpan(context.active(), parentSpan)\n : undefined\n\n return spanContext\n }\n\n public getRootSpanAttributes() {\n const spanId = context.active().getValue(rootSpanIdKey) as number\n return rootSpanAttributesStore.get(spanId)\n }\n\n public setRootSpanAttribute(key: AttributeNames, value: AttributeValue) {\n const spanId = context.active().getValue(rootSpanIdKey) as number\n const attributes = rootSpanAttributesStore.get(spanId)\n if (attributes && !attributes.has(key)) {\n attributes.set(key, value)\n }\n }\n}\n\nconst getTracer = (() => {\n const tracer = new NextTracerImpl()\n\n return () => tracer\n})()\n\nexport { getTracer, SpanStatusCode, SpanKind }\nexport type { NextTracer, Span, SpanOptions, ContextAPI, TracerSpanOptions }\n"],"names":["BubbledError","SpanKind","SpanStatusCode","getTracer","isBubbledError","NEXT_OTEL_PERFORMANCE_PREFIX","process","env","api","NEXT_RUNTIME","require","err","context","propagation","trace","ROOT_CONTEXT","Error","constructor","bubble","result","error","closeSpanWithError","span","setAttribute","recordException","name","setStatus","code","ERROR","message","end","rootSpanAttributesStore","Map","rootSpanIdKey","createContextKey","lastSpanId","getSpanId","clientTraceDataSetter","set","carrier","key","value","push","NextTracerImpl","getTracerInstance","getContext","getTracePropagationData","activeContext","active","entries","inject","getActiveScopeSpan","getSpan","withPropagatedContext","fn","getter","getSpanContext","remoteContext","extract","with","args","type","fnOrOptions","fnOrEmpty","options","spanName","NextVanillaSpanAllowlist","has","NEXT_OTEL_VERBOSE","hideSpan","spanContext","parentSpan","isRootSpan","isRemote","spanId","attributes","setValue","startActiveSpan","startTime","LogSpanAllowList","globalThis","performance","now","undefined","cleanedUp","onCleanup","delete","measure","split","pop","replace","match","toLowerCase","start","Object","length","isThenable","then","res","catch","finally","wrap","tracer","optionsObj","apply","arguments","lastArgId","cb","scopeBoundCb","bind","_span","done","startSpan","setSpan","getRootSpanAttributes","getValue","get","setRootSpanAttribute"],"mappings":";;;;;;;;;;;;;;;;;;IAwCaA,YAAY;eAAZA;;IA6buBC,QAAQ;eAARA;;IAAhBC,cAAc;eAAdA;;IAAXC,SAAS;eAATA;;IApbOC,cAAc;eAAdA;;;2BA9C2C;4BAUhC;AAE3B,MAAMC,+BAA+BC,QAAQC,GAAG,CAACF,4BAA4B;AAE7E,IAAIG;AAEJ,gFAAgF;AAChF,8EAA8E;AAC9E,uCAAuC;AACvC,0EAA0E;AAC1E,+EAA+E;AAC/E,4CAA4C;AAC5C,6CAA6C;AAC7C,IAAIF,QAAQC,GAAG,CAACE,YAAY,KAAK,QAAQ;IACvCD,MAAME,QAAQ;AAChB,OAAO;IACL,IAAI;QACFF,MAAME,QAAQ;IAChB,EAAE,OAAOC,KAAK;QACZH,MACEE,QAAQ;IACZ;AACF;AAEA,MAAM,EAAEE,OAAO,EAAEC,WAAW,EAAEC,KAAK,EAAEZ,cAAc,EAAED,QAAQ,EAAEc,YAAY,EAAE,GAC3EP;AAEK,MAAMR,qBAAqBgB;IAChCC,YACE,AAAgBC,MAAgB,EAChC,AAAgBC,MAAyB,CACzC;QACA,KAAK,SAHWD,SAAAA,aACAC,SAAAA;IAGlB;AACF;AAEO,SAASf,eAAegB,KAAc;IAC3C,IAAI,OAAOA,UAAU,YAAYA,UAAU,MAAM,OAAO;IACxD,OAAOA,iBAAiBpB;AAC1B;AAE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AC3D;IAEQd,eAAee,UAAiB,EAAE;QACxC,MAAMD,cAAcC,aAChBzD,MAAMmG,OAAO,CAACrG,QAAQoC,MAAM,IAAIuB,cAChCY;QAEJ,OAAOb;IACT;IAEO4C,wBAAwB;QAC7B,MAAMxC,SAAS9D,QAAQoC,MAAM,GAAGmE,QAAQ,CAAClF;QACzC,OAAOF,wBAAwBqF,GAAG,CAAC1C;IACrC;IAEO2C,qBAAqB7E,GAAmB,EAAEC,KAAqB,EAAE;QACtE,MAAMiC,SAAS9D,QAAQoC,MAAM,GAAGmE,QAAQ,CAAClF;QACzC,MAAM0C,aAAa5C,wBAAwBqF,GAAG,CAAC1C;QAC/C,IAAIC,cAAc,CAACA,WAAWR,GAAG,CAAC3B,MAAM;YACtCmC,WAAWrC,GAAG,CAACE,KAAKC;QACtB;IACF;AACF;AAEA,MAAMtC,YAAY,AAAC,CAAA;IACjB,MAAMmG,SAAS,IAAI3D;IAEnB,OAAO,IAAM2D;AACf,CAAA","ignoreList":[0]}
1
+ {"version":3,"sources":["../../../../src/server/lib/trace/tracer.ts"],"sourcesContent":["import type { FetchEventResult } from '../../web/types'\nimport type { TextMapSetter } from '@opentelemetry/api'\nimport type { SpanTypes } from './constants'\nimport { LogSpanAllowList, NextVanillaSpanAllowlist } from './constants'\n\nimport type {\n ContextAPI,\n Span,\n SpanOptions,\n Tracer,\n AttributeValue,\n TextMapGetter,\n} from 'next/dist/compiled/@opentelemetry/api'\nimport { isThenable } from '../../../shared/lib/is-thenable'\n\nconst NEXT_OTEL_PERFORMANCE_PREFIX = process.env.NEXT_OTEL_PERFORMANCE_PREFIX\n\nlet api: typeof import('next/dist/compiled/@opentelemetry/api')\n\n// we want to allow users to use their own version of @opentelemetry/api if they\n// want to, so we try to require it first, and if it fails we fall back to the\n// version that is bundled with Next.js\n// this is because @opentelemetry/api has to be synced with the version of\n// @opentelemetry/tracing that is used, and we don't want to force users to use\n// the version that is bundled with Next.js.\n// the API is ~stable, so this should be fine\nif (process.env.NEXT_RUNTIME === 'edge') {\n api = require('@opentelemetry/api') as typeof import('@opentelemetry/api')\n} else {\n try {\n api = require('@opentelemetry/api') as typeof import('@opentelemetry/api')\n } catch (err) {\n api =\n require('next/dist/compiled/@opentelemetry/api') as typeof import('next/dist/compiled/@opentelemetry/api')\n }\n}\n\nconst { context, propagation, trace, SpanStatusCode, SpanKind, ROOT_CONTEXT } =\n api\n\nexport class BubbledError extends Error {\n constructor(\n public readonly bubble?: boolean,\n public readonly result?: FetchEventResult\n ) {\n super()\n }\n}\n\nexport function isBubbledError(error: unknown): error is BubbledError {\n if (typeof error !== 'object' || error === null) return false\n return error instanceof BubbledError\n}\n\nconst closeSpanWithError = (span: Span, error?: Error) => {\n if (isBubbledError(error) && error.bubble) {\n span.setAttribute('next.bubble', true)\n } else {\n if (error) {\n span.recordException(error)\n span.setAttribute('error.type', error.name)\n }\n span.setStatus({ code: SpanStatusCode.ERROR, message: error?.message })\n }\n span.end()\n}\n\ntype TracerSpanOptions = Omit<SpanOptions, 'attributes'> & {\n parentSpan?: Span\n spanName?: string\n attributes?: Partial<Record<AttributeNames, AttributeValue | undefined>>\n hideSpan?: boolean\n}\n\ninterface NextTracer {\n getContext(): ContextAPI\n\n /**\n * Instruments a function by automatically creating a span activated on its\n * scope.\n *\n * The span will automatically be finished when one of these conditions is\n * met:\n *\n * * The function returns a promise, in which case the span will finish when\n * the promise is resolved or rejected.\n * * The function takes a callback as its second parameter, in which case the\n * span will finish when that callback is called.\n * * The function doesn't accept a callback and doesn't return a promise, in\n * which case the span will finish at the end of the function execution.\n *\n */\n trace<T>(\n type: SpanTypes,\n fn: (span?: Span, done?: (error?: Error) => any) => Promise<T>\n ): Promise<T>\n trace<T>(\n type: SpanTypes,\n fn: (span?: Span, done?: (error?: Error) => any) => T\n ): T\n trace<T>(\n type: SpanTypes,\n options: TracerSpanOptions,\n fn: (span?: Span, done?: (error?: Error) => any) => Promise<T>\n ): Promise<T>\n trace<T>(\n type: SpanTypes,\n options: TracerSpanOptions,\n fn: (span?: Span, done?: (error?: Error) => any) => T\n ): T\n\n /**\n * Wrap a function to automatically create a span activated on its\n * scope when it's called.\n *\n * The span will automatically be finished when one of these conditions is\n * met:\n *\n * * The function returns a promise, in which case the span will finish when\n * the promise is resolved or rejected.\n * * The function takes a callback as its last parameter, in which case the\n * span will finish when that callback is called.\n * * The function doesn't accept a callback and doesn't return a promise, in\n * which case the span will finish at the end of the function execution.\n */\n wrap<T = (...args: Array<any>) => any>(type: SpanTypes, fn: T): T\n wrap<T = (...args: Array<any>) => any>(\n type: SpanTypes,\n options: TracerSpanOptions,\n fn: T\n ): T\n wrap<T = (...args: Array<any>) => any>(\n type: SpanTypes,\n options: (...args: any[]) => TracerSpanOptions,\n fn: T\n ): T\n\n /**\n * Starts and returns a new Span representing a logical unit of work.\n *\n * This method do NOT modify the current Context by default. In result, any inner span will not\n * automatically set its parent context to the span created by this method unless manually activate\n * context via `tracer.getContext().with`. `trace`, or `wrap` is generally recommended as it gracefully\n * handles context activation. (ref: https://github.com/open-telemetry/opentelemetry-js/issues/1923)\n */\n startSpan(type: SpanTypes): Span\n startSpan(type: SpanTypes, options: TracerSpanOptions): Span\n\n /**\n * Returns currently activated span if current context is in the scope of the span.\n * Returns undefined otherwise.\n */\n getActiveScopeSpan(): Span | undefined\n\n /**\n * Returns trace propagation data for the currently active context. The format is equal to data provided\n * through the OpenTelemetry propagator API.\n */\n getTracePropagationData(): ClientTraceDataEntry[]\n}\n\ntype NextAttributeNames =\n | 'next.route'\n | 'next.page'\n | 'next.rsc'\n | 'next.segment'\n | 'next.span_name'\n | 'next.span_type'\n | 'next.clientComponentLoadCount'\ntype OTELAttributeNames = `http.${string}` | `net.${string}`\ntype AttributeNames = NextAttributeNames | OTELAttributeNames\n\n/** we use this map to propagate attributes from nested spans to the top span */\nconst rootSpanAttributesStore = new Map<\n number,\n Map<AttributeNames, AttributeValue | undefined>\n>()\nconst rootSpanIdKey = api.createContextKey('next.rootSpanId')\nlet lastSpanId = 0\nconst getSpanId = () => lastSpanId++\n\nexport interface ClientTraceDataEntry {\n key: string\n value: string\n}\n\nconst clientTraceDataSetter: TextMapSetter<ClientTraceDataEntry[]> = {\n set(carrier, key, value) {\n carrier.push({\n key,\n value,\n })\n },\n}\n\nclass NextTracerImpl implements NextTracer {\n /**\n * Returns an instance to the trace with configured name.\n * Since wrap / trace can be defined in any place prior to actual trace subscriber initialization,\n * This should be lazily evaluated.\n */\n private getTracerInstance(): Tracer {\n return trace.getTracer('next.js', '0.0.1')\n }\n\n public getContext(): ContextAPI {\n return context\n }\n\n public getTracePropagationData(): ClientTraceDataEntry[] {\n const activeContext = context.active()\n const entries: ClientTraceDataEntry[] = []\n propagation.inject(activeContext, entries, clientTraceDataSetter)\n return entries\n }\n\n public getActiveScopeSpan(): Span | undefined {\n return trace.getSpan(context?.active())\n }\n\n public withPropagatedContext<T, C>(\n carrier: C,\n fn: () => T,\n getter?: TextMapGetter<C>\n ): T {\n const activeContext = context.active()\n if (trace.getSpanContext(activeContext)) {\n // Active span is already set, too late to propagate.\n return fn()\n }\n const remoteContext = propagation.extract(activeContext, carrier, getter)\n return context.with(remoteContext, fn)\n }\n\n // Trace, wrap implementation is inspired by datadog trace implementation\n // (https://datadoghq.dev/dd-trace-js/interfaces/tracer.html#trace).\n public trace<T>(\n type: SpanTypes,\n fn: (span?: Span, done?: (error?: Error) => any) => Promise<T>\n ): Promise<T>\n public trace<T>(\n type: SpanTypes,\n fn: (span?: Span, done?: (error?: Error) => any) => T\n ): T\n public trace<T>(\n type: SpanTypes,\n options: TracerSpanOptions,\n fn: (span?: Span, done?: (error?: Error) => any) => Promise<T>\n ): Promise<T>\n public trace<T>(\n type: SpanTypes,\n options: TracerSpanOptions,\n fn: (span?: Span, done?: (error?: Error) => any) => T\n ): T\n public trace<T>(...args: Array<any>) {\n const [type, fnOrOptions, fnOrEmpty] = args\n\n // coerce options form overload\n const {\n fn,\n options,\n }: {\n fn: (span?: Span, done?: (error?: Error) => any) => T | Promise<T>\n options: TracerSpanOptions\n } =\n typeof fnOrOptions === 'function'\n ? {\n fn: fnOrOptions,\n options: {},\n }\n : {\n fn: fnOrEmpty,\n options: { ...fnOrOptions },\n }\n\n const spanName = options.spanName ?? type\n\n if (\n (!NextVanillaSpanAllowlist.has(type) &&\n process.env.NEXT_OTEL_VERBOSE !== '1') ||\n options.hideSpan\n ) {\n return fn()\n }\n\n // Trying to get active scoped span to assign parent. If option specifies parent span manually, will try to use it.\n let spanContext = this.getSpanContext(\n options?.parentSpan ?? this.getActiveScopeSpan()\n )\n\n if (!spanContext) {\n spanContext = context?.active() ?? ROOT_CONTEXT\n }\n // Check if there's already a root span in the store for this trace\n // We are intentionally not checking whether there is an active context\n // from outside of nextjs to ensure that we can provide the same level\n // of telemetry when using a custom server\n const existingRootSpanId = spanContext.getValue(rootSpanIdKey)\n const isRootSpan =\n typeof existingRootSpanId !== 'number' ||\n !rootSpanAttributesStore.has(existingRootSpanId)\n\n const spanId = getSpanId()\n\n options.attributes = {\n 'next.span_name': spanName,\n 'next.span_type': type,\n ...options.attributes,\n }\n\n return context.with(spanContext.setValue(rootSpanIdKey, spanId), () =>\n this.getTracerInstance().startActiveSpan(\n spanName,\n options,\n (span: Span) => {\n let startTime: number | undefined\n if (\n NEXT_OTEL_PERFORMANCE_PREFIX &&\n type &&\n LogSpanAllowList.has(type)\n ) {\n startTime =\n 'performance' in globalThis && 'measure' in performance\n ? globalThis.performance.now()\n : undefined\n }\n\n let cleanedUp = false\n const onCleanup = () => {\n if (cleanedUp) return\n cleanedUp = true\n rootSpanAttributesStore.delete(spanId)\n if (startTime) {\n performance.measure(\n `${NEXT_OTEL_PERFORMANCE_PREFIX}:next-${(\n type.split('.').pop() || ''\n ).replace(\n /[A-Z]/g,\n (match: string) => '-' + match.toLowerCase()\n )}`,\n {\n start: startTime,\n end: performance.now(),\n }\n )\n }\n }\n\n if (isRootSpan) {\n rootSpanAttributesStore.set(\n spanId,\n new Map(\n Object.entries(options.attributes ?? {}) as [\n AttributeNames,\n AttributeValue | undefined,\n ][]\n )\n )\n }\n if (fn.length > 1) {\n try {\n return fn(span, (err) => closeSpanWithError(span, err))\n } catch (err: any) {\n closeSpanWithError(span, err)\n throw err\n } finally {\n onCleanup()\n }\n }\n\n try {\n const result = fn(span)\n if (isThenable(result)) {\n // If there's error make sure it throws\n return result\n .then((res) => {\n span.end()\n // Need to pass down the promise result,\n // it could be react stream response with error { error, stream }\n return res\n })\n .catch((err) => {\n closeSpanWithError(span, err)\n throw err\n })\n .finally(onCleanup)\n } else {\n span.end()\n onCleanup()\n }\n\n return result\n } catch (err: any) {\n closeSpanWithError(span, err)\n onCleanup()\n throw err\n }\n }\n )\n )\n }\n\n public wrap<T = (...args: Array<any>) => any>(type: SpanTypes, fn: T): T\n public wrap<T = (...args: Array<any>) => any>(\n type: SpanTypes,\n options: TracerSpanOptions,\n fn: T\n ): T\n public wrap<T = (...args: Array<any>) => any>(\n type: SpanTypes,\n options: (...args: any[]) => TracerSpanOptions,\n fn: T\n ): T\n public wrap(...args: Array<any>) {\n const tracer = this\n const [name, options, fn] =\n args.length === 3 ? args : [args[0], {}, args[1]]\n\n if (\n !NextVanillaSpanAllowlist.has(name) &&\n process.env.NEXT_OTEL_VERBOSE !== '1'\n ) {\n return fn\n }\n\n return function (this: any) {\n let optionsObj = options\n if (typeof optionsObj === 'function' && typeof fn === 'function') {\n optionsObj = optionsObj.apply(this, arguments)\n }\n\n const lastArgId = arguments.length - 1\n const cb = arguments[lastArgId]\n\n if (typeof cb === 'function') {\n const scopeBoundCb = tracer.getContext().bind(context.active(), cb)\n return tracer.trace(name, optionsObj, (_span, done) => {\n arguments[lastArgId] = function (err: any) {\n done?.(err)\n return scopeBoundCb.apply(this, arguments)\n }\n\n return fn.apply(this, arguments)\n })\n } else {\n return tracer.trace(name, optionsObj, () => fn.apply(this, arguments))\n }\n }\n }\n\n public startSpan(type: SpanTypes): Span\n public startSpan(type: SpanTypes, options: TracerSpanOptions): Span\n public startSpan(...args: Array<any>): Span {\n const [type, options]: [string, TracerSpanOptions | undefined] = args as any\n\n const spanContext = this.getSpanContext(\n options?.parentSpan ?? this.getActiveScopeSpan()\n )\n return this.getTracerInstance().startSpan(type, options, spanContext)\n }\n\n private getSpanContext(parentSpan?: Span) {\n const spanContext = parentSpan\n ? trace.setSpan(context.active(), parentSpan)\n : undefined\n\n return spanContext\n }\n\n public getRootSpanAttributes() {\n const spanId = context.active().getValue(rootSpanIdKey) as number\n return rootSpanAttributesStore.get(spanId)\n }\n\n public setRootSpanAttribute(key: AttributeNames, value: AttributeValue) {\n const spanId = context.active().getValue(rootSpanIdKey) as number\n const attributes = rootSpanAttributesStore.get(spanId)\n if (attributes && !attributes.has(key)) {\n attributes.set(key, value)\n }\n }\n}\n\nconst getTracer = (() => {\n const tracer = new NextTracerImpl()\n\n return () => tracer\n})()\n\nexport { getTracer, SpanStatusCode, SpanKind }\nexport type { NextTracer, Span, SpanOptions, ContextAPI, TracerSpanOptions }\n"],"names":["BubbledError","SpanKind","SpanStatusCode","getTracer","isBubbledError","NEXT_OTEL_PERFORMANCE_PREFIX","process","env","api","NEXT_RUNTIME","require","err","context","propagation","trace","ROOT_CONTEXT","Error","constructor","bubble","result","error","closeSpanWithError","span","setAttribute","recordException","name","setStatus","code","ERROR","message","end","rootSpanAttributesStore","Map","rootSpanIdKey","createContextKey","lastSpanId","getSpanId","clientTraceDataSetter","set","carrier","key","value","push","NextTracerImpl","getTracerInstance","getContext","getTracePropagationData","activeContext","active","entries","inject","getActiveScopeSpan","getSpan","withPropagatedContext","fn","getter","getSpanContext","remoteContext","extract","with","args","type","fnOrOptions","fnOrEmpty","options","spanName","NextVanillaSpanAllowlist","has","NEXT_OTEL_VERBOSE","hideSpan","spanContext","parentSpan","existingRootSpanId","getValue","isRootSpan","spanId","attributes","setValue","startActiveSpan","startTime","LogSpanAllowList","globalThis","performance","now","undefined","cleanedUp","onCleanup","delete","measure","split","pop","replace","match","toLowerCase","start","Object","length","isThenable","then","res","catch","finally","wrap","tracer","optionsObj","apply","arguments","lastArgId","cb","scopeBoundCb","bind","_span","done","startSpan","setSpan","getRootSpanAttributes","get","setRootSpanAttribute"],"mappings":";;;;;;;;;;;;;;;;;;IAwCaA,YAAY;eAAZA;;IAicuBC,QAAQ;eAARA;;IAAhBC,cAAc;eAAdA;;IAAXC,SAAS;eAATA;;IAxbOC,cAAc;eAAdA;;;2BA9C2C;4BAUhC;AAE3B,MAAMC,+BAA+BC,QAAQC,GAAG,CAACF,4BAA4B;AAE7E,IAAIG;AAEJ,gFAAgF;AAChF,8EAA8E;AAC9E,uCAAuC;AACvC,0EAA0E;AAC1E,+EAA+E;AAC/E,4CAA4C;AAC5C,6CAA6C;AAC7C,IAAIF,QAAQC,GAAG,CAACE,YAAY,KAAK,QAAQ;IACvCD,MAAME,QAAQ;AAChB,OAAO;IACL,IAAI;QACFF,MAAME,QAAQ;IAChB,EAAE,OAAOC,KAAK;QACZH,MACEE,QAAQ;IACZ;AACF;AAEA,MAAM,EAAEE,OAAO,EAAEC,WAAW,EAAEC,KAAK,EAAEZ,cAAc,EAAED,QAAQ,EAAEc,YAAY,EAAE,GAC3EP;AAEK,MAAMR,qBAAqBgB;IAChCC,YACE,AAAgBC,MAAgB,EAChC,AAAgBC,MAAyB,CACzC;QACA,KAAK,SAHWD,SAAAA,aACAC,SAAAA;IAGlB;AACF;AAEO,SAASf,eAAegB,KAAc;IAC3C,IAAI,OAAOA,UAAU,YAAYA,UAAU,MAAM,OAAO;IACxD,OAAOA,iBAAiBpB;AAC1B;AAEA,MAAMqB,qBAAqB,CAACC,MAAYF;IACtC,IAAIhB,eAAegB,UAAUA,MAAMF,MAAM,EAAE;QACzCI,KAAKC,YAAY,CAAC,eAAe;IACnC,OAAO;QACL,IAAIH,OAAO;YACTE,KAAKE,eAAe,CAACJ;YACrBE,KAAKC,YAAY,CAAC,cAAcH,MAAMK,IAAI;QAC5C;QACAH,KAAKI,SAAS,CAAC;YAAEC,MAAMzB,eAAe0B,KAAK;Y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C;IACrC;IAEO0C,qBAAqB7E,GAAmB,EAAEC,KAAqB,EAAE;QACtE,MAAMkC,SAAS/D,QAAQoC,MAAM,GAAGyB,QAAQ,CAACxC;QACzC,MAAM2C,aAAa7C,wBAAwBqF,GAAG,CAACzC;QAC/C,IAAIC,cAAc,CAACA,WAAWT,GAAG,CAAC3B,MAAM;YACtCoC,WAAWtC,GAAG,CAACE,KAAKC;QACtB;IACF;AACF;AAEA,MAAMtC,YAAY,AAAC,CAAA;IACjB,MAAMoG,SAAS,IAAI5D;IAEnB,OAAO,IAAM4D;AACf,CAAA","ignoreList":[0]}
@@ -21,7 +21,7 @@ _export(exports, {
21
21
  }
22
22
  });
23
23
  function isStableBuild() {
24
- return !"16.0.2-canary.10"?.includes('canary') && !process.env.__NEXT_TEST_MODE && !process.env.NEXT_PRIVATE_LOCAL_DEV;
24
+ return !"16.0.2-canary.11"?.includes('canary') && !process.env.__NEXT_TEST_MODE && !process.env.NEXT_PRIVATE_LOCAL_DEV;
25
25
  }
26
26
  class CanaryOnlyConfigError extends Error {
27
27
  constructor(arg){
@@ -81,7 +81,7 @@ function getAnonymousMeta() {
81
81
  isWsl: _iswsl.default,
82
82
  isCI: _ciinfo.isCI,
83
83
  ciName: _ciinfo.isCI && _ciinfo.name || null,
84
- nextVersion: "16.0.2-canary.10"
84
+ nextVersion: "16.0.2-canary.11"
85
85
  };
86
86
  return traits;
87
87
  }
@@ -11,11 +11,11 @@ Object.defineProperty(exports, "eventCliSessionStopped", {
11
11
  const EVENT_VERSION = 'NEXT_CLI_SESSION_STOPPED';
12
12
  function eventCliSessionStopped(event) {
13
13
  // This should be an invariant, if it fails our build tooling is broken.
14
- if (typeof "16.0.2-canary.10" !== 'string') {
14
+ if (typeof "16.0.2-canary.11" !== 'string') {
15
15
  return [];
16
16
  }
17
17
  const payload = {
18
- nextVersion: "16.0.2-canary.10",
18
+ nextVersion: "16.0.2-canary.11",
19
19
  nodeVersion: process.version,
20
20
  cliCommand: event.cliCommand,
21
21
  durationMilliseconds: event.durationMilliseconds,
@@ -12,12 +12,12 @@ const EVENT_VERSION = 'NEXT_CLI_SESSION_STARTED';
12
12
  function eventCliSession(nextConfig, event) {
13
13
  var _nextConfig_experimental_staleTimes, _nextConfig_experimental_staleTimes1, _nextConfig_reactCompiler, _nextConfig_reactCompiler1;
14
14
  // This should be an invariant, if it fails our build tooling is broken.
15
- if (typeof "16.0.2-canary.10" !== 'string') {
15
+ if (typeof "16.0.2-canary.11" !== 'string') {
16
16
  return [];
17
17
  }
18
18
  const { images, i18n } = nextConfig || {};
19
19
  const payload = {
20
- nextVersion: "16.0.2-canary.10",
20
+ nextVersion: "16.0.2-canary.11",
21
21
  nodeVersion: process.version,
22
22
  cliCommand: event.cliCommand,
23
23
  isSrcDir: event.isSrcDir,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "next",
3
- "version": "16.0.2-canary.10",
3
+ "version": "16.0.2-canary.11",
4
4
  "description": "The React Framework",
5
5
  "main": "./dist/server/next.js",
6
6
  "license": "MIT",
@@ -98,7 +98,7 @@
98
98
  ]
99
99
  },
100
100
  "dependencies": {
101
- "@next/env": "16.0.2-canary.10",
101
+ "@next/env": "16.0.2-canary.11",
102
102
  "@swc/helpers": "0.5.15",
103
103
  "caniuse-lite": "^1.0.30001579",
104
104
  "postcss": "8.4.31",
@@ -128,14 +128,14 @@
128
128
  },
129
129
  "optionalDependencies": {
130
130
  "sharp": "^0.34.4",
131
- "@next/swc-darwin-arm64": "16.0.2-canary.10",
132
- "@next/swc-darwin-x64": "16.0.2-canary.10",
133
- "@next/swc-linux-arm64-gnu": "16.0.2-canary.10",
134
- "@next/swc-linux-arm64-musl": "16.0.2-canary.10",
135
- "@next/swc-linux-x64-gnu": "16.0.2-canary.10",
136
- "@next/swc-linux-x64-musl": "16.0.2-canary.10",
137
- "@next/swc-win32-arm64-msvc": "16.0.2-canary.10",
138
- "@next/swc-win32-x64-msvc": "16.0.2-canary.10"
131
+ "@next/swc-darwin-arm64": "16.0.2-canary.11",
132
+ "@next/swc-darwin-x64": "16.0.2-canary.11",
133
+ "@next/swc-linux-arm64-gnu": "16.0.2-canary.11",
134
+ "@next/swc-linux-arm64-musl": "16.0.2-canary.11",
135
+ "@next/swc-linux-x64-gnu": "16.0.2-canary.11",
136
+ "@next/swc-linux-x64-musl": "16.0.2-canary.11",
137
+ "@next/swc-win32-arm64-msvc": "16.0.2-canary.11",
138
+ "@next/swc-win32-x64-msvc": "16.0.2-canary.11"
139
139
  },
140
140
  "devDependencies": {
141
141
  "@babel/code-frame": "7.26.2",
@@ -170,11 +170,11 @@
170
170
  "@modelcontextprotocol/sdk": "1.18.1",
171
171
  "@mswjs/interceptors": "0.23.0",
172
172
  "@napi-rs/triples": "1.2.0",
173
- "@next/font": "16.0.2-canary.10",
174
- "@next/polyfill-module": "16.0.2-canary.10",
175
- "@next/polyfill-nomodule": "16.0.2-canary.10",
176
- "@next/react-refresh-utils": "16.0.2-canary.10",
177
- "@next/swc": "16.0.2-canary.10",
173
+ "@next/font": "16.0.2-canary.11",
174
+ "@next/polyfill-module": "16.0.2-canary.11",
175
+ "@next/polyfill-nomodule": "16.0.2-canary.11",
176
+ "@next/react-refresh-utils": "16.0.2-canary.11",
177
+ "@next/swc": "16.0.2-canary.11",
178
178
  "@opentelemetry/api": "1.6.0",
179
179
  "@playwright/test": "1.51.1",
180
180
  "@rspack/core": "1.6.0",