noop(); pop(); map();

    @pokutuna/requestlog-cloudfunctions
    TypeScript icon, indicating that this package has built-in type declarations

    0.0.3 • Public • Published

    @pokutuna/requestlog-cloudfunctions

    Actions Status npm (scoped)

    A middleware to write an httpRequest log with trace field on Cloud Functions.

    This makes it possible to group your application logs in an HTTP request.

    log-grouping

    Usage

    import express = require("express");
    import { logHttpRequest } from "@pokutuna/requestlog-cloudfunctions";
    
    const projectId = "<YOUR_PROJECT_ID>";
    const logId = "request_log";
    
    const app = express();
    app.use(logHttpRequest({ projectId, logId }));
    ...

    Options

    • projectId
      • default: process.env.GCLOUD_PROJECT
      • You must give projectId on nodejs10 runtime which doesn't provide GCLOUD_PROJECT environment variable.
    • logId
      • default: "request_log"
      • Logs are written to logName projects/{projectId}/logs/{logId} on Stackdriver Logging

    Writing logs

    • (Recommend) use @google-cloud/logging-winston or @google-cloud/logging-bunyan
    • Or write the trace field by yourself.
      • The X-Cloud-Trace-Context request header contains ${traceId}/${spanId}
      • Write trace field with projects/${projectId}/traces/${traceId} in metadata of a entry using the client library @google-cloud/logging.
      const { Logging } = require("@google-cloud/logging");
      
      const projectId = "<YOUR_PROJECT_ID>";
      const logging = new Logging({ projectId });
      const log = logging.log("application_log");
      
      exports.app = (req, res) => {
        const [traceId] = req.header("X-Cloud-Trace-Context").split("/");
        const trace = `projects/${projectId}/traces/${traceId}`;
      
        // log.entry(metadata, data)
        const entry = log.entry(
          { trace },
          { message: "this is a message", obj: { key: "value" } }
        );
        await log.write(entry);
      };

    Keywords

    none

    Install

    npm i @pokutuna/requestlog-cloudfunctions

    DownloadsWeekly Downloads

    0

    Version

    0.0.3

    License

    Apache-2.0

    Unpacked Size

    20.7 kB

    Total Files

    9

    Last publish

    Collaborators

    • pokutuna