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

Cannot find module 'OTLPTraceExporter' imported from /app/server/index.mjs #5218

Closed
nishant-compro opened this issue Nov 29, 2024 · 5 comments · Fixed by #5227
Closed

Cannot find module 'OTLPTraceExporter' imported from /app/server/index.mjs #5218

nishant-compro opened this issue Nov 29, 2024 · 5 comments · Fixed by #5227
Assignees
Labels

Comments

@nishant-compro
Copy link

nishant-compro commented Nov 29, 2024

Description

We are importing @opentelemetry/exporter-trace-otlp-http in our setup code. Everything was working fine till v0.52.1, but the following error is coming after updating to v0.53.0. The error is coming when we are starting the node server.

Error message

Error [ERR_MODULE_NOT_FOUND]: Cannot find module '/app/node_modules/.pnpm/@[email protected]_@[email protected]/node_modules/@opentelemetry/exporter-trace-otlp-http/build/src/platform/node/OTLPTraceExporter' imported from /app/server/index.mjs
    at finalizeResolution (node:internal/modules/esm/resolve:265:11)
    at moduleResolve (node:internal/modules/esm/resolve:933:10)
    at defaultResolve (node:internal/modules/esm/resolve:1157:11)
    at ModuleLoader.defaultResolve (node:internal/modules/esm/loader:390:12)
    at ModuleLoader.resolve (node:internal/modules/esm/loader:359:25)
    at ModuleLoader.getModuleJob (node:internal/modules/esm/loader:234:38)
    at ModuleWrap.<anonymous> (node:internal/modules/esm/module_job:87:39)
    at link (node:internal/modules/esm/module_job:86:36) {
  code: 'ERR_MODULE_NOT_FOUND',
  url: 'file:///app/node_modules/.pnpm/@[email protected]_@[email protected]/node_modules/@opentelemetry/exporter-trace-otlp-http/build/src/platform/node/OTLPTraceExporter'
}

Additional Details

  • This is a Nuxt app monorepo, setup with Nx and pnpm.
  • On version 0.52.1, after the build, @opentelemetry/exporter-trace-otlp-http was present in the package.json of the build dir .output. And was also imported in the index.mjs file. After the update, it is not present in the above places, and instead, its code is inline in the server chunk index.mjs.
  • This error is coming for version 0.55.0 as well.

OpenTelemetry Setup Code

// src/server/plugins/tracing.ts
import { Resource } from '@opentelemetry/resources';
import { SEMRESATTRS_SERVICE_NAME } from '@opentelemetry/semantic-conventions';
import { BatchSpanProcessor } from '@opentelemetry/sdk-trace-base';
import { NodeTracerProvider } from '@opentelemetry/sdk-trace-node';
import { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-http';
import { registerInstrumentations } from '@opentelemetry/instrumentation';
import { HttpInstrumentation } from '@opentelemetry/instrumentation-http';
import type {
  HttpRequestCustomAttributeFunction,
  IgnoreIncomingRequestFunction
} from '@opentelemetry/instrumentation-http';
import type { Span } from '@opentelemetry/api';
import type { ClientRequest, IncomingMessage } from 'http';

export default defineNitroPlugin(() => {
    const {
      traceExporterEndpoint,
      apiKey,
      appName,
      appEnv,
      otelExporterThresholds
    } = getOpentelemetryConfig();

    // Configure the OTLP exporter
    const exporterConfig: ExporterConfig = {
      url: traceExporterEndpoint,
      headers: {
        'api-key': apiKey
      },
      concurrencyLimit: otelExporterThresholds.concurrencyLimit
    };

    // Initialize OTEL trace exporter
    const exporter = new OTLPTraceExporter(exporterConfig);

    // Create a NodeTracerProvider instance
    const provider = new NodeTracerProvider({
      resource: new Resource({
        [SEMRESATTRS_SERVICE_NAME]: `${appName}-${appEnv}-server`
      })
    });

    provider.addSpanProcessor(
      new BatchSpanProcessor(exporter, {
        maxExportBatchSize: otelExporterThresholds.maxExportBatchSize,
        scheduledDelayMillis: otelExporterThresholds.scheduledDelayMillis,
        exportTimeoutMillis: otelExporterThresholds.exportTimeoutMillis,
        maxQueueSize: otelExporterThresholds.maxQueueSize
      })
    );

    // Register the provider with OpenTelemetry
    provider.register();

package.json

{
  "name": "...",
  "version": "0.0.0",
  "license": "MIT",
  "scripts": {
    "preinstall": "npx only-allow pnpm",
    "docs": "typedoc"
  },
  "private": true,
  "dependencies": {
    "@opentelemetry/api": "1.9.0",
    "@opentelemetry/exporter-trace-otlp-http": "0.53.0",
    "@opentelemetry/instrumentation": "0.53.0",
    "@opentelemetry/instrumentation-http": "0.53.0",
    "@opentelemetry/resources": "1.28.0",
    "@opentelemetry/sdk-trace-base": "1.28.0",
    "@opentelemetry/sdk-trace-node": "1.28.0",
    "@opentelemetry/sdk-trace-web": "1.28.0",
    "@opentelemetry/semantic-conventions": "1.28.0"
  }
}

Relevant log output

No response

Operating System and Version

No response

Runtime and Version

  • Operating System: Linux
  • Node Version: v20.12.0
  • Nuxt Version: 3.13.2
  • Package Manager: [email protected]
  • Nx: v20.0.5
@pichlermarc
Copy link
Member

Hi, thanks for reaching out - I've looked into this and found some weird behavior around comments when building with Nuxt. Going from 0.52.1 to 0.53.0, we added this comment here:

* TODO: Replace export * with named exports before next major version

It's absolutely astonishing, but removing that comment above, here and here for some reason makes it work. I narrowed it down to the string export * in a comment causing trouble when used with Nuxt. It breaks using both // and /* comments

I'm fairly certain that this is a bug or limitation with the build tooling that's in use here. Does anyone have an insight/link to what I may be looking at?

@pichlermarc
Copy link
Member

pichlermarc commented Dec 2, 2024

I made a reproducer so that we can verify that changing the comment actually fixes things:
https://github.com/pichlermarc/repro-5218

@pichlermarc
Copy link
Member

Self assigning since I have a fix at #5227

@nishant-compro
Copy link
Author

Hi @pichlermarc, thank you for this fix.

Do you know when is the next release date? As we are stuck due to this.

@pichlermarc
Copy link
Member

please see #5232 for tracking release progress 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
2 participants