From 3b61c550067b473674f02d4353f0bf526371b487 Mon Sep 17 00:00:00 2001 From: Ran Nozik Date: Thu, 19 Aug 2021 13:55:00 +0300 Subject: [PATCH] add another test --- .../test/mongodb.test.ts | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/plugins/node/opentelemetry-instrumentation-mongodb/test/mongodb.test.ts b/plugins/node/opentelemetry-instrumentation-mongodb/test/mongodb.test.ts index 489b45d98a..9a2dae710a 100644 --- a/plugins/node/opentelemetry-instrumentation-mongodb/test/mongodb.test.ts +++ b/plugins/node/opentelemetry-instrumentation-mongodb/test/mongodb.test.ts @@ -250,6 +250,37 @@ describe('MongoDBInstrumentation', () => { }); }); + describe('when using enhanced database reporting without db statementSerializer', () => { + const key = 'key'; + const value = 'value'; + const object = { [key]: value }; + + beforeEach(() => { + memoryExporter.reset(); + create({ + enhancedDatabaseReporting: false, + }); + }); + + it('should properly collect db statement (hide attribute values)', done => { + const span = provider.getTracer('default').startSpan('insertRootSpan'); + context.with(trace.setSpan(context.active(), span), () => { + collection.insertOne(object).then(() => { + span.end(); + const spans = memoryExporter.getFinishedSpans(); + const operationName = 'mongodb.insert'; + assertSpans(spans, operationName, SpanKind.CLIENT, false, false); + const mongoSpan = spans.find(s => s.name === operationName); + const dbStatement = JSON.parse( + mongoSpan!.attributes[SemanticAttributes.DB_STATEMENT] as string + ); + assert.strictEqual(dbStatement[key], '?'); + done(); + }); + }); + }); + }); + describe('when specifying a dbStatementSerializer configuration', () => { const key = 'key'; const value = 'value';