Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure user-installed opentelemetry package has the minimal required version #50554

Merged
merged 4 commits into from
Jun 2, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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