Skip to content
Draft
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
10 changes: 6 additions & 4 deletions packages/dd-trace/src/opentracing/span.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
const startCh = channel('dd-trace:span:start')
const finishCh = channel('dd-trace:span:finish')

function getIntegrationCounter (event, integration) {
function getIntegrationCounter (event, integration, version) {
const counters = integrationCounters[event]

if (integration in counters) {
Expand All @@ -43,7 +43,9 @@

const counter = tracerMetrics.count(event, [
`integration_name:${integration.toLowerCase()}`,
`otel_enabled:${OTEL_ENABLED}`
`otel_enabled:${OTEL_ENABLED}`,
`dependency_name:${integration}`,
`dependency_version:${version}`
])

integrationCounters[event][integration] = counter
Expand Down Expand Up @@ -75,7 +77,7 @@
this._name = operationName
this._integrationName = fields.integrationName || 'opentracing'

getIntegrationCounter('spans_created', this._integrationName).inc()
getIntegrationCounter('spans_created', this._integrationName, tags['_dd.dependency_version']).inc()

this._spanContext = this._createContext(parent, fields)
this._spanContext._name = operationName
Expand Down Expand Up @@ -239,7 +241,7 @@
log.error('Finishing invalid span: %s', this)
}

getIntegrationCounter('spans_finished', this._integrationName).inc()
getIntegrationCounter('spans_finished', this._integrationName, this._spanContext._tags['_dd.dependency_version']).inc()

Check failure on line 244 in packages/dd-trace/src/opentracing/span.js

View workflow job for this annotation

GitHub Actions / lint

This line has a length of 123. Maximum allowed is 120
this._spanContext._tags['_dd.integration'] = this._integrationName

if (DD_TRACE_EXPERIMENTAL_SPAN_COUNTS && finishedRegistry) {
Expand Down
4 changes: 2 additions & 2 deletions packages/dd-trace/src/opentracing/tracer.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ class DatadogTracer {

// as per spec, allow the setting of service name through options
const tags = {
'service.name': options?.tags?.service ? String(options.tags.service) : this._service
'service.name': options?.tags?.service ? String(options.tags.service) : this._service,
...options.tags
}

// As per unified service tagging spec if a span is created with a service name different from the global
Expand All @@ -75,7 +76,6 @@ class DatadogTracer {
}, this._debug)

span.addTags(this._config.tags)
span.addTags(options.tags)

return span
}
Expand Down
5 changes: 5 additions & 0 deletions packages/dd-trace/src/plugins/tracing.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const Plugin = require('./plugin')
const { storage } = require('../../../datadog-core')
const analyticsSampler = require('../analytics_sampler')
const { COMPONENT } = require('../constants')
const { detectedDependencyToVersion } = require('../telemetry/dependencies')

class TracingPlugin extends Plugin {
constructor (...args) {
Expand Down Expand Up @@ -125,6 +126,8 @@ class TracingPlugin extends Plugin {
childOf = store.span
}

const dependencyVersion = detectedDependencyToVersion[this.component]

const span = tracer.startSpan(name, {
startTime,
childOf,
Expand All @@ -134,6 +137,8 @@ class TracingPlugin extends Plugin {
'resource.name': resource,
'span.kind': kind,
'span.type': type,
'_dd.dependency_name': this.component,
'_dd.dependency_version': dependencyVersion,
...meta,
...metrics
},
Expand Down
4 changes: 3 additions & 1 deletion packages/dd-trace/src/telemetry/dependencies.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const { isTrue } = require('../../src/util')
const savedDependenciesToSend = new Set()
const detectedDependencyKeys = new Set()
const detectedDependencyVersions = new Set()
const detectedDependencyToVersion = {}

const FILE_URI_START = 'file://'
const moduleLoadStartChannel = dc.channel('dd-trace:moduleLoadStart')
Expand Down Expand Up @@ -119,6 +120,7 @@ function onModuleLoad (data) {
if (!detectedDependencyVersions.has(dependencyAndVersion)) {
savedDependenciesToSend.add(`${dependencyAndVersion} ${initialLoad}`)
detectedDependencyVersions.add(dependencyAndVersion)
detectedDependencyToVersion[name] = version

waitAndSend(config, application, host)
}
Expand Down Expand Up @@ -171,4 +173,4 @@ function stop () {
moduleLoadStartChannel.unsubscribe(onModuleLoad)
}
}
module.exports = { start, stop }
module.exports = { start, stop, detectedDependencyToVersion }
11 changes: 11 additions & 0 deletions packages/dd-trace/test/plugins/agent.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
const { storage } = require('../../../datadog-core')
const { assertObjectContains } = require('../../../../integration-tests/helpers')
const { expect } = require('chai')
const { detectedDependencyToVersion } = require('../../src/telemetry/dependencies')

const traceHandlers = new Set()
const statsHandlers = new Set()
Expand Down Expand Up @@ -247,6 +248,16 @@
`Expected span to have "_dd.integration" tag "${currentIntegrationName}"
but found "${span.meta['_dd.integration']}" for span ID ${span.span_id}`
)
expect(span.meta['_dd.dependency_version']).to.equal(
detectedDependencyToVersion[span.meta['_dd.dependency_name']],
`Expected span to have "_dd.dependency_version" tag "${detectedDependencyToVersion[span.meta['_dd.dependency_name']]}"

Check failure on line 253 in packages/dd-trace/test/plugins/agent.js

View workflow job for this annotation

GitHub Actions / lint

This line has a length of 134. Maximum allowed is 120
but found "${span.meta['_dd.dependency_version']}" for span ID ${span.span_id}`
)
expect(span.meta['_dd.dependency_name']).to.equal(
span.meta['_dd.integration'],
`Expected span to have "_dd.dependency_name" tag "${span.meta['_dd.integration']}"
but found "${span.meta['_dd.dependency_name']}" for span ID ${span.span_id}`
)
}
})
}
Expand Down
Loading