Unverified Commit 8f0acdf7 authored by JJ Kasper's avatar JJ Kasper Committed by GitHub

Gracefully handle telemetry not being available (#44986)

parent 6d09f0b8
......@@ -607,7 +607,7 @@ function getExtractMetadata(params: {
return async () => {
metadataByEntry.clear()
const resolver = compilation.resolverFactory.get('normal')
const telemetry: Telemetry = traceGlobals.get('telemetry')
const telemetry: Telemetry | undefined = traceGlobals.get('telemetry')
for (const [entryName, entry] of compilation.entries) {
if (entry.options.runtime !== EDGE_RUNTIME_WEBPACK) {
......@@ -683,7 +683,7 @@ function getExtractMetadata(params: {
}
if (edgeFunctionConfig?.config?.unstable_allowDynamicGlobs) {
telemetry.record({
telemetry?.record({
eventName: 'NEXT_EDGE_ALLOW_DYNAMIC_USED',
payload: {
...edgeFunctionConfig,
......@@ -773,7 +773,7 @@ function getExtractMetadata(params: {
}
}
telemetry.record({
telemetry?.record({
eventName: EVENT_BUILD_FEATURE_USAGE,
payload: {
featureName: 'vercelImageGeneration',
......
......@@ -20,7 +20,7 @@ export type EventSwcLoadFailure = {
export async function eventSwcLoadFailure(
event?: EventSwcLoadFailure['payload']
): Promise<void> {
const telemetry: Telemetry = traceGlobals.get('telemetry')
const telemetry: Telemetry | undefined = traceGlobals.get('telemetry')
// can't continue if telemetry isn't set
if (!telemetry) return
......
import { Telemetry } from '../../telemetry/storage'
import { traceGlobals } from '../shared'
const TRACE_EVENT_ACCESSLIST = new Map(
......@@ -11,7 +12,7 @@ const reportToTelemetry = (spanName: string, duration: number) => {
if (!eventName) {
return
}
const telemetry = traceGlobals.get('telemetry')
const telemetry: Telemetry | undefined = traceGlobals.get('telemetry')
if (!telemetry) {
return
}
......
export type SpanId = number
export const traceGlobals: Map<any, any> = new Map()
let _traceGlobals: Map<any, any> = (global as any)._traceGlobals
if (!_traceGlobals) {
_traceGlobals = new Map()
}
;(global as any)._traceGlobals = _traceGlobals
export const traceGlobals: Map<any, any> = _traceGlobals
export const setGlobal = (key: any, val: any) => {
traceGlobals.set(key, val)
}
......@@ -6,7 +6,11 @@ import { NextInstance } from 'test/lib/next-modes/base'
jest.setTimeout(2 * 60 * 1000)
export function runTests(example = '') {
export function runTests(
example = '',
testPath = '/',
expectedContent = ['index page']
) {
const versionParts = process.versions.node.split('.').map((i) => Number(i))
if ((global as any).isNextDeploy) {
......@@ -42,7 +46,7 @@ export function runTests(example = '') {
prev.push(`${cur}@${dependencies[cur]}`)
return prev
}, [] as string[])
return `yarn set version 4.0.0-rc.13 && yarn config set enableGlobalCache true && yarn config set compressionLevel 0 && yarn add ${pkgs.join(
return `yarn set version berry && yarn config set enableGlobalCache true && yarn config set compressionLevel 0 && yarn add ${pkgs.join(
' '
)}`
},
......@@ -55,9 +59,14 @@ export function runTests(example = '') {
afterAll(() => next?.destroy())
it(`should compile and serve the index page correctly ${example}`, async () => {
const res = await fetchViaHTTP(next.url, '/')
const res = await fetchViaHTTP(next.url, testPath)
expect(res.status).toBe(200)
expect(await res.text()).toContain('<html')
const text = await res.text()
for (const content of expectedContent) {
expect(text).toContain(content)
}
})
} else {
it('should not run PnP test for older node versions', () => {})
......
import { runTests } from './utils'
describe('yarn PnP', () => {
runTests('with-eslint')
runTests('with-eslint', '/', ['<html', 'Home', 'fake-script'])
})
import { runTests } from './utils'
describe('yarn PnP', () => {
runTests('with-mdx')
runTests('with-mdx', '/', ['Look, a button', 'Hello'])
})
import { runTests } from './utils'
describe('yarn PnP', () => {
runTests('with-next-sass')
runTests('with-next-sass', '/', [
'Hello World, I am being styled using SCSS Modules',
])
})
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment