Welcome Corner Blog Posts
Go a little bit deeper into the Welcome Corner with blog posts. Learn how to get started in SAP Community and get tips on maximizing your participation.
cancel
Showing results for 
Search instead for 
Did you mean: 
shashankvimal99
Associate
Associate
277

Modern large scale integration architectures are powered by advance resurgence of observability, distributed tracing, and correlations.
The advancement in observability and analytics platform, provides confidence to extend the reach of integration and envision more on horizon.

The traceability improvement is not limited to the digital world.
The evolutionary spiral is expanding in the realms of supply chain operations, infobahn and data reservoirs.

With EPCIS(Electronic Product Code Information Services) upgrade to version 2.0, the business events, propagating downstream, upstream or in the reverse logistic channel- can be wrapped in json-ld/json file and can be upserted at each stage of the supply chain to the next.

Key EPC identifiers are GTIN, SGTIN(Combination of serial number and GTIN), GRAI(Global Returnable Asset Identifier) and SSCC(Serial Shipping Container Code).

The core idea of this blog is to use the physical EPC(Electronic Product Code) identifiers as W3C trace context identifiers such as traceparent and tracestate.
Each integrated (and OTEL observable) cloud/web application , in case forwards, these identifiers from one system to other, as part of HTTP headers then the organizations can establish strong correlation between physical supply chain events and digital system interactions. A major leverage point of these headers, would be the scenarios, where asynchronous request and response is used at larger scale for e.g. usage of SAP Event Mesh, JMS Queues etc.

For supply-chain leaders and digital-transformation executives, the multi-fold benefits are clear:
a unified, correlated view of physical events and digital flows, enabling deeper insights, quicker decisions, and more successful operations. From a different vantage point, the digital trails set by W3C trace context, reflects the recording of physical events by the digital systems as traceparent/tracestate, whenever the system digitally observes a product related event(specified by EPCIS jason-ld file) passing through it.

Following are few methods to set/derive the W3C trace context using epc ids:
- Set traceparent as hash of epc id.
- Set tracestate as epc id.
- Set trace-id field of traceparent as epc id(if epc id is a UUID).

Below you would find an http client snippet which performs the above suggested steps.  The snippet below is only for didactic purpose.

with open("epcis_payload.json", "r", encoding="utf-8") as file:
    payload = json.load(file)

#epcis file itself can carry traceparent as part of extension field; if present extract and set it 
traceParent = None
if 'extension' in payload:
    if 'traceContext' in payload['extension']:
        if 'traceparent' in payload['extension']['traceContext']:
            traceParent = payload['extension']['traceContext']['traceparent']

#Otherwise, hash the epc id and set traceparent with the obtained value post hashing             
if traceParent == None:            
    # Create deterministic 16 byte trace ID
    if 'epcList' in payload:
        traceId = hashlib.sha256(str(payload['epcList']).encode()).hexdigest()[:32]
    else:
        traceId = str(uuid.uuid4())[:32]
    span_uuid = uuid.uuid4()
    spanId = str(span_uuid)
    #traceparent = 00-<trace-id>-<span-id>-01
    traceParent = '00-' + traceId + '-' + spanId[:16] + '-01'

#Add traceparent as http header 
headers.update({"traceparent": traceParent})

#epcis file itself can carry tracestate as part of extension field; if present extract and set it
traceState = ""
if 'extension' in payload:
    if 'traceContext' in payload['extension']:
        if 'traceState' in payload['extension']['traceContext']:
            traceState = payload['extension']['traceContext']['traceState']

#Otherwise, set the tracestate as epc id           
if traceState == "":
        if 'epcList' in payload: 
            # Create tracestate from EPCIS Id
            traceState = 'epcList = ' + str(payload['epcList'])
        if 'inputEPCList' in payload:
            # Extend the tracestate
            if 'epcList' in traceState:
                traceState = traceState + ',' + 'inputEPCList = ' + str(payload['inputEPCList'])
            else:
                traceState = 'inputEPCList = ' + str(payload['inputEPCList'])
        if 'outputEPCList' in payload:
            traceState = traceState + ',' + 'outputEPCList = ' + str(payload['outputEPCList'])

#Add tracestate as http header 
headers.update({"tracestate": traceState})

#POST request
response = requests.post(url, auth=HTTPBasicAuth(username, password), headers=headers, json=payload)

The EPCIS json-ld/json file forwarder, can even send traceparent and tracestate(as part of extension field of the file) along with business event details.

In the Runtime Configuration of Integration Flow, set traceparent and tracestate as allowed headers (as shown below):

AllowedHeaders.png

One can even think of embedding the returned MPL ID (from SAP Integration Suite. as part of HTTP response), into tracestate for further transmission down the lane. Later, the predecessor MPL IDs and Integration Flows involved, in processing, the EPCIS json-Ld, can be determined as per explanation in following help documentation:
https://help.sap.com/docs/cloud-integration/sap-cloud-integration/using-ids-to-filter-messages?local...

An EPCIS event describes what, where, why, when and how about the business event. Taking an abstract look to overall above suggested scheme-  it would appear as if a new dimension is added to EPCIS event i.e. who(digitally viewed the event).


Now imagine that the integrated systems are streaming these message headers to data lake such as SAP Business Data Cloud or to a data federation system. This would then open a new portal to the world of federated tracing and large scale correlation. By indexing with traceparent, the correlated messages, in data lake and federation system, can be brought together.

Additionally, the W3C trace context headers can be stored as custom header properties, in message processing logs, in SAP Integration Suite. These settings can be achieved by (AI assisted) groovy scripting in SAP Integration Suite.

Below snippet reflects the extraction of traceparent and tracestate from the http header and setting the same as MPL's custom headers.

def messageLog = messageLogFactory.getMessageLog(message)
    
    if(messageLog != null) {
        messageLog.addAttachmentAsString(attachmentName, body, "text/plain")
    } 
    def traceid = message.getHeader("traceparent", String.class)
    messageLog.addCustomHeaderProperty("traceparent", traceid)
    
    def tracestate = message.getHeader("tracestate", String.class)
    messageLog.addCustomHeaderProperty("tracestate", tracestate)

One can then view these custom headers, in Message Monitor section of SAP Integration Suite, as shown below:

ViewTraceContext.png

 

The added custom attributes would be then visible, in SAP Cloud ALM as well, provided the respective SAP Integration Suite and  SAP Cloud ALM tenants are already dovetailed.

Harvest above insights and ideas and redefine the observability of supply chains !


References:
https://help.sap.com/docs/cloud-integration/sap-cloud-integration/message-processing-log-text-view?l...
https://help.sap.com/docs/cloud-alm/apis/raw-data-inbound-logs?locale=en-US

Top kudoed authors