Skip to content

Commit

Permalink
Ensure user-installed opentelemetry package has the minimal required …
Browse files Browse the repository at this point in the history
…version (vercel#50554)
  • Loading branch information
shuding authored and hydRAnger committed Jun 12, 2023
1 parent e157348 commit 9c497e7
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions packages/next/src/build/webpack-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import chalk from 'next/dist/compiled/chalk'
import crypto from 'crypto'
import { webpack } from 'next/dist/compiled/webpack/webpack'
import path from 'path'
import semver from 'next/dist/compiled/semver'
import { escapeStringRegexp } from '../shared/lib/escape-regexp'
import {
DOT_NEXT_ALIAS,
Expand Down Expand Up @@ -1041,8 +1042,18 @@ export default async function getBaseWebpackConfig(

let hasExternalOtelApiPackage = false
try {
require.resolve('@opentelemetry/api')
hasExternalOtelApiPackage = true
const opentelemetryPackageJson = require('@opentelemetry/api/package.json')
if (opentelemetryPackageJson.version) {
// 0.19.0 is the first version of the package that has the `tracer.getSpan` API that we need:
// https://github.com/vercel/next.js/issues/48118
if (semver.gte(opentelemetryPackageJson.version, '0.19.0')) {
hasExternalOtelApiPackage = true
} else {
throw new Error(
`Installed "@opentelemetry/api" with version ${opentelemetryPackageJson.version} is not supported by Next.js. Please upgrade to 0.19.0 or newer version.`
)
}
}
} catch {}

const resolveConfig: webpack.Configuration['resolve'] = {
Expand Down

0 comments on commit 9c497e7

Please sign in to comment.