-
Notifications
You must be signed in to change notification settings - Fork 358
SCI Embedding of git metadata #3118
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
33851f2
1bba75f
b713f2d
8201501
af2f78d
4490619
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| 'use strict' | ||
|
|
||
| const { | ||
| FakeAgent, | ||
| spawnProc, | ||
| createSandbox, | ||
| curlAndAssertMessage | ||
| } = require('./helpers') | ||
| const path = require('path') | ||
| const { assert } = require('chai') | ||
|
|
||
| describe(`sci embedding`, function () { | ||
| let agent | ||
| let proc | ||
| let sandbox | ||
| let cwd | ||
|
|
||
| before(async () => { | ||
| sandbox = await createSandbox(['express']) | ||
| cwd = sandbox.folder | ||
| }) | ||
|
|
||
| after(async () => { | ||
| await sandbox.remove() | ||
| }) | ||
|
|
||
| beforeEach(async () => { | ||
| agent = await new FakeAgent().start() | ||
| }) | ||
|
|
||
| afterEach(async () => { | ||
| proc && proc.kill() | ||
| await agent.stop() | ||
| }) | ||
|
|
||
| context('via DD_GIT_* tags', () => { | ||
| it('in the first span', async () => { | ||
| proc = await spawnProc(path.join(cwd, 'sci-embedding/express.js'), { | ||
| cwd, | ||
| env: { | ||
| AGENT_PORT: agent.port, | ||
| DD_GIT_REPOSITORY_URL: '[email protected]:DataDog/sci_git_example.git', | ||
| DD_GIT_COMMIT_SHA: '13851f2b092e97acebab1b73f6c0e7818e795b50' | ||
| } | ||
| }) | ||
| return curlAndAssertMessage(agent, proc, ({ headers, payload }) => { | ||
| const firstSpan = payload[0][0] | ||
| assert.equal(firstSpan.meta['_dd.git.commit.sha'], '13851f2b092e97acebab1b73f6c0e7818e795b50') | ||
| assert.equal(firstSpan.meta['_dd.git.repository_url'], '[email protected]:DataDog/sci_git_example.git') | ||
|
|
||
| const secondSpan = payload[0][1] | ||
| assert.notExists(secondSpan.meta['_dd.git.commit.sha']) | ||
| assert.notExists(secondSpan.meta['_dd.git.repository_url']) | ||
| }) | ||
| }) | ||
| }) | ||
| context('via DD_TAGS', () => { | ||
| it('in the first span', async () => { | ||
| proc = await spawnProc(path.join(cwd, 'sci-embedding/express.js'), { | ||
| cwd, | ||
| env: { | ||
| AGENT_PORT: agent.port, | ||
| DD_TAGS: 'git.repository_url:[email protected]:DataDog/sci_git_example.git,' + | ||
| 'git.commit.sha:13851f2b092e97acebab1b73f6c0e7818e795b50' | ||
| } | ||
| }) | ||
| return curlAndAssertMessage(agent, proc, ({ headers, payload }) => { | ||
| const firstSpan = payload[0][0] | ||
| assert.equal(firstSpan.meta['_dd.git.commit.sha'], '13851f2b092e97acebab1b73f6c0e7818e795b50') | ||
| assert.equal(firstSpan.meta['_dd.git.repository_url'], '[email protected]:DataDog/sci_git_example.git') | ||
|
|
||
| const secondSpan = payload[0][1] | ||
| assert.notExists(secondSpan.meta['_dd.git.commit.sha']) | ||
| assert.notExists(secondSpan.meta['_dd.git.repository_url']) | ||
| }) | ||
| }) | ||
| }) | ||
| }) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| const tracer = require('dd-trace') | ||
| const express = require('express') | ||
|
|
||
| tracer.init({ port: process.env.AGENT_PORT }) | ||
|
|
||
| const app = express() | ||
|
|
||
| app.use((req, res) => { | ||
| res.end('hello, world\n') | ||
| }) | ||
|
|
||
| const server = app.listen(0, () => { | ||
| const port = server.address().port | ||
| process.send({ port }) | ||
| }) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -393,6 +393,11 @@ ken|consumer_?(?:id|key|secret)|sign(?:ed|ature)?|auth(?:entication|orization)?) | |
| true | ||
| ) | ||
|
|
||
| const DD_TRACE_GIT_METADATA_ENABLED = coalesce( | ||
| process.env.DD_TRACE_GIT_METADATA_ENABLED, | ||
| true | ||
| ) | ||
|
|
||
| const ingestion = options.ingestion || {} | ||
| const dogstatsd = coalesce(options.dogstatsd, {}) | ||
| const sampler = { | ||
|
|
@@ -506,6 +511,19 @@ ken|consumer_?(?:id|key|secret)|sign(?:ed|ature)?|auth(?:entication|orization)?) | |
| this.isGitUploadEnabled = this.isCiVisibility && | ||
| (this.isIntelligentTestRunnerEnabled && !isFalse(DD_CIVISIBILITY_GIT_UPLOAD_ENABLED)) | ||
|
|
||
| this.isTraceGitMetadataEnabled = isTrue(DD_TRACE_GIT_METADATA_ENABLED) | ||
|
||
|
|
||
| if (this.isTraceGitMetadataEnabled) { | ||
| this.repositoryUrl = coalesce( | ||
| process.env.DD_GIT_REPOSITORY_URL, | ||
| this.tags['git.repository_url'] | ||
| ) | ||
| this.commitSHA = coalesce( | ||
| process.env.DD_GIT_COMMIT_SHA, | ||
| this.tags['git.commit.sha'] | ||
| ) | ||
| } | ||
|
|
||
| this.stats = { | ||
| enabled: isTrue(DD_TRACE_STATS_COMPUTATION_ENABLED) | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,6 +5,7 @@ const format = require('./format') | |
| const SpanSampler = require('./span_sampler') | ||
|
|
||
| const { SpanStatsProcessor } = require('./span_stats') | ||
| const { SCI_COMMIT_SHA, SCI_REPOSITORY_URL } = require('./constants') | ||
|
|
||
| const startedSpans = new WeakSet() | ||
| const finishedSpans = new WeakSet() | ||
|
|
@@ -25,14 +26,18 @@ class SpanProcessor { | |
| const active = [] | ||
| const formatted = [] | ||
| const trace = spanContext._trace | ||
| const { flushMinSpans } = this._config | ||
| const { flushMinSpans, isTraceGitMetadataEnabled } = this._config | ||
| const { started, finished } = trace | ||
|
|
||
| if (trace.record === false) return | ||
| if (started.length === finished.length || finished.length >= flushMinSpans) { | ||
| this._prioritySampler.sample(spanContext) | ||
| this._spanSampler.sample(spanContext) | ||
|
|
||
| if (isTraceGitMetadataEnabled) { | ||
| this.addRepositoryMetadata(started) | ||
| } | ||
|
|
||
| for (const span of started) { | ||
| if (span._duration !== undefined) { | ||
| const formattedSpan = format(span) | ||
|
|
@@ -59,6 +64,13 @@ class SpanProcessor { | |
| } | ||
| } | ||
|
|
||
| addRepositoryMetadata (spans) { | ||
|
||
| const { repositoryUrl, commitSHA } = this._config | ||
| const firstSpan = spans[0] | ||
| firstSpan.setTag(SCI_REPOSITORY_URL, repositoryUrl) | ||
| firstSpan.setTag(SCI_COMMIT_SHA, commitSHA) | ||
| } | ||
|
|
||
| killAll () { | ||
| this._killAll = true | ||
| } | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.