instrumentation.ts + middleware.ts => produces __import_unsupported error
Answered
Havana posted this in #help-forum
HavanaOP
I'm trying to add instrumentation to 2 of my nextjs apps. Both these apps live in the same mono-repo and are pretty similar expect that one has a middleware.ts
The app without a middleware worked as expected when adding instrumentation.
The app that has a middleware fails with
My instrumentation.ts:
Am I missing something? What should I do to make this work?
PS: I'm deploying this app in a docker container, so I don't use edge.
The app without a middleware worked as expected when adding instrumentation.
The app that has a middleware fails with
__import_unsupported
(see full error in the attached file). If I remove the middleware the error does not occur anymore.My instrumentation.ts:
// import { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-http'
import { Resource } from '@opentelemetry/resources'
import { NodeSDK } from '@opentelemetry/sdk-node'
import { BatchSpanProcessor, ConsoleSpanExporter } from '@opentelemetry/sdk-trace-base';
import { ATTR_SERVICE_NAME } from '@opentelemetry/semantic-conventions'
const sdk = new NodeSDK({
resource: new Resource({
[ATTR_SERVICE_NAME]: 'publication-web',
}),
spanProcessor: new BatchSpanProcessor(
// new OTLPTraceExporter({ url: `http://${process.env.OTEL_EXPORTER_OTLP_ENDPOINT}/v1/traces` }),
new ConsoleSpanExporter(),
),
})
sdk.start()
Am I missing something? What should I do to make this work?
PS: I'm deploying this app in a docker container, so I don't use edge.
Answered by Havana
https://nextjs.org/docs/app/building-your-application/optimizing/instrumentation#importing-runtime-specific-code - this is the fix, I need to make sure I import the appropriate instrumentation based on environment
1 Reply
HavanaOP
https://nextjs.org/docs/app/building-your-application/optimizing/instrumentation#importing-runtime-specific-code - this is the fix, I need to make sure I import the appropriate instrumentation based on environment
Answer