Product
Introducing License Enforcement in Socket
Ensure open-source compliance with Socket’s License Enforcement Beta. Set up your License Policy and secure your software!
@sap/e2e-trace
Advanced tools
Node.js package with end to end tracing capabilities.
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:
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 'SAP_PASSPORT' session variable of the database connection.
var SAPPassport = require('@sap/e2e-trace').Passport;
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.
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.
passport.update({
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. |
compact
before forwarding an SAP Passport to HANA.passport.compact();
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) { /* ... */ });
request.end();
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(createDsrMiddleware());
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:
{"action":"https://host:5555/path?a=1&b=2","receivedBytes":1230,"sentBytes":110,"respTime":18,"transId":"104A7DB661D31EE69DE912281546ED81","userId":"n.a.","startTime":1473506434377}
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. . |
FAQs
Provides functionalities for handling SAP Passports
The npm package @sap/e2e-trace receives a total of 40,806 weekly downloads. As such, @sap/e2e-trace popularity was classified as popular.
We found that @sap/e2e-trace demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Ensure open-source compliance with Socket’s License Enforcement Beta. Set up your License Policy and secure your software!
Product
We're launching a new set of license analysis and compliance features for analyzing, managing, and complying with licenses across a range of supported languages and ecosystems.
Product
We're excited to introduce Socket Optimize, a powerful CLI command to secure open source dependencies with tested, optimized package overrides.