Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issues with NO_TELEMETRY and code_coverage in JEST #260

Open
ch-sap opened this issue Nov 29, 2024 · 0 comments
Open

Issues with NO_TELEMETRY and code_coverage in JEST #260

ch-sap opened this issue Nov 29, 2024 · 0 comments
Labels

Comments

@ch-sap
Copy link

ch-sap commented Nov 29, 2024

Hello,

we have a CAP/Fiori Elements project that uses these packages for telemetry:
"@cap-js/telemetry": "^1.1.0",
"@opentelemetry/exporter-metrics-otlp-grpc": "^0.55.0",
"@opentelemetry/exporter-trace-otlp-grpc": "^0.55.0",

For code coverage measurement, we are using "jest": "^29.7.0".

As the log gets very long, we wanted to switch off telemetry during the code coverage measurement. The npm script looks like this:
"code-coverage": "NO_TELEMETRY=true node --experimental-vm-modules ./node_modules/.bin/jest --coverage",

Unfortunately, we got a flickering in our unit tests (red/green) where the cds log is read to check audit logging. It seemed as if an asynchronous request was not finished, but required. When we removed NO_TELEMETRY again, everything works fine.

Please, check. It took me quite some time to find where the issue comes from.

Best regards,
Christine

Some more information:

The test:
it('should log an audit log message when a visitor is read', async function () {
// Read the updated poetry slam in draft mode
const visitors = await GET(/odata/v4/visitorservice/Visitors?$top=1);
expect(visitors.data.value.length).to.greaterThan(0);
const auditLog = filterLog(cdsTestLog);
expect(auditLog.length).to.eql(1);
expect(auditLog[0].type).to.eql('SensitiveDataRead');
expect(auditLog[0].attributes[0]).to.eql('email');
});

The filterLog method:
function filterLog(log) {
// Filter the audit log entries
const auditLogs = log.output
.split(/^[/m)
.filter((log) => log.startsWith('audit-log'));
// Extract the type and details
const auditLogsInfo = auditLogs.map((log) =>
log.replaceAll(/\s/g, '').match(/-(\w+):.attributes:[(.)]/)
);
// Keep the type and extract the affected attributes
const auditLogsTypeAndAttributes = auditLogsInfo.map((info) => {
return {
type: info[1],
attributes: [...info[2].matchAll(/name:'(\w+)'/g)].map((attr) => attr[1])
};
});

return auditLogsTypeAndAttributes;
}

@github-actions github-actions bot added the new label Nov 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant