Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -845,7 +845,7 @@ declare namespace tracer {
* @env DD_DBM_PROPAGATION_MODE
* Programmatic configuration takes precedence over the environment variables listed above.
*/
dbmPropagationMode?: 'disabled' | 'service' | 'full'
dbmPropagationMode?: 'disabled' | 'service' | 'full' | 'dynamic_service'

/**
* Whether to enable Data Streams Monitoring.
Expand Down
2 changes: 1 addition & 1 deletion index.d.v5.ts
Original file line number Diff line number Diff line change
Expand Up @@ -912,7 +912,7 @@ declare namespace tracer {
* @env DD_DBM_PROPAGATION_MODE
* Programmatic configuration takes precedence over the environment variables listed above.
*/
dbmPropagationMode?: 'disabled' | 'service' | 'full'
dbmPropagationMode?: 'disabled' | 'service' | 'full' | 'dynamic_service'

/**
* Whether to enable Data Streams Monitoring.
Expand Down
7 changes: 4 additions & 3 deletions packages/dd-trace/src/plugins/database.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,9 @@ class DatabasePlugin extends StoragePlugin {

let dbmComment = servicePropagation

// Add propagation hash if both process tags and SQL base hash injection are enabled
if (propagationHash.isEnabled() && this.config['dbm.injectSqlBaseHash']) {
// Add propagation hash if process tags are enabled and either SQL base hash injection is enabled
// or dynamic_service mode implicitly enables it
if (propagationHash.isEnabled() && (this.config['dbm.injectSqlBaseHash'] || mode === 'dynamic_service')) {
const hashBase64 = propagationHash.getHashBase64()
if (hashBase64) {
dbmComment += `,ddsh='${hashBase64}'`
Expand All @@ -107,7 +108,7 @@ class DatabasePlugin extends StoragePlugin {
}
}

if (disableFullMode || mode === 'service') {
if (disableFullMode || mode === 'service' || mode === 'dynamic_service') {
return dbmComment
} else if (mode === 'full') {
span.setTag('_dd.dbm_trace_injected', 'true')
Expand Down
48 changes: 48 additions & 0 deletions packages/dd-trace/test/plugins/database-dbm-hash.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,54 @@ describe('DatabasePlugin DBM Hash', () => {
})
})

describe('dynamic_service mode', () => {
beforeEach(() => {
plugin.config.dbmPropagationMode = 'dynamic_service'
})

it('should inject hash even when dbm.injectSqlBaseHash is false', () => {
plugin.config['dbm.injectSqlBaseHash'] = false

const comment = plugin.createDbmComment(span, 'test-service')

assert.ok(comment, 'Comment should be created')
assert.ok(comment.includes("ddsh='AQIDBAUG'"),
'dynamic_service should inject hash regardless of injectSqlBaseHash')
})

it('should not inject traceparent', () => {
const comment = plugin.createDbmComment(span, 'test-service')

assert.ok(comment, 'Comment should be created')
assert.ok(!comment.includes('traceparent='), 'dynamic_service should not inject traceparent')
})

it('should behave identically to service + injectSqlBaseHash=true', () => {
plugin.config['dbm.injectSqlBaseHash'] = false

const dynamicComment = plugin.createDbmComment(span, 'test-service')

// Reset span tags and compare with service + injectSqlBaseHash=true
span._tags = {}
plugin.config.dbmPropagationMode = 'service'
plugin.config['dbm.injectSqlBaseHash'] = true

const serviceComment = plugin.createDbmComment(span, 'test-service')

assert.strictEqual(dynamicComment, serviceComment,
'dynamic_service should produce identical output to service + injectSqlBaseHash=true')
})

it('should not inject hash when propagation hash is disabled', () => {
propagationHash.isEnabled = () => false

const comment = plugin.createDbmComment(span, 'test-service')

assert.ok(comment, 'Comment should still be created')
assert.ok(!comment.includes('ddsh='), 'Should not inject hash when propagation hash is disabled')
})
})

describe('control matrix for process tags and SQL base hash', () => {
it('should inject hash when both propagateProcessTags and injectSqlBaseHash are enabled', () => {
// DD_EXPERIMENTAL_PROPAGATE_PROCESS_TAGS_ENABLED=true + DD_DBM_INJECT_SQL_BASEHASH=true
Expand Down
Loading