opentelemetry-collector-dev-setup icon indicating copy to clipboard operation
opentelemetry-collector-dev-setup copied to clipboard

@vercel/otel Testing Strategy

Open sgoodrow-zymergen opened this issue 1 year ago • 4 comments

Apologies if this is not the best place for this issue. I couldn't find the repo for @vercel/otel.

I attempted to instrument my app-router enabled NextJS project today and tried to test the instrumentation with this stack. I am fairly certain I followed the instructions correctly. The OTel instrumentation instructions indicate that this stack can be used to verify the instrumentation is sending data.

It is not clear how to use the stack to verify that. I ran the docker-compose and reviewed all logs of each pod, as well as their GUIs, and didn't see any response to running my app.

Are there environment variables that need to be set so that the app points at these collectors, or are the defaults correct?

Has anyone confirmed that this works lately?

Thanks!

sgoodrow-zymergen avatar Feb 16 '24 04:02 sgoodrow-zymergen

I found a fix which works for me in this comment: https://github.com/vercel/next.js/issues/61975#issuecomment-1943079675

import { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-http'
import { SimpleSpanProcessor } from '@opentelemetry/sdk-trace-node'
import { registerOTel } from '@vercel/otel'

export function register() {
  if (process.env.NEXT_RUNTIME === 'nodejs') {
    registerOTel({
      serviceName: 'next-app',
      spanProcessors: [new SimpleSpanProcessor(new OTLPTraceExporter())],
    })
  }
}

I can see the trace in the local Jaeger UI.

I had to wrap it in a process.env.NEXT_RUNTIME === 'nodejs', otherwise it threw an error. But this could be because I'm still von Next 13.5

timomeh avatar Feb 22 '24 14:02 timomeh

For anyone who has followed instructions from vercel and tried to run this, I spent hours testing and found out only @vercel/otel version ^0.3.0 will correctly send traces to this docker app. Every other version has not worked for me. I'm unsure why, but I hope this saves everyone else their time and sanity.

tansanDOTeth avatar Mar 13 '24 07:03 tansanDOTeth

@tansanDOTeth you are a god amongst men. THANKS! This has annoyed me for weeks!

Gawdfrey avatar Mar 20 '24 19:03 Gawdfrey

@tansanDOTeth you are a god amongst men. THANKS! This has annoyed me for weeks!

I also found a solution here: https://github.com/vercel/next.js/issues/61975#issuecomment-1993777573

tansanDOTeth avatar Mar 21 '24 02:03 tansanDOTeth