I think the observability insights in the logs are pretty cool, but our application is getting the data in RSCs 99% from db queries and not from fetches. Having a similar UI with query duration for queries would be great.
Is there an Observability API that I can use to add traces?
Thanks
Vercel Alum
Hi, Bernd!
Yes, you can add custom traces for your database queries using Vercel's OpenTelemetry integration.
Vercel's Observability platform supports custom instrumentation through OpenTelemetry, which allows you to add traces for your database queries similar to how fetch requests are automatically traced.
Here's how you can get started:
First, install the OpenTelemetry packages:
npminstall @vercel/otel
You can use it to create spans for your database queries:
import{ trace }from'@vercel/otel';
asyncfunctionfetchDataFromDB(){
return trace.span('db.query',async(span)=>{
// Add details about your query
span.setAttribute('db.system','postgresql');// or whatever DB you use
span.setAttribute('db.statement','SELECT * FROM users');
// Your actual database query
const result =await db.query('SELECT * FROM users');
Thanks. After reading the docs it was not apparent that OTEL traces will show up in the monitoring logs.
Hi ,
We are now an Observability customer.
First of all. Your example is not working. You have posted a made up API method.
After digging through the docs I've added
registerOTel({ serviceName: "app-frontend" }); to instrumentation.ts
and then added spans for my db calls.
import { trace } from "@opentelemetry/api";
I cannot submit the rest of my post because I get this error:
Long story short: The span is not showing up in the Vercel logs. Please provide some link to documentation or code from an actual API that can be used to track performance of custom code to show up in the log details. I'm not interested to send spans to New Relic or Datadog.
Hi can I expect a response?
Vercel Alum
Hi, Bernd!
I actually asked your question in yesterday's live session: