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

Pino transport on NextJS cause Unknown worker assertion error #188

Open
bozzelliandrea opened this issue Sep 16, 2024 · 2 comments
Open

Comments

@bozzelliandrea
Copy link

bozzelliandrea commented Sep 16, 2024

Hi, I'm trying to send pino logs to grafana loki from a NextJS server side context, with pino-opentelemetry-transport I have this error:

Error [ERR_INTERNAL_ASSERTION]: Unknown worker message type message
This is caused by either a bug in Node.js or incorrect usage of Node.js internals.
Please open an issue with this stack trace at https://github.com/nodejs/node/issues

    at Function.fail (node:internal/assert:20:9)
    at [kOnMessage] (node:internal/worker:354:12)
    at MessagePort.<anonymous> (node:internal/worker:232:57)
    at _ZoneDelegate.invokeTask (webpack-internal:///(ssr)/../../node_modules/.pnpm/[email protected]/node_modules/zone.js/fesm2015/zone.js:406:31)
    at Zone.runTask (webpack-internal:///(ssr)/../../node_modules/.pnpm/[email protected]/node_modules/zone.js/fesm2015/zone.js:178:47)
    at ZoneTask.invokeTask [as invoke] (webpack-internal:///(ssr)/../../node_modules/.pnpm/[email protected]/node_modules/zone.js/fesm2015/zone.js:487:34)
    at invokeTask (webpack-internal:///(ssr)/../../node_modules/.pnpm/[email protected]/node_modules/zone.js/fesm2015/zone.js:1661:18)
    at globalCallback (webpack-internal:///(ssr)/../../node_modules/.pnpm/[email protected]/node_modules/zone.js/fesm2015/zone.js:1692:29)
    at MessagePort.globalZoneAwareCallback (webpack-internal:///(ssr)/../../node_modules/.pnpm/[email protected]/node_modules/zone.js/fesm2015/zone.js:1725:16)
    at [nodejs.internal.kHybridDispatch] (node:internal/event_target:820:20)
    at MessagePort.<anonymous> (node:internal/per_context/messageport:23:28)
    at MessagePort.callbackTrampoline (node:internal/async_hooks:130:17) {
  code: 'ERR_INTERNAL_ASSERTION'
}

About the code, this is my instrumentation config:

const OTEL_COLLECTOR_URL="http://localhost:4318";
diag.setLogger(new DiagConsoleLogger(), DiagLogLevel.DEBUG);

const sdk = new NodeSDK({
  serviceName: "next-node-instrumentation",
  textMapPropagator: new W3CTraceContextPropagator(),
  traceExporter: new OTLPTraceExporter({
    url: `${OTEL_COLLECTOR_URL}/v1/traces`
  }),
  
  instrumentations: [
    getNodeAutoInstrumentations(),
    new PinoInstrumentation({
        logHook: (span, record) => {
            console.log("RECEIVE FROM HOOK")
        }
    }),
  ],
  
  logRecordProcessors: [
    new logs.SimpleLogRecordProcessor(new logs.ConsoleLogRecordExporter()),
    new logs.SimpleLogRecordProcessor(
        new OTLPLogExporter({
            url: `${OTEL_COLLECTOR_URL}/v1/logs`,
        }),
  )],  
})
sdk.start()

and this is an example POST route where pino is used:

export async function POST(request: Request) {
 const { url } = await request.json();
 const transport = pino.transport({
   target: 'pino-opentelemetry-transport'
 })
 
 const log = pino(transport)
 log.info("HELLO FROM PINO");
}

env

OTEL_EXPORTER_OTLP_PROTOCOL=http
OTEL_EXPORTER_OTLP_LOGS_PROTOCOL=http

OTEL_EXPORTER_OTLP_ENDPOINT=http://localhost:4318
OTEL_EXPORTER_OTLP_LOGS_ENDPOINT=http://localhost:4318

node -v: 20.17.0
next: 14
pino: 9.4.0
pino-opentelemetry-transport: 1.0.1

Am I missing something inside the configuration?

@Vunovati
Copy link
Collaborator

Hello @bozzelliandrea, you should not create any logRecordProcessors when instantiating the SDK. pino-opentelemetry-transport will do that for you.

Try removing that first. If it does not work can you please create a simple way to reproduce this? I am not sure I'll be able to guess what your Next.js application looks like. If I can make it work I'd like to create an example of how to use the transport with Next.js.

@Starefossen
Copy link

Getting a ton of those in Next.js, without having any additional instrumentation config.

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

No branches or pull requests

3 participants