Skip to content

Logging

Considering the different meetings and interviews with some technical leaders of the services, we were able to identify which were those fields that add value when it comes to monitoring the events generated by our services. With that knowledge, we created a standard based on OTeL Data Model, considering their base fields, but adapted to the specific needs of each team. For us it was very important in each meeting with the leaders, to identify which set of fields can provide a lot of information to generate business metrics that allow us to take action to positively impact the company and to generate alerts based on events reported by the services.

Structure

erDiagram
    BaseAttributes ||--o{ Frontend : attributes
    BaseAttributes ||--o{ Backend : attributes
    BaseAttributes ||--o{ Mobile : attributes
    BaseAttributes ||--o{ Job : attributes
    BaseAttributes ||--o{ Consumer : attributes
    BaseAttributes {
        string time
        string level
        string service
        string traceId
        string eventType
        string appVersion
        string msg
        string package
        string method
        string file
        object attributes
    }

    Frontend {
        string url
        int statusCode
        string httpMethod
        string duration
        string headers
        string userId
        string requestId
        object customAttributes
    }
    Backend {
        string url
        int statusCode
        string userAgent
        string host
        string httpMethod
        string duration
        string requestId
       strung xAppId
        object customAttributes
    }
    Mobile {
        string device
        string os
        string screenView
        string userId
        string ip
        object customAttributes
    }
    Job {
        string schedule
        string status
        string duration
        object customAttributes
    }
    Consumer {
        string status
        string duration
        object customAttributes
    }

Examples

{
    "time": "2023-06-29T10:30:00",
    "level": "info",
    "traceId": "abc123",
    "service": "frontend-service",
    "appVersion": "1.2.1",
    "eventType": "frontend",
    "msg": "Request received",
    "package": "com.example.frontend",
    "method": "handleRequest",
    "file": "FrontendController.java",
    "attributes": {
        "url": "/data/products?size=small",
        "statusCode": 200,
        "httpMethod": "GET",
        "duration": "0.5",
        "userId": "d81916c4-251e-11ee-232ardf",
        "requestId": "req456",
        "headers": {
            "Content-Type": "application/json",
            "Authorization": "Bearer token123"
        },
        "customAttributes": {
            "isMobile": true,
            "countryVisitor": "COL",
            "xAppId": "app456"
        }
    }
}
{
    "time": "2023-06-29T10:30:00",
    "level": "info",
    "traceId": "abc123",
    "service": "frontend-service",
    "eventType": "backend",
    "appVersion": "1.2.1",
    "msg": "Request received",
    "package": "com.example.frontend",
    "method": "handleRequest",
    "file": "FrontendController.java",
    "attributes": {
        "url": "/data/catalog",
        "statusCode": 200,
        "httpMethod": "GET",
        "duration": "0.5",
        "host": "esnumera.com",
        "requestId": "req456",
        "xAppId": "app456",
        "userAgent": "Mozilla",
        "customAttributes": {
            "protocol": "HTTP",
            "sqlQuery": "SELECT * FROM table1 LIMIT 1;"
        }
    }
}
{
    "time": "2023-06-29T10:30:00",
    "level": "info",
    "traceId": "abc123",
    "service": "frontend-service",
    "eventType": "mobile",
    "appVersion": "1.2.1",
    "msg": "Request received",
    "package": "com.example.frontend",
    "method": "handleRequest",
    "file": "FrontendController.java",
    "attributes": {
        "device": "Samsung",
        "os": "Android 9",
        "screenView": "home",
        "userId": "d81916c4-251e-11ee-232ardf",
        "ip": "33.118.93.249",
        "customAttributes": {
            "advisorId": "adv2324",
            "deviceId": "123wer23"
        }
    }
}
{
    "time": "2023-06-29T10:30:00",
    "level": "info",
    "traceId": "abc123",
    "service": "process-lead-job",
    "eventType": "job",
    "appVersion": "1.2.1",
    "msg": "Request received",
    "package": "com.example.frontend",
    "method": "handleRequest",
    "file": "FrontendController.java",
    "attributes": {
        "schedule": "1 0 * * *",
        "status": "success",
        "duration": "300",
        "customAttributes": {
            "userId": "d81916c4-251e-11ee-232ardf",
            "triggerJob": "service1"
        }
    }
}
{
    "time": "2023-06-29T10:30:00",
    "level": "info",
    "traceId": "abc123",
    "service": "frontend-service",
    "eventType": "consumer",
    "appVersion": "1.2.1",
    "msg": "Request received",
    "package": "com.example.frontend",
    "method": "handleRequest",
    "file": "FrontendController.java",
    "attributes": {
        "status": "processed",
        "duration": "60",
        "customAttributes": {
            "queueName": "products.fifo",
            "leadId": "lea123"
        }
    }
}

Attributes

Base attributes definition

Base attributes that all event types must have.

Note: - All properties of the customAttributes attribute must be camelCased. - Any sensitive information added in customAtributes must be encrypted, obfuscated or masked.

  • time: Time when the event occurred measured by the origin clock, i.e. the time at the source. Format ISO 8601 YYYY-MM-DDTHH:MM:SS (2007-11-03T24:12:03) UTC
  • level: This is the original string representation of the severity as it is known at the source (ref).

    • debug: A debugging event.
    • info: An informational event. Indicates that an event happened.
    • warning: A warning event. Not an error, but is likely more important than an informational event.
    • error : An error event. Something went wrong, the owner team must be notified.
    • emergency: Overall application or system failure that should be investigated immediately, DRI (Directly Responsible Individual) should be notified automatically. Alerts based on this event.
    • service: Name of the service that generates logs.
    • appVersion: Service version.
    • traceId: Set for logs that are part of event processing and have an assigned trace id related to other services.
    • package: Library of the code that generates the log.
    • method: Method or function of the code that generates the log.
    • file: File name of the code that generates the log.
    • msg: Message to be logged. It should be text.
    • eventType: Type of the resource that generates the log:
    • backend: Development that ensures that all the logical part of an app (ims-backend, seller, property-catalogue, etc).
    • frontend: Visible part of a website or application that users can interact with directly. Also the monolith (Sobreplanos, seller-frontend, ims-admin-frontend, etc).
    • job: Scheduled or event-driven jobs, which are responsible for completing specific tasks.
    • mobile: Mobile applications.
    • consumer: Services that are designed to consume events such as kafka, sqs or eventbridge.
    • attributes: Object type field grouping attributes based of eventType (backend, frontend, mobile, job and consumer).

Attributes based on eventType definition

Backend

  • url: Request path (without domain).
  • statusCode: An HTTP status code
  • userAgent: User agent attribute used at request.
  • host: Information of the server domain receiving the request.
  • httpMethod: HTTP methods allow you to communicate to the server what you want to do with a request under a URL: POST, GET, PUT, DELETE, PATCH, and HEAD.
  • duration: Time taken by the application to serve a particular event (in seconds).
  • requestId: Identifies the HTTP request sent from the app to the service and enables the app to correlate requests and responses.
  • xAppId: Identifier of the service from which the request originates.
  • customAttributes: Field to add additional IMPORTANT information, for example; attributes to identify a user or custom metadata like SQL query.

Frontend

  • url: Request path (without domain).
  • statusCode: An HTTP status code.
  • ip: ip address sending the request.
  • httpMethod: HTTP methods allow you to communicate to the server what you want to do with a request under a URL: POST, GET, PUT, DELETE, PATCH, and HEAD.
  • duration: Time taken by the application to serve a particular event (in seconds).
  • headers: Shares additional information between the clients and the server through the request and response header.
  • userId: A unique customer identifier user visiting our website (email or anonymous).
  • requestId: Identifies the HTTP request sent from the app to the service and enables the app to correlate requests and responses.
  • customAttributes: Field to add additional IMPORTANT information, for example; attributes to identify a user or custom metadata like SQL query.

Mobile

  • device: Description of the device used by the customer.
  • os: Operating system used by customers.
  • screenView: Screen that generates the log report.
  • userId: A unique customer identifier (final client) user visiting our website (email or anonymous).
  • ip: Ip address sending the request.
  • customAttributes: Field to add additional IMPORTANT information, for example; attributes to identify a user, advisor ID, or HTTP response.

Job

  • schedule: Execution schedule (cron expression or null).
  • status: Status definition: success, skipped, or failed.
  • duration: Time taken by the application to process a particular event (in seconds).
  • customAttributes: Field to add additional IMPORTANT information, for example; attributes to identify a user or custom metadata like SQL query.

Consumer

  • status: Status definition: processed, queued, failed.
  • duration: Time taken by the application to process a particular event (in seconds).
  • customAttributes: Field to add additional IMPORTANT information, for example; attributes to identify a user or custom metadata like SQL query.