Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
4 changes: 2 additions & 2 deletions packages/dd-trace/src/plugins/util/ci.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ function filterSensitiveInfoFromRepository (repositoryUrl) {

return `${protocol}//${hostname}${pathname}`
} catch (e) {
return repositoryUrl
return ''
}
}

Expand All @@ -93,6 +93,7 @@ function resolveTilde (filePath) {
}

module.exports = {
removeEmptyValues,
normalizeRef,
getCIMetadata () {
const { env } = process
Expand Down Expand Up @@ -605,7 +606,6 @@ module.exports = {
normalizeTag(tags, GIT_REPOSITORY_URL, filterSensitiveInfoFromRepository)
normalizeTag(tags, GIT_BRANCH, normalizeRef)
normalizeTag(tags, GIT_TAG, normalizeRef)

return removeEmptyValues(tags)
}
}
37 changes: 34 additions & 3 deletions packages/dd-trace/src/plugins/util/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const ignore = require('ignore')

const { getGitMetadata } = require('./git')
const { getUserProviderGitMetadata } = require('./user-provided-git')
const { getCIMetadata } = require('./ci')
const { getCIMetadata, removeEmptyValues } = require('./ci')
const { getRuntimeAndOSMetadata } = require('./env')
const {
GIT_BRANCH,
Expand All @@ -16,14 +16,15 @@ const {
GIT_COMMIT_AUTHOR_EMAIL,
GIT_COMMIT_AUTHOR_NAME,
GIT_COMMIT_MESSAGE,
CI_WORKSPACE_PATH
CI_WORKSPACE_PATH, CI_PIPELINE_URL
} = require('./tags')
const id = require('../../id')

const { SPAN_TYPE, RESOURCE_NAME, SAMPLING_PRIORITY } = require('../../../../../ext/tags')
const { SAMPLING_RULE_DECISION } = require('../../constants')
const { AUTO_KEEP } = require('../../../../../ext/priority')
const { version: ddTraceVersion } = require('../../../../../package.json')
const { URL } = require('url')

const TEST_FRAMEWORK = 'test.framework'
const TEST_FRAMEWORK_VERSION = 'test.framework_version'
Expand Down Expand Up @@ -116,6 +117,35 @@ function getPkgManager () {
}
}

function validateMetadata (metadata) {
if (GIT_REPOSITORY_URL in metadata && metadata[GIT_REPOSITORY_URL]) {
const validUrl = validateUrl(metadata[GIT_REPOSITORY_URL])
if (!validUrl) {
delete metadata[GIT_REPOSITORY_URL]
}
}
if (CI_PIPELINE_URL in metadata && metadata[CI_PIPELINE_URL]) {
const validUrl = validateUrl(metadata[CI_PIPELINE_URL])
if (!validUrl) {
delete metadata[CI_PIPELINE_URL]
}
}
return removeEmptyValues(metadata)
}

function validateUrl (url) {
if (url.startsWith('git@') && url.includes(':')) {
const hostname = url.substring(url.indexOf('@') + 1, url.lastIndexOf(':'))
return hostname.includes('.')
}
try {
const urlObject = new URL(url)
return (urlObject.protocol === 'https:' || urlObject.protocol === 'http:')
} catch (e) {
return false
}
}

function getTestEnvironmentMetadata (testFramework, config) {
// TODO: eventually these will come from the tracer (generally available)
const ciMetadata = getCIMetadata()
Expand Down Expand Up @@ -145,13 +175,14 @@ function getTestEnvironmentMetadata (testFramework, config) {

const runtimeAndOSMetadata = getRuntimeAndOSMetadata()

const metadata = {
let metadata = {
[TEST_FRAMEWORK]: testFramework,
...gitMetadata,
...ciMetadata,
...userProvidedGitMetadata,
...runtimeAndOSMetadata
}
metadata = validateMetadata(metadata)
if (config && config.service) {
metadata['service.name'] = config.service
}
Expand Down
180 changes: 90 additions & 90 deletions packages/dd-trace/test/plugins/util/ci-env/azurepipelines.json

Large diffs are not rendered by default.

56 changes: 28 additions & 28 deletions packages/dd-trace/test/plugins/util/ci-env/bitbucket.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"BITBUCKET_BUILD_NUMBER": "bitbucket-build-num",
"BITBUCKET_CLONE_DIR": "/foo/bar",
"BITBUCKET_COMMIT": "bitbucket-commit",
"BITBUCKET_GIT_SSH_ORIGIN": "bitbucket-repo-url",
"BITBUCKET_GIT_SSH_ORIGIN": "https://bitbucket-repo-url.com/",
"BITBUCKET_PIPELINE_UUID": "{bitbucket-uuid}",
"BITBUCKET_REPO_FULL_NAME": "bitbucket-repo"
},
Expand All @@ -19,7 +19,7 @@
"ci.workspace_path": "/foo/bar",
"git.branch": "master",
"git.commit.sha": "bitbucket-commit",
"git.repository_url": "bitbucket-repo-url"
"git.repository_url": "https://bitbucket-repo-url.com/"
}
],
[
Expand All @@ -28,7 +28,7 @@
"BITBUCKET_BUILD_NUMBER": "bitbucket-build-num",
"BITBUCKET_CLONE_DIR": "foo/bar",
"BITBUCKET_COMMIT": "bitbucket-commit",
"BITBUCKET_GIT_SSH_ORIGIN": "bitbucket-repo-url",
"BITBUCKET_GIT_SSH_ORIGIN": "https://bitbucket-repo-url.com/",
"BITBUCKET_PIPELINE_UUID": "{bitbucket-uuid}",
"BITBUCKET_REPO_FULL_NAME": "bitbucket-repo"
},
Expand All @@ -42,7 +42,7 @@
"ci.workspace_path": "foo/bar",
"git.branch": "master",
"git.commit.sha": "bitbucket-commit",
"git.repository_url": "bitbucket-repo-url"
"git.repository_url": "https://bitbucket-repo-url.com/"
}
],
[
Expand All @@ -51,7 +51,7 @@
"BITBUCKET_BUILD_NUMBER": "bitbucket-build-num",
"BITBUCKET_CLONE_DIR": "/foo/bar~",
"BITBUCKET_COMMIT": "bitbucket-commit",
"BITBUCKET_GIT_SSH_ORIGIN": "bitbucket-repo-url",
"BITBUCKET_GIT_SSH_ORIGIN": "https://bitbucket-repo-url.com/",
"BITBUCKET_PIPELINE_UUID": "{bitbucket-uuid}",
"BITBUCKET_REPO_FULL_NAME": "bitbucket-repo"
},
Expand All @@ -65,7 +65,7 @@
"ci.workspace_path": "/foo/bar~",
"git.branch": "master",
"git.commit.sha": "bitbucket-commit",
"git.repository_url": "bitbucket-repo-url"
"git.repository_url": "https://bitbucket-repo-url.com/"
}
],
[
Expand All @@ -74,7 +74,7 @@
"BITBUCKET_BUILD_NUMBER": "bitbucket-build-num",
"BITBUCKET_CLONE_DIR": "/foo/~/bar",
"BITBUCKET_COMMIT": "bitbucket-commit",
"BITBUCKET_GIT_SSH_ORIGIN": "bitbucket-repo-url",
"BITBUCKET_GIT_SSH_ORIGIN": "https://bitbucket-repo-url.com/",
"BITBUCKET_PIPELINE_UUID": "{bitbucket-uuid}",
"BITBUCKET_REPO_FULL_NAME": "bitbucket-repo"
},
Expand All @@ -88,7 +88,7 @@
"ci.workspace_path": "/foo/~/bar",
"git.branch": "master",
"git.commit.sha": "bitbucket-commit",
"git.repository_url": "bitbucket-repo-url"
"git.repository_url": "https://bitbucket-repo-url.com/"
}
],
[
Expand All @@ -97,7 +97,7 @@
"BITBUCKET_BUILD_NUMBER": "bitbucket-build-num",
"BITBUCKET_CLONE_DIR": "~/foo/bar",
"BITBUCKET_COMMIT": "bitbucket-commit",
"BITBUCKET_GIT_SSH_ORIGIN": "bitbucket-repo-url",
"BITBUCKET_GIT_SSH_ORIGIN": "https://bitbucket-repo-url.com/",
"BITBUCKET_PIPELINE_UUID": "{bitbucket-uuid}",
"BITBUCKET_REPO_FULL_NAME": "bitbucket-repo",
"HOME": "/not-my-home",
Expand All @@ -113,7 +113,7 @@
"ci.workspace_path": "/not-my-home/foo/bar",
"git.branch": "master",
"git.commit.sha": "bitbucket-commit",
"git.repository_url": "bitbucket-repo-url"
"git.repository_url": "https://bitbucket-repo-url.com/"
}
],
[
Expand All @@ -122,7 +122,7 @@
"BITBUCKET_BUILD_NUMBER": "bitbucket-build-num",
"BITBUCKET_CLONE_DIR": "~foo/bar",
"BITBUCKET_COMMIT": "bitbucket-commit",
"BITBUCKET_GIT_SSH_ORIGIN": "bitbucket-repo-url",
"BITBUCKET_GIT_SSH_ORIGIN": "https://bitbucket-repo-url.com/",
"BITBUCKET_PIPELINE_UUID": "{bitbucket-uuid}",
"BITBUCKET_REPO_FULL_NAME": "bitbucket-repo"
},
Expand All @@ -136,7 +136,7 @@
"ci.workspace_path": "~foo/bar",
"git.branch": "master",
"git.commit.sha": "bitbucket-commit",
"git.repository_url": "bitbucket-repo-url"
"git.repository_url": "https://bitbucket-repo-url.com/"
}
],
[
Expand All @@ -145,7 +145,7 @@
"BITBUCKET_BUILD_NUMBER": "bitbucket-build-num",
"BITBUCKET_CLONE_DIR": "~",
"BITBUCKET_COMMIT": "bitbucket-commit",
"BITBUCKET_GIT_SSH_ORIGIN": "bitbucket-repo-url",
"BITBUCKET_GIT_SSH_ORIGIN": "https://bitbucket-repo-url.com/",
"BITBUCKET_PIPELINE_UUID": "{bitbucket-uuid}",
"BITBUCKET_REPO_FULL_NAME": "bitbucket-repo",
"HOME": "/not-my-home",
Expand All @@ -161,7 +161,7 @@
"ci.workspace_path": "/not-my-home",
"git.branch": "master",
"git.commit.sha": "bitbucket-commit",
"git.repository_url": "bitbucket-repo-url"
"git.repository_url": "https://bitbucket-repo-url.com/"
}
],
[
Expand All @@ -170,7 +170,7 @@
"BITBUCKET_BUILD_NUMBER": "bitbucket-build-num",
"BITBUCKET_CLONE_DIR": "/foo/bar",
"BITBUCKET_COMMIT": "bitbucket-commit",
"BITBUCKET_GIT_SSH_ORIGIN": "bitbucket-repo-url",
"BITBUCKET_GIT_SSH_ORIGIN": "https://bitbucket-repo-url.com/",
"BITBUCKET_PIPELINE_UUID": "{bitbucket-uuid}",
"BITBUCKET_REPO_FULL_NAME": "bitbucket-repo"
},
Expand All @@ -184,7 +184,7 @@
"ci.workspace_path": "/foo/bar",
"git.branch": "master",
"git.commit.sha": "bitbucket-commit",
"git.repository_url": "bitbucket-repo-url"
"git.repository_url": "https://bitbucket-repo-url.com/"
}
],
[
Expand All @@ -193,7 +193,7 @@
"BITBUCKET_BUILD_NUMBER": "bitbucket-build-num",
"BITBUCKET_CLONE_DIR": "/foo/bar",
"BITBUCKET_COMMIT": "bitbucket-commit",
"BITBUCKET_GIT_SSH_ORIGIN": "bitbucket-repo-url",
"BITBUCKET_GIT_SSH_ORIGIN": "https://bitbucket-repo-url.com/",
"BITBUCKET_PIPELINE_UUID": "{bitbucket-uuid}",
"BITBUCKET_REPO_FULL_NAME": "bitbucket-repo"
},
Expand All @@ -207,7 +207,7 @@
"ci.workspace_path": "/foo/bar",
"git.branch": "master",
"git.commit.sha": "bitbucket-commit",
"git.repository_url": "bitbucket-repo-url"
"git.repository_url": "https://bitbucket-repo-url.com/"
}
],
[
Expand All @@ -216,7 +216,7 @@
"BITBUCKET_BUILD_NUMBER": "bitbucket-build-num",
"BITBUCKET_CLONE_DIR": "/foo/bar",
"BITBUCKET_COMMIT": "bitbucket-commit",
"BITBUCKET_GIT_SSH_ORIGIN": "bitbucket-repo-url",
"BITBUCKET_GIT_SSH_ORIGIN": "https://bitbucket-repo-url.com/",
"BITBUCKET_PIPELINE_UUID": "{bitbucket-uuid}",
"BITBUCKET_REPO_FULL_NAME": "bitbucket-repo"
},
Expand All @@ -230,7 +230,7 @@
"ci.workspace_path": "/foo/bar",
"git.branch": "master",
"git.commit.sha": "bitbucket-commit",
"git.repository_url": "bitbucket-repo-url"
"git.repository_url": "https://bitbucket-repo-url.com/"
}
],
[
Expand All @@ -239,7 +239,7 @@
"BITBUCKET_BUILD_NUMBER": "bitbucket-build-num",
"BITBUCKET_CLONE_DIR": "/foo/bar",
"BITBUCKET_COMMIT": "bitbucket-commit",
"BITBUCKET_GIT_SSH_ORIGIN": "bitbucket-repo-url",
"BITBUCKET_GIT_SSH_ORIGIN": "https://bitbucket-repo-url.com/",
"BITBUCKET_PIPELINE_UUID": "{bitbucket-uuid}",
"BITBUCKET_REPO_FULL_NAME": "bitbucket-repo"
},
Expand All @@ -253,15 +253,15 @@
"ci.workspace_path": "/foo/bar",
"git.branch": "feature/one",
"git.commit.sha": "bitbucket-commit",
"git.repository_url": "bitbucket-repo-url"
"git.repository_url": "https://bitbucket-repo-url.com/"
}
],
[
{
"BITBUCKET_BUILD_NUMBER": "bitbucket-build-num",
"BITBUCKET_CLONE_DIR": "/foo/bar",
"BITBUCKET_COMMIT": "bitbucket-commit",
"BITBUCKET_GIT_SSH_ORIGIN": "bitbucket-repo-url",
"BITBUCKET_GIT_SSH_ORIGIN": "https://bitbucket-repo-url.com/",
"BITBUCKET_PIPELINE_UUID": "{bitbucket-uuid}",
"BITBUCKET_REPO_FULL_NAME": "bitbucket-repo",
"BITBUCKET_TAG": "origin/tags/0.1.0"
Expand All @@ -275,7 +275,7 @@
"ci.provider.name": "bitbucket",
"ci.workspace_path": "/foo/bar",
"git.commit.sha": "bitbucket-commit",
"git.repository_url": "bitbucket-repo-url",
"git.repository_url": "https://bitbucket-repo-url.com/",
"git.tag": "0.1.0"
}
],
Expand All @@ -284,7 +284,7 @@
"BITBUCKET_BUILD_NUMBER": "bitbucket-build-num",
"BITBUCKET_CLONE_DIR": "/foo/bar",
"BITBUCKET_COMMIT": "bitbucket-commit",
"BITBUCKET_GIT_SSH_ORIGIN": "bitbucket-repo-url",
"BITBUCKET_GIT_SSH_ORIGIN": "https://bitbucket-repo-url.com/",
"BITBUCKET_PIPELINE_UUID": "{bitbucket-uuid}",
"BITBUCKET_REPO_FULL_NAME": "bitbucket-repo",
"BITBUCKET_TAG": "refs/heads/tags/0.1.0"
Expand All @@ -298,15 +298,15 @@
"ci.provider.name": "bitbucket",
"ci.workspace_path": "/foo/bar",
"git.commit.sha": "bitbucket-commit",
"git.repository_url": "bitbucket-repo-url",
"git.repository_url": "https://bitbucket-repo-url.com/",
"git.tag": "0.1.0"
}
],
[
{
"BITBUCKET_BUILD_NUMBER": "bitbucket-build-num",
"BITBUCKET_COMMIT": "bitbucket-commit",
"BITBUCKET_GIT_SSH_ORIGIN": "bitbucket-repo-url",
"BITBUCKET_GIT_SSH_ORIGIN": "https://bitbucket-repo-url.com/",
"BITBUCKET_PIPELINE_UUID": "{bitbucket-uuid}",
"BITBUCKET_REPO_FULL_NAME": "bitbucket-repo",
"DD_GIT_BRANCH": "user-supplied-branch",
Expand Down Expand Up @@ -343,7 +343,7 @@
{
"BITBUCKET_BUILD_NUMBER": "bitbucket-build-num",
"BITBUCKET_COMMIT": "bitbucket-commit",
"BITBUCKET_GIT_SSH_ORIGIN": "bitbucket-repo-url",
"BITBUCKET_GIT_SSH_ORIGIN": "https://bitbucket-repo-url.com/",
"BITBUCKET_PIPELINE_UUID": "{bitbucket-uuid}",
"BITBUCKET_REPO_FULL_NAME": "bitbucket-repo",
"DD_GIT_COMMIT_AUTHOR_DATE": "usersupplied-authordate",
Expand Down
Loading