From 004880f1e2e4db9ce2ecc0c3d33e6fcce900b956 Mon Sep 17 00:00:00 2001 From: mrickard Date: Fri, 26 Apr 2024 18:09:58 -0400 Subject: [PATCH 1/3] chore: Added otel compliant attributes for database spans Signed-off-by: mrickard --- lib/spans/span-event.js | 3 +++ lib/spans/streaming-span-event.js | 3 +++ test/unit/spans/span-event.test.js | 7 ++++++- test/unit/spans/streaming-span-event.test.js | 7 ++++++- 4 files changed, 18 insertions(+), 2 deletions(-) diff --git a/lib/spans/span-event.js b/lib/spans/span-event.js index 76188290a1..0d7e59c5da 100644 --- a/lib/spans/span-event.js +++ b/lib/spans/span-event.js @@ -231,6 +231,7 @@ class DatastoreSpanEvent extends SpanEvent { if (attributes.product) { this.intrinsics.component = attributes.product + this.addAttribute('db.system', attributes.product) attributes.product = null } @@ -260,10 +261,12 @@ class DatastoreSpanEvent extends SpanEvent { if (attributes.host) { this.addAttribute('peer.hostname', attributes.host) + this.addAttribute('server.address', attributes.host) if (attributes.port_path_or_id) { const address = `${attributes.host}:${attributes.port_path_or_id}` this.addAttribute('peer.address', address) + this.addAttribute('server.port', attributes.port_path_or_id) attributes.port_path_or_id = null } attributes.host = null diff --git a/lib/spans/streaming-span-event.js b/lib/spans/streaming-span-event.js index f5a578899e..70c58489a3 100644 --- a/lib/spans/streaming-span-event.js +++ b/lib/spans/streaming-span-event.js @@ -243,6 +243,7 @@ class StreamingDatastoreSpanEvent extends StreamingSpanEvent { if (agentAttributes.product) { this.addIntrinsicAttribute('component', agentAttributes.product) + this.addAgentAttribute('db.system', agentAttributes.product) agentAttributes.product = null } @@ -272,10 +273,12 @@ class StreamingDatastoreSpanEvent extends StreamingSpanEvent { if (agentAttributes.host) { this.addAgentAttribute('peer.hostname', agentAttributes.host) + this.addAgentAttribute('server.address', agentAttributes.host) if (agentAttributes.port_path_or_id) { const address = `${agentAttributes.host}:${agentAttributes.port_path_or_id}` this.addAgentAttribute('peer.address', address) + this.addAgentAttribute('server.port', agentAttributes.port_path_or_id) agentAttributes.port_path_or_id = null } diff --git a/test/unit/spans/span-event.test.js b/test/unit/spans/span-event.test.js index 99f2695f25..d64d0f3d4c 100644 --- a/test/unit/spans/span-event.test.js +++ b/test/unit/spans/span-event.test.js @@ -115,6 +115,7 @@ tap.test('fromSegment()', (t) => { // Should have no datastore properties. t.notOk(hasOwnAttribute('db.statement')) t.notOk(hasOwnAttribute('db.instance')) + t.notOk(hasOwnAttribute('db.system')) t.notOk(hasOwnAttribute('peer.hostname')) t.notOk(hasOwnAttribute('peer.address')) @@ -182,6 +183,7 @@ tap.test('fromSegment()', (t) => { const hasOwnAttribute = Object.hasOwnProperty.bind(attributes) t.notOk(hasOwnAttribute('db.statement')) t.notOk(hasOwnAttribute('db.instance')) + t.notOk(hasOwnAttribute('db.system')) t.notOk(hasOwnAttribute('peer.hostname')) t.notOk(hasOwnAttribute('peer.address')) @@ -191,7 +193,7 @@ tap.test('fromSegment()', (t) => { }) }) - t.test('should create an datastore span with an datastore segment', (t) => { + t.test('should create a datastore span with a datastore segment', (t) => { agent.config.transaction_tracer.record_sql = 'raw' const shim = new DatastoreShim(agent, 'test-data-store') @@ -270,6 +272,9 @@ tap.test('fromSegment()', (t) => { t.equal(attributes['db.collection'], 'my-collection') t.equal(attributes['peer.hostname'], 'my-db-host') t.equal(attributes['peer.address'], 'my-db-host:/path/to/db.sock') + t.equal(attributes['db.system'], 'TestStore') // same as intrinsics.component + t.equal(attributes['server.address'], 'my-db-host') + t.equal(attributes['server.port'], '/path/to/db.sock') const statement = attributes['db.statement'] t.ok(statement) diff --git a/test/unit/spans/streaming-span-event.test.js b/test/unit/spans/streaming-span-event.test.js index 235f2f3f93..95515876a2 100644 --- a/test/unit/spans/streaming-span-event.test.js +++ b/test/unit/spans/streaming-span-event.test.js @@ -107,6 +107,7 @@ tap.test('fromSegment()', (t) => { // Should have no datastore properties. t.notOk(hasOwnAttribute('db.statement')) t.notOk(hasOwnAttribute('db.instance')) + t.notOk(hasOwnAttribute('db.system')) t.notOk(hasOwnAttribute('peer.hostname')) t.notOk(hasOwnAttribute('peer.address')) @@ -167,6 +168,7 @@ tap.test('fromSegment()', (t) => { const hasOwnAttribute = Object.hasOwnProperty.bind(agentAttributes) t.notOk(hasOwnAttribute('db.statement')) t.notOk(hasOwnAttribute('db.instance')) + t.notOk(hasOwnAttribute('db.system')) t.notOk(hasOwnAttribute('peer.hostname')) t.notOk(hasOwnAttribute('peer.address')) @@ -176,7 +178,7 @@ tap.test('fromSegment()', (t) => { }) }) - t.test('should create an datastore span with an datastore segment', (t) => { + t.test('should create a datastore span with a datastore segment', (t) => { agent.config.transaction_tracer.record_sql = 'raw' const shim = new DatastoreShim(agent, 'test-data-store') @@ -258,6 +260,9 @@ tap.test('fromSegment()', (t) => { t.same(agentAttributes['db.collection'], { [STRING_TYPE]: 'my-collection' }) t.same(agentAttributes['peer.hostname'], { [STRING_TYPE]: 'my-db-host' }) t.same(agentAttributes['peer.address'], { [STRING_TYPE]: 'my-db-host:/path/to/db.sock' }) + t.same(agentAttributes['db.system'], { [STRING_TYPE]: 'TestStore' }) // same as intrinsics.component + t.same(agentAttributes['server.address'], { [STRING_TYPE]: 'my-db-host' }) + t.same(agentAttributes['server.port'], { [STRING_TYPE]: '/path/to/db.sock' }) const statement = agentAttributes['db.statement'] t.ok(statement) From f656ea02d099193a55e316d038846e86adc566b9 Mon Sep 17 00:00:00 2001 From: mrickard Date: Tue, 30 Apr 2024 17:15:58 -0400 Subject: [PATCH 2/3] chore: Added truncateExempt flag for port properties, and restored defaults that had been stripped from JSDoc declarations Signed-off-by: mrickard --- lib/spans/span-event.js | 2 +- lib/spans/streaming-span-event.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/spans/span-event.js b/lib/spans/span-event.js index 0d7e59c5da..6970a09099 100644 --- a/lib/spans/span-event.js +++ b/lib/spans/span-event.js @@ -266,7 +266,7 @@ class DatastoreSpanEvent extends SpanEvent { if (attributes.port_path_or_id) { const address = `${attributes.host}:${attributes.port_path_or_id}` this.addAttribute('peer.address', address) - this.addAttribute('server.port', attributes.port_path_or_id) + this.addAttribute('server.port', attributes.port_path_or_id, true) attributes.port_path_or_id = null } attributes.host = null diff --git a/lib/spans/streaming-span-event.js b/lib/spans/streaming-span-event.js index 70c58489a3..c89a271eef 100644 --- a/lib/spans/streaming-span-event.js +++ b/lib/spans/streaming-span-event.js @@ -278,7 +278,7 @@ class StreamingDatastoreSpanEvent extends StreamingSpanEvent { if (agentAttributes.port_path_or_id) { const address = `${agentAttributes.host}:${agentAttributes.port_path_or_id}` this.addAgentAttribute('peer.address', address) - this.addAgentAttribute('server.port', agentAttributes.port_path_or_id) + this.addAgentAttribute('server.port', agentAttributes.port_path_or_id, true) agentAttributes.port_path_or_id = null } From 707ab6e2bb964ac1701e17ebfc9be191de22e292 Mon Sep 17 00:00:00 2001 From: mrickard Date: Tue, 30 Apr 2024 17:30:36 -0400 Subject: [PATCH 3/3] chore: Removed db span test assertions that conflicted with new properties Signed-off-by: mrickard --- test/unit/spans/span-event.test.js | 1 - test/unit/spans/streaming-span-event.test.js | 1 - 2 files changed, 2 deletions(-) diff --git a/test/unit/spans/span-event.test.js b/test/unit/spans/span-event.test.js index d64d0f3d4c..4d3d166945 100644 --- a/test/unit/spans/span-event.test.js +++ b/test/unit/spans/span-event.test.js @@ -263,7 +263,6 @@ tap.test('fromSegment()', (t) => { // Should have not http properties. const hasOwnAttribute = Object.hasOwnProperty.bind(attributes) t.notOk(hasOwnAttribute('http.url')) - t.notOk(hasOwnAttribute('server.address')) t.notOk(hasOwnAttribute('http.method')) t.notOk(hasOwnAttribute('http.request.method')) diff --git a/test/unit/spans/streaming-span-event.test.js b/test/unit/spans/streaming-span-event.test.js index 95515876a2..5f7cf9f604 100644 --- a/test/unit/spans/streaming-span-event.test.js +++ b/test/unit/spans/streaming-span-event.test.js @@ -251,7 +251,6 @@ tap.test('fromSegment()', (t) => { // Should have not http properties. const hasOwnAttribute = Object.hasOwnProperty.bind(agentAttributes) t.notOk(hasOwnAttribute('http.url')) - t.notOk(hasOwnAttribute('server.address')) t.notOk(hasOwnAttribute('http.method')) t.notOk(hasOwnAttribute('http.request.method'))