@bonniernews/gcp-trace-logging-correlator
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

gcp-trace-logging-correlator

Helps you correlate both request and application logs in an app running on GCP. You can read more about log correlation in GCP here https://cloud.google.com/run/docs/logging#correlate-logs

Installation

npm install @bonniernews/gcp-trace-logging-correlator

Usage

This package comes with an express middleware and a function that extracts the trace as an object that should be injected into your logs.

Install the middleware somewhere globally in your app. You have to provide the GCP project ID meaning you probably want to set this up with an environment variable.

import { middleware } from "@bonniernews/gcp-trace-logging-correlator";

// ...

app.use(middleware(config.get("gcp_project_id")));

You should then provide the object returned by the function getTraceObject to your logging library. If you're using pino, you should pass it to a mixin like this

import { getTraceObject } from "@bonniernews/gcp-trace-logging-correlator";

const logger = pino({
  // ...
  mixin = () => ({
    somethingElse: "foo",
    ...getTraceObject(),
  });
});

Package Sidebar

Install

npm i @bonniernews/gcp-trace-logging-correlator

Weekly Downloads

384

Version

1.0.0

License

ISC

Unpacked Size

7.24 kB

Total Files

8

Last publish

Collaborators

  • daghall
  • andreas.samuelsson
  • norla
  • mattiasobn
  • chrissode
  • jzachrisson
  • hilleso
  • adam.hakansson
  • amundsentb
  • jonaek
  • drgeobn
  • mikael.mattsson
  • morre
  • takolander
  • vitryssen
  • herbola
  • nifo
  • johark
  • aliceboberg
  • varneynz
  • gusliden
  • mxtr
  • karlbergc
  • martindanielson
  • joelekman
  • chavah
  • matsrorbecker
  • axeljohanssonbonniernews
  • markusn
  • linuss
  • joelabrahamsson
  • jonaswalden
  • indeedshouts
  • marcusgronblad