From a02b6512634a08ca5a01f99232df533a0d392548 Mon Sep 17 00:00:00 2001 From: Trent Mick Date: Tue, 16 Aug 2022 10:23:07 -0700 Subject: [PATCH] feat: improve SQL summarization to match cross-agent spec The cross-agent APM spec defines test cases for SQL statement summarization used for 'span.name' https://github.com/elastic/apm/blob/main/tests/agents/json-specs/sql_signature_examples.json --- test/sql-signature.test.js | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 test/sql-signature.test.js diff --git a/test/sql-signature.test.js b/test/sql-signature.test.js new file mode 100644 index 0000000000..0b772c0ddd --- /dev/null +++ b/test/sql-signature.test.js @@ -0,0 +1,25 @@ +/* + * Copyright Elasticsearch B.V. and other contributors where applicable. + * Licensed under the BSD 2-Clause License; you may not use this file except in + * compliance with the BSD 2-Clause License. + */ + +'use strict' + +// Test the Node.js APM agent's summarization of SQL statements used to set +// 'span.name' for DB spans against the cross-agent JSON spec. + +const sqlSummary = require('sql-summary') +const tape = require('tape') + +tape.test('cross-agent SQL statement summary/signature', function (t) { + const sqlSigCases = require('./fixtures/json-specs/sql_signature_examples.json') + sqlSigCases.forEach(sqlSigCase => { + let desc = JSON.stringify(sqlSigCase.input) + if (sqlSigCase.comment) { + desc += ' # ' + sqlSigCase.comment + } + t.equal(sqlSummary(sqlSigCase.input), sqlSigCase.output, desc) + }) + t.end() +})