Provides functionalities for handling SAP Passports

Downloads in past


3.2.05 months ago3 years agoMinified + gzip package size for @sap/e2e-trace in KB


Node.js package with end to end tracing capabilities.


SAP Passport

SAP Passports allow to identify a specific request in an end-to-end scenario involving several components communicating with each other. This is especially helpful in the task of following the state of a business transaction across different systems. To achieve that, the client should send a special header ('sap-passport') containing the SAP Passport to the first component. The SAP Passport is a hex string with a special structure. The client can send one via a browser plugin or via SAPUI5 application frontend. Whenever an SAP Passport comes into a component, this component should also include the unique identifiers of the SAP Passport in its logs/traces, update it with component specific data and then forward it to the next system.
See the diagram below:
SAP Passport overview diagram
An application receives an SAP Passport in the 'sap-passport' header. The same header is used when the SAP Passport is getting forwarded over the HTTP protocol to another system. If it is being sent to HANA, the SAP Passport should be set as the 'SAPPASSPORT' session variable of the database connection.


  • Loading the package:

var SAPPassport = require('@sap/e2e-trace').Passport;

  • Creating an SAP Passport instance

function requestHandler(req, res) {
  var encodedPassport = req.headers[SAPPassport.HEADER_NAME];
  if (encodedPassport) {
    var passport = new SAPPassport(encodedPassport);

The library provides a constant for the 'sap-passport' header: SAPPassport.HEADER_NAME.
The passport variable is an instance with which you may read/modify the SAP Passport in your component.
  • Reading the unique identifiers of an SAP Passport

var identifiers = passport.readUniqueIdentifiers();

The returned value (assigned to the identifiers variable) is an object that has the following properties: transactionID, rootContextID, connectionID, connectionCounter. These SAP Passport fields got to be present in the logs/traces of the component. If you are using the sap-logging library, refer to its documentation to check whether the specific version is capable of handling SAP Passports or not.
  • Updating the SAP Passport - this is done right before forwarding it to the next component.

  previousComponent: 'my-application',
  connectionID: '00112233445566778899AABBCCDDEEFF',
  connectionCounter: 36

This method takes an object with the following properties:
Property | Value | Mandatory | Semantics ------------- | ---------- | --------- | -------------------------- previousComponent | ASCII string. Up to 32 characters. | | This is the name of the current component which is about to make an outbound connection to another component. Defaults to
XSA Node.js. connectionID | GUID, 16-byte hex | yes | Every connection between the current component and the next component should have an ID which is passed as that property. connectionCounter| Positive integer, up to 4 bytes | yes | States for which time the connection with the given connectionID is being reused.
  • Compacting the SAP Passport - HANA DB has a limitation over the SAP Passport size.
This is why it is recommended to call the method compact before forwarding an SAP Passport to HANA.

  • Generating a hex string out of the updated SAP Passport - the SAP Passport can be send to other components in this format.

var http = require('http');
var url = require('url');

var encodedPassport = passport.serialize();

var options = url.parse('http://my-host:1234/my/path');
options.headers = {};
options.headers[SAPPassport.HEADER_NAME] = encodedPassport;

var request = http.request(options);
request.on('error', function (err) { /* ... */ });
request.on('response', function (response) { /* ... */ });

DSR records

Distributed Statistics Records contain statistical information regarding an incoming request. The library writes every record on the standard output in a JSON format. Gathering DSR statistics is triggered when a request containing an SAP passport is received.


var connect = require('connect');
var createDsrMiddleware = require('@sap/e2e-trace').createDsrMiddleware;

var app = connect();

app.use('/path', function (req, res, next) {
  // ...

The DSR middleware (can be used with frameworks like connect and express) should be the first middleware in the request processing flow.
Example DSR record:

Properties in a DSR record:
Property | Description ------------- | ----------- startTime | Time at which request processing starts (milliseconds elapsed since 1 January 1970 00:00:00 UTC). action | The requested URL. receivedBytes | Number of bytes the incoming HTTP request contains (lengths of request line, headers section and body included). Note: due to a bug in Node.js, this field might be 0 in some runtime versions. Refer to the engines/node property in
package.json for recommended Node.js versions. sentBytes | Number of bytes the outgoing HTTP response contains (lengths of status line, headers section and body included). respTime | Number of milliseconds spent in request processing (until the whole outgoing HTTP response has been handed off to the operating system for transmission over the network). transId | The Transaction ID field of the SAP Passport that has triggered the DSR record. userId | User ID of the current user taken from the request object. Defaults to n.a..