Adding attributes to Log Events automatically - 7.1

Talend ESB Infrastructure Services Configuration Guide

EnrichVersion
7.1
EnrichProdName
Talend Data Fabric
Talend Data Services Platform
Talend ESB
Talend MDM Platform
Talend Open Studio for ESB
Talend Real-Time Big Data Platform
EnrichPlatform
Talend ESB
Talend Runtime
task
Design and Development
Installation and Upgrade

The Logging Framework supports the use of MDC properties to enrich log events with attributes like Subject and CorrelationID, as shown in a previous section. To automatically assign these attributes to their log event, you can optimize the Event Logging feature to extract the CorrelationID and Subject information from your SOAP messages with a CXF interceptor (if available), and directly set them as MCD properties. This way, all log messages within the service implementation would directly benefit from the enrichment of each log statement with Subject and CorrelationID, making it a lot easier for system administrators to correlate log messages.

To do so, the MDC mapper should be installed and configured in the Talend Runtime Container:

  1. Install the MDC mapper as follows:

    feature:install tesb-el-mdc-mapper

    All CXF web services within the same container will then automatically profit from this feature. No additional configuration for any web service is required.

  2. Make sure the MDC mapper comes with the following default configuration in the org.talend.eventlogging.mdc.cfg file:

    # MDC key value for CoorelationID
    mdc.correlationId = CorrelationID
    
    # MDC key value  for authenticated user name
    mdc.principle = Subject

    Currently, only two values can be extracted and mapped to MDC values:

    • A username taken from the SecurityContext (thus being independent from the authentication style)

    • CorrelationId taken from the message context (if available)

Once the MDC mapper installed and configured in the Talend Runtime Container:

  • The value defined for mdc.correlationId will be used as the MDC property key, in this case: CorrelationID.

  • The value defined for mdc.principle will be used to map the authenticated username to a MDC property with the key: Subject.

If both values are available within the message context, this feature will set two MDC properties for each log message (within the same context). For example:

{
   "eventUUID":  "9452dd3c-dbd3-47c0-a98e-398f89c9e78a",
   . . . 
    "customInfo": {
       "CorrelationID":  "someBusinessCorrelationId",
       "Subject":  "alice"
   }
}

In most cases, CorrelationID and Subject MDC properties will be defined within the agent configuration file to match the corresponding event log fields, and in that case, these values will not be stored as customInfo attributes, but as CorrelationID and Subject attributes like this:

{
   "eventUUID":  "9452dd3c-dbd3-47c0-a98e-398f89c9e78a",
    "correlationId":  "someBusinessCorrelationId",
   . . . 
    "subject":  "alice",
    "customInfo": {
   }
}