Skip to content

Commit 03302f1

Browse files
change organization
1 parent b713f2d commit 03302f1

File tree

5 files changed

+80
-97
lines changed

5 files changed

+80
-97
lines changed

integration-tests/sci-embedding.spec.js

Lines changed: 0 additions & 83 deletions
This file was deleted.

packages/dd-trace/src/config.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -512,9 +512,9 @@ ken|consumer_?(?:id|key|secret)|sign(?:ed|ature)?|auth(?:entication|orization)?)
512512
this.isGitUploadEnabled = this.isCiVisibility &&
513513
(this.isIntelligentTestRunnerEnabled && !isFalse(DD_CIVISIBILITY_GIT_UPLOAD_ENABLED))
514514

515-
this.isTraceGitMetadataEnabled = isTrue(DD_TRACE_GIT_METADATA_ENABLED)
515+
this.gitMetadataEnabled = isTrue(DD_TRACE_GIT_METADATA_ENABLED)
516516

517-
if (this.isTraceGitMetadataEnabled) {
517+
if (this.gitMetadataEnabled) {
518518
this.repositoryUrl = coalesce(
519519
process.env.DD_GIT_REPOSITORY_URL,
520520
this.tags[GIT_REPOSITORY_URL]
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
const { SCI_COMMIT_SHA, SCI_REPOSITORY_URL } = require('./constants')
2+
3+
class GitMetadataTagger {
4+
constructor (config) {
5+
this._config = config
6+
}
7+
8+
tagGitMetadata (spanContext) {
9+
if (this._config.gitMetadataEnabled) {
10+
spanContext._trace.tags[SCI_COMMIT_SHA] = this._config.commitSHA
11+
spanContext._trace.tags[SCI_REPOSITORY_URL] = this._config.repositoryUrl
12+
}
13+
}
14+
}
15+
16+
module.exports = GitMetadataTagger

packages/dd-trace/src/span_processor.js

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
const log = require('./log')
44
const format = require('./format')
55
const SpanSampler = require('./span_sampler')
6+
const GitMetadataTagger = require('./git_metadata_tagger')
67

78
const { SpanStatsProcessor } = require('./span_stats')
89
const { SCI_COMMIT_SHA, SCI_REPOSITORY_URL } = require('./constants')
@@ -19,24 +20,22 @@ class SpanProcessor {
1920

2021
this._stats = new SpanStatsProcessor(config)
2122
this._spanSampler = new SpanSampler(config.sampler)
23+
this._gitMetadataTagger = new GitMetadataTagger(config)
2224
}
2325

2426
process (span) {
2527
const spanContext = span.context()
2628
const active = []
2729
const formatted = []
2830
const trace = spanContext._trace
29-
const { flushMinSpans, isTraceGitMetadataEnabled } = this._config
31+
const { flushMinSpans } = this._config
3032
const { started, finished } = trace
3133

3234
if (trace.record === false) return
3335
if (started.length === finished.length || finished.length >= flushMinSpans) {
3436
this._prioritySampler.sample(spanContext)
3537
this._spanSampler.sample(spanContext)
36-
37-
if (isTraceGitMetadataEnabled) {
38-
this.addRepositoryMetadata(started)
39-
}
38+
this._gitMetadataTagger.tagGitMetadata(spanContext)
4039

4140
for (const span of started) {
4241
if (span._duration !== undefined) {
@@ -64,13 +63,6 @@ class SpanProcessor {
6463
}
6564
}
6665

67-
addRepositoryMetadata (spans) {
68-
const { repositoryUrl, commitSHA } = this._config
69-
const firstSpan = spans[0]
70-
firstSpan.setTag(SCI_REPOSITORY_URL, repositoryUrl)
71-
firstSpan.setTag(SCI_COMMIT_SHA, commitSHA)
72-
}
73-
7466
killAll () {
7567
this._killAll = true
7668
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
'use strict'
2+
3+
require('./setup/tap')
4+
5+
const agent = require('./plugins/agent')
6+
const { SCI_COMMIT_SHA, SCI_REPOSITORY_URL } = require('../src/constants')
7+
8+
const DUMMY_GIT_SHA = '13851f2b092e97acebab1b73f6c0e7818e795b50'
9+
const DUMMY_REPOSITORY_URL = '[email protected]:DataDog/sci_git_example.git'
10+
11+
const oldEnv = process.env
12+
13+
describe('dd-trace', () => {
14+
let tracer
15+
16+
beforeEach(() => {
17+
process.env = {
18+
...oldEnv,
19+
DD_GIT_COMMIT_SHA: DUMMY_GIT_SHA,
20+
DD_TAGS: `git.repository_url:${DUMMY_REPOSITORY_URL}`
21+
}
22+
tracer = require('../')
23+
return agent.load()
24+
})
25+
26+
afterEach(() => {
27+
agent.close()
28+
})
29+
30+
afterEach(() => {
31+
process.env = oldEnv
32+
})
33+
34+
it(`should include git metadata when using DD_GIT_* tags and DD_TAGS`, async () => {
35+
const span = tracer.startSpan('hello', {
36+
tags: {
37+
'resource.name': '/hello/:name'
38+
}
39+
})
40+
41+
const childSpan = tracer.startSpan('world', {
42+
childOf: span
43+
})
44+
45+
childSpan.finish()
46+
span.finish()
47+
48+
return agent.use((payload) => {
49+
const firstSpan = payload[0][0]
50+
expect(firstSpan.meta[SCI_COMMIT_SHA]).to.equal(DUMMY_GIT_SHA)
51+
expect(firstSpan.meta[SCI_REPOSITORY_URL]).to.equal(DUMMY_REPOSITORY_URL)
52+
53+
const secondSpan = payload[0][1]
54+
expect(secondSpan.meta[SCI_COMMIT_SHA]).not.to.exist
55+
expect(secondSpan.meta[SCI_REPOSITORY_URL]).not.to.exist
56+
})
57+
})
58+
})

0 commit comments

Comments
 (0)