npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

auth0-logs-to-cloud-logging

v0.1.0

Published

A connector that fetches logs from Auth0 and uploads them to Google Cloud Logging

Downloads

1

Readme

Auth0 Logs to Cloud Logging

A simple script extracing Auth0 Logs and writing them to Google Cloud Logging. Auth0 stores logs for limited time, so it's recommended to store them in an external place. Currently there is no official extension for exporting logs to Google Cloud Logging.

Under the hood

To read logs this script uses LogsApiStream from auth0-extensions/auth0-log-extension-tools that are being used in official Auth0 extensions for extracting logs.

To write them back to Google Cloud Logging, official @google-cloud/logging node.js library is used.

How to use it?

It's as simple as:

import { connectLogs } from 'auth0-logs-to-cloud-logging'

connectLogs({ ...config, checkpointId: fetchCheckpoint() })
  .then((result) => storeCheckpoint(result.checkpointId))
  .catch((error) => console.log("Oh no!", error))

If you don't provide checkpointId while calling the function it will attempt fetching all your logs. In production environments this will most probably fail to fetch all of them, given Auth0 limits the number of API calls you can perform.

You need to write your own logic for storing and fetching checkpointId (fetchCheckpoint() and storeCheckpoint(id) in example above) to ensure that you're always fetching trying to fetch only logs that you actually need.

Configuration

Configuration object you have to provide to the function and their default values

{
  auth0: {
    domain: 'name.auth0.com', // requried, your Auth0 domain
    clientId: null,           // required, clientId for Auth0 machine-to-machine
                              // client with logs:read permission
    clientSecret: null        // required, clientSecret for the above client
  },
  google: {
    projectId: null,          // required, Google projectId under which logs
                              // will be stored
    logName: 'auth0-logs',    // name of the log in Cloud Logging

    location: 'Europe',       // location, namespace and nodeId are sent as metadata
    namespace: 'auth0',       // with every Cloud Logging entry, as per [documentation](https://cloud.google.com/monitoring/api/resources#tag_generic_node)
    nodeId: domain            // nodeId defaults to Auth0 domain
  },
  connector: {
    batchSize: 50,
    logger: null              // a logger object, if you want to see 
                              // debug messages (e.g. `console`)
    checkpointId: null        // id of last fetched log message
  }
}

For Cloud Logging this script expects to be run in the environment with access to service account with Log Writer permisssions (https://cloud.google.com/docs/authentication/getting-started)

Return value

The function returns a promise which resolves with following object when fetching of the logs from Auth0 ended. This can happen either because there is no more logs, or because the request limit has been reached.

resolve(object)

{
  startingCheckpointId: '...',  // ID of the starting checkpoint
  checkpointId: '...',          // string with ID of last fetched log entry
  logsProcessed: 0,             // number of log entries processed
  limits: {                     // returned from Auth0 library representing API limits
    limit: '50',
    remaining: '48',
    reset: '1585823889',
  }
}

reject(err)

Error object