opentelemetry-collector-dev-setup
opentelemetry-collector-dev-setup copied to clipboard
@vercel/otel Testing Strategy
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!
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
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 you are a god amongst men. THANKS! This has annoyed me for weeks!
@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