Skip to content

Commit 619c301

Browse files
authored
instrumentation: fix service name for oracledb (#6038)
The service name should be handled by the schema, even if undefined is passed through. Instead of falling back to the connection, use the fallback as defined in schema v1. The service method is now only accepting truthy strings as return value and will otherwise fallback.
1 parent 14dec06 commit 619c301

File tree

5 files changed

+8
-12
lines changed

5 files changed

+8
-12
lines changed

packages/datadog-plugin-oracledb/src/index.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class OracledbPlugin extends DatabasePlugin {
1111
static get peerServicePrecursors () { return ['db.instance', 'db.hostname'] }
1212

1313
start ({ query, connAttrs, port, hostname, dbInstance }) {
14-
let service = this.serviceName({ pluginConfig: this.config, params: connAttrs })
14+
const service = this.serviceName({ pluginConfig: this.config, params: connAttrs })
1515

1616
if (hostname === undefined) {
1717
// Lazy load for performance. This is not needed in v6 and up
@@ -22,11 +22,6 @@ class OracledbPlugin extends DatabasePlugin {
2222
dbInstance ??= dbInfo.dbInstance
2323
}
2424

25-
if (service === undefined && hostname) {
26-
// Fallback for users not providing the service properly in a serviceName method
27-
service = `${hostname}:${port}/${dbInstance}`
28-
}
29-
3025
this.startSpan(this.operationName(), {
3126
service,
3227
resource: query,

packages/datadog-plugin-oracledb/test/index.spec.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -293,11 +293,11 @@ describe('Plugin', () => {
293293
{
294294
v0: {
295295
opName: 'oracle.query',
296-
serviceName: config.connectString
296+
serviceName: 'test-oracle'
297297
},
298298
v1: {
299299
opName: 'oracle.query',
300-
serviceName: config.connectString
300+
serviceName: 'test'
301301
}
302302
}
303303
)
@@ -306,7 +306,7 @@ describe('Plugin', () => {
306306
await Promise.all([
307307
agent.assertFirstTraceSpan({
308308
name: expectedSchema.outbound.opName,
309-
service: config.connectString
309+
service: 'test-oracle'
310310
}),
311311
connection.execute(dbQuery)
312312
])

packages/dd-trace/src/service-naming/schemas/v1/storage.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ const mySQLNaming = {
1414

1515
function withFunction ({ tracerService, pluginConfig, params }) {
1616
if (typeof pluginConfig.service === 'function') {
17-
return pluginConfig.service(params)
17+
const result = pluginConfig.service(params)
18+
return typeof result === 'string' && result.length > 0 ? result : tracerService
1819
}
1920
return configWithFallback({ tracerService, pluginConfig })
2021
}

packages/dd-trace/test/plugins/agent.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ function assertIntegrationName (args) {
244244
if (span && span.meta && span.meta.component && span.meta.component !== span.meta['_dd.integration']) {
245245
expect(span.meta['_dd.integration']).to.equal(
246246
currentIntegrationName,
247-
`Expected span to have "_dd.integration" tag "${currentIntegrationName}"
247+
`Expected span to have "_dd.integration" tag "${currentIntegrationName}"
248248
but found "${span.meta['_dd.integration']}" for span ID ${span.span_id}`
249249
)
250250
}

packages/dd-trace/test/setup/mocha.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ function withNamingSchema (
3434
const {
3535
hooks = (version, defaultToGlobalService) => {},
3636
desc = '',
37-
selectSpan = (traces) => traces[0][0]
37+
selectSpan = (traces) => traces[0][0],
3838
} = opts
3939
let fullConfig
4040

0 commit comments

Comments
 (0)