View costs with faunadb-js


Using the faunadb-js client, errors will return the billing related x-headers in the response, but this is not available for the successful responses although suggests that it might be available if not for all, then for some of the operations.

Is there an option or some other way to expose the headers for successful returns so that we can view or log op costs? This would be helpful as the Dashboard data is not live.



this is currently only exposed via an observer functions.

var faunadb = require('./index')
var q = faunadb.query
function account (res) {
  if (!res || !res.responseHeaders) return
  h = res.responseHeaders
var client = new faunadb.Client({
  secret: 'secret',
  domain: 'localhost',
  port: 8443,
  scheme: 'http',
  observer: account

The idea to not put them directly in the query results was to simplify that result for early users.
Granted, using an observer is a bit cumbersome though especially if you want to link these headers back to the original query (that feedback is already delivered to the drivers team, in the future we’ll probably improve this).


Thanks. For my current purpose I just want to be able to get an idea of execution costs of a new project so as long as it logs in order that’s pretty much all I need at the moment, but it would be helpful to be able to have a way to link back to the original query as you say in the event I want to push that out for analytics/reporting purposes down the track. Even if the query function took an additional callback parameter for the original response/error or headers, that would be really useful.


1 Like

Very helpful! Thanks for including this. Heads up that the h in the example is not instantiated. Needs a var before it to run successfully.