Logflare/pino-logflare

Error: Request failed with status code 406

uatuko opened this issue · 10 comments

I seem to be getting a 406 when I tried to use it as described in the API docs.

Error: Request failed with status code 406
    at createError (/path/to/code/node_modules/axios/lib/core/createError.js:16:15)
    at settle (/path/to/code/node_modules/axios/lib/core/settle.js:17:12)
    at IncomingMessage.handleStreamEnd (/path/to/code/node_modules/axios/lib/adapters/http.js:236:11)
    at IncomingMessage.emit (events.js:323:22)
    at IncomingMessage.EventEmitter.emit (domain.js:505:15)
    at endReadableNT (_stream_readable.js:1204:12)
    at processTicksAndRejections (internal/process/task_queues.js:84:21)

+1 also encountered this issue

Hey! Sorry not sure why I didn't get alerted here.

This is probably because you're trying to log an object with keys that have characters not compatible with BigQuery. Specifically, a column name must contain only letters (a-z, A-Z), numbers (0-9), or underscores (_), and it must start with a letter or underscore. We turn every object key into a BigQuery column for you automatically.

Alrighty I see some things are much more confusing than they should be ... I will update here in a bit ... but you also might be missing the log message if you're just trying to log data.

We will output the Logflare API response body to the console in the case of non 2xx response codes. This will be much more informative.

Couple things to note... make sure you're on the 0.1.0 release and using the config keys for that release. They will be changing in 0.2.0.

Make sure you're using a log message when logging structured data. e.g. (logger.info(data, "Log message"). This is also getting updated in 0.2.0 where a log message won't be required.

And again, make sure you're sending over events that adhere to the BigQuery column name specs.

Hello, just to add up to the issue, just with a simple test :

{
  ...
  "pino": "^6.3.2",
  "pino-logflare": "^0.1.0",
  ...
}
import pino from 'pino';
import logflare from 'pino-logflare';

const stream = logflare.createWriteStream({
  apiKey: '...',
  sourceToken: '...',
});

const logger = pino({}, stream);

logger.info({ foo: 'bar' }, 'Log message');

I still get :

The previous log(s) were not saved
Request failed with status code 406
Error: Request failed with status code 406
    at createError (/Users/me/Projects/test-pino/node_modules/axios/lib/core/createError.js:16:15)
    at settle (/Users/me/Projects/test-pino/node_modules/axios/lib/core/settle.js:17:12)
    at IncomingMessage.handleStreamEnd (/Users/me/Projects/test-pino/node_modules/axios/lib/adapters/http.js:236:11)
    at IncomingMessage.emit (events.js:322:22)
    at endReadableNT (_stream_readable.js:1187:12)
    at processTicksAndRejections (internal/process/task_queues.js:84:21)

I mean, { foo: 'bar' } is adhering to the specs right ? 😮

Yeah sorry you need the config keys from 0.1.0: https://github.com/Logflare/pino-logflare/blob/v0.1.0/docs/API.md

sourceToken should be source

Lots of improvements and conveniences will be released probably next week.

Oh ok perfect !
Also, do you know how to wait for the log event to be sent ? We are using Vercel's Now but each push doesn't have time to be sent, I had to wrap res.send in a setTimeout just to understand why it wasn't working :)

Thank you !

Yeah that's a problem with lambda in general. I'm in the middle of writing up a guide for Vercel / Pino / Logflare to go through all this actually. Last week we significantly improved our Vercel log parser so it supports multiple log lines with JSON data. So you should be able to use our Vercel integration directly with Pino (not with pino-logflare) to log JSON data to stdout which would then get picked up and parsed by the Logflare integration. The only problem with this is that you only get 4kb of data in the lambdaMessage before it gets truncated because that's all the lambda gives you.

I guess you answered everything for me ! Thank you @chasers, for this package & Logflare, I'm eager to see the new changes soon ! ;)

Have a nice day

Alrighty new version is published! Please review >> https://github.com/Logflare/pino-logflare/releases/tag/v0.3.1

Note if you're using Vercel we have an example of a Next project that uses the Logflare Vercel integration where server side logs go to stdout so they get processed by Vercel's logging infra and then go to Logflare while the browser logs get sent to Logflare via http. All of this with an easy setup. I think this is the best way to setup logging with an isomorphic Vercel project.

You still need to be conscious of your data payloads as we're not handling that stuff automatically yet, although we would like to.