aura-logging utility

aura-logging utility is used for controlling login in Aura

Introduction

aura-logging utility is a custom login tool across every Aura apps intended to prevent possible errors in execution time or unspecified login format.

Find more information in the Github repository: https://github.com/Telefonica/aura-utilities/tree/master/packages/aura-logging

The current logging format, including different fields and logging levels to be used across Aura components, is included in the Aura logging common format section.

emit function has been deprecated, please use logging method in future implementations:

jest.spyOn(AuraLog.prototype, 'logging').mockImplementation();

Use aura-logging utility

Basic usage

import { AuraLogger } from '@telefonica/aura-logging';

const logger: AuraLog = new AuraLog('new-component');

logger.debug(msg: 'ok');

Configuration

Set level and format

import { AuraLogger } from '@telefonica/aura-logging';

AuraLogger.setLevel('DEBUG');
AuraLogger.setFormat('json');

Set default fields on each log

import { AuraLogger } from '@telefonica/aura-logging';

AuraLogger.defaultFields({version: '1.2.3', app: 'randomApp'});

Everything else should be managed by the dependency.

aura-logging format

The current section describes the process for writing operational logs by Aura components and the defined fields and levels.

  • File format: JSON
    • If possible, each input in a log file might be a plain JSON object
  • What should be logged in each level:
    • DEBUG LEVEL:
      • in/out of each step in a server
      • Incoming requests in a server
      • DB access
      • Health-check requests
      • Any other thing interesting for the developer
    • INFO LEVEL:
      • Outgoing responses in a server
      • Calls to external APIs (see HTTP requests below)
      • Message pushed to queues
      • Bot: NLP resolution
      • Bot: after user authentication, logs user’s data
    • WARN LEVEL:
      • A non blocking error or special situation in the current request
    • ERROR:
      • Outgoing error responses in a server
      • Error responses from external APIs (see HTTP requests below)
    • FATAL:
      • If server is closed

Fields names

  • Fields marked in bold are mandatory
  • Fields marked in italics are optional

Common

All logs in the system must count on the following list of fields:

Field Type Format Description
time string YYYY-mm-DDTHH:MM:SS.MSSZ ISO 8601 UTC time
corr string UUID Cross component request identifier
msg string List of messages Description of the operation
lvl string Valid log level One of DEBUG, INFO, WARN, ERROR, FATAL
host string string POD where the container is running
version string X.Y.Z Version of the component writing the log
module string string Class/module identifier within the component writing the log

All logs in the system could count with the following field:

Field Type Format Description
app string string Application name

Specific cases

Outgoing server response (INFO and ERROR)
Field Type Format Description
drt integer number Request duration in milliseconds
status integer HTTP status code Valid HTTP status code
path string string
  • HTTP servers: endpoint path
  • aura-bot: library resolving the request
method string HTTP method name HTTP method called (in case of HTTP servers)

Examples

  • Successful response
{
    "time": "2019-04-05T11:51:09.325Z",
    "lvl": "INFO",
    "corr": "9c83c5d8-f3b5-4074-b475-28e2f528dd50",
    "userId": "123456677890",
    "auraId": "9c83c5d8-f3b5-4074-b475-28e2f528dd50",
    "auraIdGlobal ": "12344556778900 asdf3455",
    "channelId ": "f110f872-5d99-4839-b950-452847f1e59a",
    "version ": "8.2.1",
    "module ": "aura-users-controller",
    "msg ": "Get user by auraid",
    "drt ": 45,
    "status": 200,
    "path": "/users/123456677890",
    "method": "GET"
}
  • Error response
{
    "time": "2019-04-05T11:51:09.325Z",
    "lvl": "ERROR",
    "corr": "9c83c5d8-f3b5-4074-b475-28e2f528dd50",
    "userId": "123456677890",
    "auraId": "9c83c5d8-f3b5-4074-b475-28e2f528dd50",
    "auraIdGlobal ": "12344556778900 asdf3455",
    "channelId ": "f110f872-5d99-4839-b950-452847f1e59a",
    "version ": "8.2.1",
    "module ": "aura-users-controller",
    "msg ": "AuraId does not exist",
    "drt ": 45,
    "status": 404,
    "path": "/users/123456677890",
    "method": "GET"
}
Error cases
Field Type Format Description
error string error.message Exact error message returned by the failed request/module
stck string stack trace of the error Only in DEBUG for expected errors. In ERROR for unexpected
HTTP requests and responses

This type is used both at the request and at the response. At the response it has more fields.

Field Type Format Description
method string HTTP method name Name of the HTTP method
domain string FQDN Domain name called with this request
path string /*/* Path called by the request, including params
reqParams string csv key:value Only for DEBUG logs. Array of request params:
  • headers, except: Authorization, x-token-info,
  • query and body params, except: jwt, code, sastoken
status string HTTP status code Valid HTTP status code. Only response
drt integer number Total duration of the request processing in milliseconds. Only response.
body string string / json Only for DEBUG logs. Complete response.body
origin string comma separated string From header X-Real-IP or remoteAddress field from express request

Examples

  • Request
 {
     "time": "2019-04-05T11:51:09.325Z",
    "lvl": "INFO",
    "module": "aura-http-monkey-patcher",
    "domain": "localhost",
    "method": "POST",
    "path": "/deployments/deployment_bot_gpt-35-turbo/chat/completions?",
    "corr": "no-correlator",
    "version": "8.5.0",
    "app": "aura-gateway-api",
    "host": "mac-XQM577TDV0"
}
  • Successful response
{
    "time": "2019-04-05T11:51:09.325Z",
    "lvl": "INFO",
    "corr": "9c83c5d8-f3b5-4074-b475-28e2f528dd50",
    "method": "GET",
    "domain": "api.global-int.baikalplatform.com",
    "path": "/userprofile/v3/users/123456677890",
    "version ": "8.2.1",
    "module ": "subscriptions-service",
    "msg ": "User profile retrieved",
    "origin": "10.0.0.1",
    "drt ": 45,
    "status": 200
}
  • Error response
{
    "time": "2019-04-05T11:51:09.325Z",
    "lvl": "INFO",
    "corr": "9c83c5d8-f3b5-4074-b475-28e2f528dd50",
    "method": "GET",
    "domain": "api.global-int.baikalplatform.com",
    "path": "/userprofile/v3/users/123456677890",
    "version ": "8.2.1",
    "module ": "subscriptions-service",
    "msg ": "User profile cannot be retrieved",
    "origin": "10.0.0.1",
    "drt ": 45,
    "status": 403,
    "error": "{\"code\":\"PERMISSION_DENIED\",\"message\":\"Client does not have sufficient permission\"}"
}
Aura Bot

In aura-bot, the outgoing response message of the server should include these fields:

Field Type Format Description
conversationId string string Identifier of the conversation in DL
fromId string string Identifier of the user in the channel
replyToId string string Identifier of the message being answered
type string string Type of the activity, in this version only message
locale string 2 letters: lang-country ISO culture code: en-gb, es-es, etc.
Aura NLP

In Aura NLP, the outgoing response message of the server should include these fields:

Field Type Format Description
intent string intent.{name} or None Intent resolved by Aura NLP server
domain string string Domain to which the detected intent belongs
accuracy float Four decimals number, [0, 1] Probability of returning the correct intent

Logging levels and usages

Level Description
DEBUG Log extra info and steps, for development purposes.
INFO To follow the request with the most important steps and information
WARN A non blocking error or special situation in the current request
ERROR A blocking error in the current request
FATAL A blocking error that avoids the normal behavior of the server, so it would be stopped.

Correlator policy

The correlator property in the log traces (corr) is mandatory in all levels but DEBUG, even though it is also highly recommended in that level.

We can use a correlator passed by in the original request (from other component), and we will use the same correlator in requests to other components (that allows them) in order to keep a cross-component correlator (the same correlator is used in the all the request-response flow, involving several APIs/servers/components).

If the correlator is not passed by the component creating the request, a new random correlator is generated at the beginning of the flow and is used from then on (even in requests to other components).

The correlator is used to relate all operations done in a request-response flow, that is all things done from the moment when the user starts the request untilaura-bot sends the last response (all operations logged must have the same corr).

There are a couple of exceptions to the last rule, as we are not able to get a correlator in all cases (some of them within a request-response flow, others outside it). Some special values are defined to know in which case the log trace is:

corr Description
<uuid> Normal case. The same correlator is used in all the request-response flow (passed in the original request, or random generated at the beginning).
no-correlator The log trace does not have a correlator because it cannot have one (i.e., by technical limitations, such as HTTP request triggered by an event).
aura-system The log trace is outside a request-response flow (such as server starting, server stopping, etc.)
null|undefined These values are not permitted and are always considered a bug.

⚠️ Note: Do not abuse of the use of no-correlator, when the developer is lazy enough to get the current request-response correlator, and prefers to set no-correlator to avoid the bug detection when null or undefined. no-correlator means that it is impossible to get the correlator.

Standard logs

The log id must be:

  • The name of the class, if we are writing a class:
// to class AuraBridgeFlow
const logger: AuraLog = new AuraLog('aura-bridge-flow');
  • The name of the file, if we are writing an utility file:
// to dialog whatsapp-utilities file
const logger: AuraLog = new AuraLog('whatsapp-utilities');
  • The dialog identifier if we are writing a dialog:
// to dialog DisambiguationDialog
const logger: AuraLog = new AuraLog(DisambiguationDialog.id);

Define the log outside the class to avoid attacks:

const logger: AuraLog = new AuraLog('aura-bridge-flow');

export class AuraBridgeFlow {
    ...
}

In the dialogs, it is convenient to use this standard: [${Dialog.id} dialog]

logger.debug({ msg: `[${DisambiguationDialog.id} dialog] Started`, corr });

You can include an object as a string key to get more information about the case. In this scenario, avoid including very large objects to precent blocking the pods due to logs writing.

logger.info({ msg: 'Try to upload and validate attachments', fromId: from, auraId: auraUser.auraId, corr });
Last modified May 18, 2026: Remove KGB (52b04d91)