see ./transaction.js
:
function main(params) {
const { __ow_headers: headers = {} } = params;
const body = {
transactionId: process.env.__OW_TRANSACTION_ID,
requestId: headers['x-request-id'] || 'n/a',
};
return {
statusCode: 200,
headers: { 'Content-Type': 'application/json'},
body,
};
}
$ curl -sD - https://adobeioruntime.net/api/v1/web/tripod/default/transaction
HTTP/1.1 200 OK
...
x-openwhisk-activation-id: 5cb3efd2c86d4088b3efd2c86d208847
X-Request-ID: jJZA1hZ5wKCfNEvalA0cnTnWiUd5Alfo
{
"requestId": "jJZA1hZ5wKCfNEvalA0cnTnWiUd5Alfo",
"transactionId": "jJZA1hZ5wKCfNEvalA0cnTnWiUd5Alfo"
}
$ curl -sD - https://adobeioruntime.net/api/v1/web/tripod/default/transaction -H 'x-request-id: toby-was-here'
HTTP/1.1 200 OK
...
x-openwhisk-activation-id: 3d8ecb11ff65448b8ecb11ff65c48b92
X-Request-ID: toby-was-here
{
"requestId": "toby-was-here",
"transactionId": "toby-was-here"
}
$
$ wsk action invoke -r transaction
{
"body": {
"requestId": "n/a",
"transactionId": "QzysZzIC9npxTUlgHWnBeA5xXs5iYtUw"
},
"headers": {
"Content-Type": "application/json"
},
"statusCode": 200
}
$ cat transaction.json
{
"__ow_headers": {
"x-request-id": "toby-was-here"
}
}
$ wsk action invoke -r transaction -P transaction.json
{
"body": {
"requestId": "toby-was-here",
"transactionId": "ye3WgpMwvta3CZfaiWojP8pa88wwzTJ7"
},
"headers": {
"Content-Type": "application/json"
},
"statusCode": 200
}
$ curl -sD - -X POST \
-H "x-request-id: toby-was-here" \
-u "$WSK_AUTH" \
'https://adobeioruntime.net/api/v1/namespaces/tripod/actions/transaction?blocking=true&result=true'
HTTP/1.1 200 OK
...
x-openwhisk-activation-id: dc3cbcf5d7014258bcbcf5d70152588c
X-Request-ID: toby-was-here
Content-Length: 123
Connection: keep-alive
{"body":{"requestId":"n/a","transactionId":"toby-was-here"},"headers":{"Content-Type":"application/json"},"statusCode":200}
the openwhisk client can be patched in order to propagate the transaction id:
const ow = openwhisk();
const { client } = ow.actions;
const original_params = client.params.bind(client);
client.params = async (...args) => {
const ps = await original_params(...args);
ps.headers['x-request-id'] = process.env.__OW_TRANSACTION_ID;
return ps;
};
so, invoking another action:
const ret = await ow.actions.invoke({
name: 'transaction',
blocking: true,
result: true,
});
body.invoke_result = ret;
works:
$ curl -sD - "https://adobeioruntime.net/api/v1/web/tripod/default/transaction?recursive=true" -H 'x-request-id: toby-was-here'
HTTP/1.1 200 OK
...
x-openwhisk-activation-id: a6626cec6fbf4dfda26cec6fbf8dfdc1
X-Request-ID: toby-was-here
{
"invoke_result": {
"body": {
"requestId": "n/a",
"transactionId": "toby-was-here"
},
"headers": {
"Content-Type": "application/json"
},
"statusCode": 200
},
"requestId": "toby-was-here",
"transactionId": "toby-was-here"
}