genkit icon indicating copy to clipboard operation
genkit copied to clipboard

[JS] Tracing missing "root" span for nextjs

Open i2amsam opened this issue 1 year ago • 0 comments

Describe the bug When prod traces are logged with autoInstrumentation=true some traces fail to be shown in the DevUI. The proximate cause is that traces are logged without a startTime attribute on the span. You will also see spans in GCP with "Missing span ID" errors. The start/end dates are missing for the same reason. We determined that turning off autoinstrumentation restores startTime, because the root span will be provided by Genkit in that case.

Upon further investigation, this appears to be attributed to Nextjs specific behavior. Sentry also encountered this issue: https://github.com/getsentry/sentry-javascript/issues/11046. Most likely Nextjs specific implementation details are required to resolve. Nextjs provides a "hook" (instrumentation.ts) for initializing OTel. See also: https://nextjs.org/docs/app/api-reference/file-conventions/instrumentation.

To Reproduce Steps to reproduce the behavior. Code samples.

Expected behavior All prod traces in the remote tracestore should be viewable in the DevUI

Screenshots Here's an example trace in Firestore without startTime

image

And in cloud trace (missing root span) image

Runtime (please complete the following information): NextJS app deployed to Firebase App Hosting

i2amsam avatar Jun 20 '24 13:06 i2amsam