Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
9 changes: 4 additions & 5 deletions packages/dd-trace/src/format.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ const map = {
'resource.name': 'resource'
}

function format (span) {
function format (span, isChunkRoot) {
const formatted = formatSpan(span)

extractSpanLinks(formatted, span)
extractSpanEvents(formatted, span)
extractRootTags(formatted, span)
extractChunkTags(formatted, span)
extractChunkTags(formatted, span, isChunkRoot)
extractTags(formatted, span)

return formatted
Expand Down Expand Up @@ -192,11 +192,10 @@ function extractRootTags (formattedSpan, span) {
addTag({}, formattedSpan.metrics, TOP_LEVEL_KEY, 1)
}

function extractChunkTags (formattedSpan, span) {
function extractChunkTags (formattedSpan, span, isChunkRoot) {
const context = span.context()
const isLocalRoot = span === context._trace.started[0]

if (!isLocalRoot) return
if (!isChunkRoot) return

for (const [key, value] of Object.entries(context._trace.tags)) {
addTag(formattedSpan.meta, formattedSpan.metrics, key, value)
Expand Down
5 changes: 4 additions & 1 deletion packages/dd-trace/src/span_processor.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,14 @@ class SpanProcessor {
this._spanSampler.sample(spanContext)
this._gitMetadataTagger.tagGitMetadata(spanContext)

let isChunkRoot = true

for (const span of started) {
if (span._duration === undefined) {
active.push(span)
} else {
const formattedSpan = format(span)
const formattedSpan = format(span, isChunkRoot)
isChunkRoot = false
this._stats?.onSpanFinished(formattedSpan)
formatted.push(formattedSpan)

Expand Down
20 changes: 18 additions & 2 deletions packages/dd-trace/test/format.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ describe('format', () => {
count: 1
}

trace = format(span)
trace = format(span, true)

expect(trace.meta).to.include({
chunk: 'test'
Expand All @@ -304,13 +304,29 @@ describe('format', () => {
})
})

it('should not extract trace chunk tags whens isNotChunkRoot', () => {
spanContext._trace.tags = {
chunk: 'test',
count: 1
}

trace = format(span, false)
expect(trace.meta).to.not.include({
chunk: 'test'
})

expect(trace.metrics).to.not.include({
count: 1
})
})

it('should extract empty tags', () => {
spanContext._trace.tags = {
foo: '',
count: 1
}

trace = format(span)
trace = format(span, true)

expect(trace.meta).to.include({
foo: ''
Expand Down
15 changes: 14 additions & 1 deletion packages/dd-trace/test/span_processor.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ describe('SpanProcessor', () => {
expect(trace).to.have.deep.property('finished', [])
})

it('should configure span sampler conrrectly', () => {
it('should configure span sampler correctly', () => {
const config = {
stats: { enabled: false },
sampler: {
Expand Down Expand Up @@ -156,4 +156,17 @@ describe('SpanProcessor', () => {
expect(finishedSpan.context()).to.have.deep.property('_tags', {})
expect(exporter.export).not.to.have.been.called
})

it('should call format every time a partial flush is triggered', () => {
config.flushMinSpans = 1
const processor = new SpanProcessor(exporter, prioritySampler, config)
trace.started = [activeSpan, finishedSpan]
trace.finished = [finishedSpan]
processor.process(activeSpan)

expect(trace).to.have.deep.property('started', [activeSpan])
expect(trace).to.have.deep.property('finished', [])
expect(format.callCount).to.equal(1)
expect(format).to.have.been.calledWith(finishedSpan, true)
})
})