Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to send logs from Vercel serverless functions (Next.js) to Google cloud Logs

From the Google cloud logging node sdk docs:

Serverless applications like Cloud Functions, Cloud Run, and App Engine are highly recommended to use the LogSync class as async logs may be dropped due to lack of CPU.

This is my implementation of google cloud logging with LogSync class

import { Logging } from "@google-cloud/logging";
const creds = {
  private_key:
    '---',
  client_email: "---",
};

const logging = new Logging({
  projectId,
  credentials: creds,
});

const log = logging.logSync(logName);

  const metadata = {
    resource: { type: "global" },
    severity,
    textPayload,
    jsonPayload,
  };

  const CombinedEntry = log.entry(metadata);


  log.alert(CombinedEntry);

I'm using this in next.js framework and deploying on Vercel (as serverless functions)

These logs are visible in the console (stdout) and Vercel functions dashboard but aren't visible on Google cloud logging.

Do I need to configure LogSync to mention that it should also send logs to google cloud logging? It's not mentioned in the docs. We also tried logging.log instead of logging.LogSync but still logs aren't visible on cloud but just on stdout.

like image 478
GorvGoyl Avatar asked Jan 22 '26 16:01

GorvGoyl


1 Answers

Here's my solution for getting Vercel logs into Cloud Logging https://github.com/kym6464/vercel-google-cloud-logging. It requires some manual configuration but it gets the job done.

like image 175
kym Avatar answered Jan 24 '26 15:01

kym



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!