Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@janiscommerce/log

Package Overview
Dependencies
Maintainers
1
Versions
40
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@janiscommerce/log

A package for creating logs in Firehose

  • 3.3.0-tnd.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
587
increased by16.7%
Maintainers
1
Weekly downloads
 
Created
Source

log

Build Status Coverage Status

A package for creating logs in Firehose

Installation

npm install @janiscommerce/log

Configuration

ENV variables

JANIS_SERVICE_NAME (required): The name of the service that will create the log. JANIS_ENV (required): The stage name that will used as prefix for trace firehose delivery stream. TRACE_FIREHOSE_DELIVERY_STREAM (required): The trace firehose delivery stream name. LOG_ROLE_ARN (required): The ARN to assume the trace role in order to put records in Firehose.

API

add(clientCode, logs)

Parameters: clientCode [String], logs [Object] or [Object array] Puts the recieved log or logs into the janis-trace-firehose

Log structure

The log [Object] parameter have the following structure:

  • id [String] (optional): The ID of the log in UUID V4 format. Default will be auto-generated.
  • service [String] (optional): The service name, if this field not exists, will be obtained from the ENV (JANIS_SERVICE_NAME)
  • type [String] (required): The log type
  • entity [String] (required): The name of the entity that is creating the log
  • entityId [String] (optional): The ID of the entity that is creating the log
  • message [String] (optional): A general message about the log
  • log [Object|Array] (optional): This property is a JSON that includes all the technical data about your log.

Log example

{
  id: '0acefd5e-cb90-4531-b27a-e4d236f07539',
  type: 'new',
  entity: 'api',
  entity_id: 'log',
  service: 'trace',
  message: '[GET] Request from 12.345.67.89 to /log',
  date_created: 1559103066,
  log: {
    verb: 'GET',
    headers: {
      'x-forwarded-for': '12.345.67.89',
      'x-forwarded-proto': 'https',
      'x-forwarded-port': '443'
    },
    responseHttpCode: 200
  }
}

on(event, callback)

Parameters: event [String], callback [Function] Calls a callback when the specified event is emitted.

Errors

The errors are informed with a LogError. This object has a code that can be useful for a correct error handling. The codes are the following:

CodeDescription
1Invalid log
2Firehose Error
3Unknown stage name
  • In case of error while sending your logs to Firehose, this package will emit an event called create-error, you can handle it using the on() method.

Usage

const Log = require('@janiscommerce/log');

// Single log send
await Log.add('some-client', {
    service: "oms",
    entity: "api",
    entityId: "order",
    type: "api-request",
    dateCreated: "2020-04-21T17:16:01.324Z",
    log: {
        api: {
            endpoint: "order/5ea1c7f48efca3c21654d4a3/pick-items",
            httpMethod: "post"
        },
        request: {
            headers: {
                accept: "application/json",
                "content-type": "application/json",
                Host: "oms.host.com",
                "janis-client": "some-client",
                "X-Amzn-Trace-Id": "Root=1-fca3c2-5ea1c7f48efca3c21654d4a3",
                "X-Forwarded-For": "12.354.67.890",
                "X-Forwarded-Port": "123",
                "X-Forwarded-Proto": "https"
            },
            data: {
                0: {
                    pickedQuantity: 1,
                    pickingSessionId: "5ea1c88463d91e9758f2c1b8",
                    pickerId: "5ea1c8895ebb38d472ccd8c3",
                    id: "5EA1C88D6E94BC19F7FC1612",
                    pickedEans: [
                        "1234567890"
                    ]
                }
            }
        },
        response: {
            code: 200,
            headers: {},
            body: {}
        },
        executionTime: 868.251946
    }
}
});

// Multiple logs send
await Log.add('some-client', [
  {
    service: "catalog",
    entity: "account",
    entityId: "5ea1c8c53fdac68fb60eac9e",
    type: "upserted",
    dateCreated: "2020-04-22T22:03:50.507Z",
    log: {
      id: "5ea1c8c53fdac68fb60eac9e",
      referenceId: "rv-000005"
    }
  },
  {
    service: "catalog",
    entity: "account",
    entityId: "5ea1c8cd11f82560a364cbd4",
    type: "upserted",
    dateCreated: "2020-04-22T22:03:50.507Z",
    log: {
      id: "5ea1c8cd11f82560a364cbd4",
      referenceId: "rf-00752"
    }
  }
]);

Log.on('create-error', (log, err) => {
	console.error(`An error occurred while creating the log ${err.message}`);
});

FAQs

Package last updated on 09 Jan 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc