sveltejs/kit · error · Error
Tracing is enabled (see the SvelteKit plugin `tracing.server
Error message
Tracing is enabled (see the SvelteKit plugin `tracing.server` option in your vite.config.js), but `@opentelemetry/api` is not available. This error will likely resolve itself when you set up your tracing instrumentation in `instrumentation.server.js`. For more information, see https://svelte.dev/docs/kit/observability#opentelemetry-api
What it means
When tracing is enabled via the SvelteKit plugin's `tracing.server` option, SvelteKit imports `@opentelemetry/api` to create spans. If that package cannot be resolved, initialization fails with this error, directing you to set up tracing instrumentation (typically in `instrumentation.server.js`) which registers the provider.
Source
Thrown at packages/kit/src/exports/internal/server/telemetry.js:29
/**
* The caller passes in `import('@opentelemetry/api')` so the import lives behind
* `__SVELTEKIT_SERVER_TRACING_ENABLED__` in the bundled runtime and is eliminated
* from builds with tracing disabled, where the package may not be installed.
* @param {Promise<typeof import('@opentelemetry/api')>} api
* @returns {void}
*/
export function init_tracing(api) {
otel ??= api
.then((module) => {
return {
tracer: module.trace.getTracer('sveltekit'),
propagation: module.propagation,
context: module.context,
SpanStatusCode: module.SpanStatusCode
};
})
.catch(() => {
throw new Error(
'Tracing is enabled (see the SvelteKit plugin `tracing.server` option in your vite.config.js), but `@opentelemetry/api` is not available. This error will likely resolve itself when you set up your tracing instrumentation in `instrumentation.server.js`. For more information, see https://svelte.dev/docs/kit/observability#opentelemetry-api'
);
});
}
/** @type {RecordSpan} */
export async function record_span({ name, attributes, fn }) {
if (otel === null) {
return fn(noop_span);
}
const { SpanStatusCode, tracer } = await otel;
return tracer.startActiveSpan(name, { attributes }, async (span) => {
try {
return await fn(span);
} catch (error) {
if (error instanceof HttpError) {View on GitHub (pinned to 03f1687fe6)
Solutions
- Install the package: `npm install @opentelemetry/api` (add it to production dependencies).
- Create/complete `instrumentation.server.js` to register a span processor/exporter per the SvelteKit observability docs.
- If you don't want tracing, disable the `tracing.server` plugin option.
- Rebuild/redeploy after installing so the server bundle can resolve the module.
Example fix
// before (svelte.config.js)
kit: { experimental: { tracing: { server: true } } }
// after
// terminal: npm i @opentelemetry/api
// instrumentation.server.js
import { NodeSDK } from '@opentelemetry/sdk-node';
export const handleInstrumentation = (sdk = new NodeSDK()) => sdk.start(); Defensive patterns
Strategy: fallback
Validate before calling
let api;
try {
api = await import('@opentelemetry/api');
} catch {
api = null; // tracing unavailable — disable or install the package
}
if (!api) console.warn('tracing.server enabled but @opentelemetry/api missing'); Try / catch
try {
await init_tracing();
} catch (e) {
if (String(e.message).includes('@opentelemetry/api')) {
console.warn('Tracing disabled: install @opentelemetry/api or turn off tracing.server');
} else throw e;
} Prevention
- Add @opentelemetry/api to production dependencies when tracing is enabled.
- Create instrumentation.server.js before enabling tracing.server.
- Verify the package resolves in the deployment bundle, not just locally.
When it happens
Trigger: Setting `tracing.server` in `svelte.config.js`/vite plugin options without `@opentelemetry/api` installed; the package is in devDependencies but the server is bundled/deployed without it; a broken node_modules after version changes.
Common situations: Enabling observability in production deployments where `@opentelemetry/api` wasn't added to production dependencies; monorepo hoisting issues hiding the package; forgetting `instrumentation.server.js` setup that registers a tracer provider.
Understand the failure class
Background: "not installed", "pip install", "required for": how missing-dependency errors surface across open-source libraries — this error's family across 34 libraries.
Related errors
- exports is not available in dev mode
- The `generateManifest` adapter API has been removed — use `g
- Instrumentation file ${instrumentation} not found. This is p
- Entrypoint file ${entrypoint} not found. This is probably a
- Instrumentation initializer ${initializer} not found. This i
AI-assisted analysis of sveltejs/kit@03f1687fe6 (2026-09-02).
Data as JSON: /api/errors/25357852108303b2.
Report an issue: GitHub.