-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: Reduce dependencies and binary size, add circle ci detector (#…
…26522) * chore: add circle ci detector * update deps * adjust deps and cleanup binary? * Add Tests * fix tests, keep artifact * Apply suggestions from code review Co-authored-by: Bill Glesias <bglesias@gmail.com> --------- Co-authored-by: Bill Glesias <bglesias@gmail.com>
- Loading branch information
1 parent
1ed2031
commit 2a8d078
Showing
7 changed files
with
239 additions
and
892 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import type { DetectorSync, ResourceAttributes, IResource } from '@opentelemetry/resources' | ||
import { Resource } from '@opentelemetry/resources' | ||
|
||
/** | ||
* CircleCiDetectorSync can be used to detect the presence of and create a Resource | ||
* from circle ci env variables. | ||
*/ | ||
class CircleCiDetectorSync implements DetectorSync { | ||
/** | ||
* Returns a {@link Resource} populated with attributes from the | ||
* circle ci environment variable. | ||
* | ||
* @param config The resource detection config -- ignored | ||
*/ | ||
detect (): IResource { | ||
const attributes: ResourceAttributes = {} | ||
|
||
const { CIRCLECI, CIRCLE_BRANCH, CIRCLE_JOB, CIRCLE_NODE_INDEX, CIRCLE_BUILD_URL, CIRCLE_BUILD_NUM, CIRCLE_SHA1, CIRCLE_PR_NUMBER } = process.env | ||
|
||
if (CIRCLECI) { | ||
attributes['ci.circle'] = CIRCLECI | ||
attributes['ci.branch'] = CIRCLE_BRANCH | ||
attributes['ci.job'] = CIRCLE_JOB | ||
attributes['ci.node'] = CIRCLE_NODE_INDEX | ||
attributes['ci.build-url'] = CIRCLE_BUILD_URL | ||
attributes['ci.build-number'] = CIRCLE_BUILD_NUM | ||
attributes['SHA1'] = CIRCLE_SHA1 | ||
attributes['ci.pr-number'] = CIRCLE_PR_NUMBER | ||
} | ||
|
||
return new Resource(attributes) | ||
} | ||
} | ||
|
||
export const circleCiDetectorSync = new CircleCiDetectorSync() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
107 changes: 107 additions & 0 deletions
107
packages/telemetry/test/detectors/circleCiDetectorSync.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
import { expect } from 'chai' | ||
|
||
|
||
import { circleCiDetectorSync } from '../../src/detectors/circleCiDetectorSync' | ||
|
||
describe('circleCiDetectorSync', () => { | ||
describe('undefined values', () => { | ||
const processValues: any = {} | ||
|
||
beforeEach(() => { | ||
// cache values | ||
processValues.CIRCLECI = process.env.CIRCLECI | ||
processValues.CIRCLE_BRANCH = process.env.CIRCLE_BRANCH | ||
processValues.CIRCLE_JOB = process.env.CIRCLE_JOB | ||
processValues.CIRCLE_NODE_INDEX = process.env.CIRCLE_NODE_INDEX | ||
processValues.CIRCLE_BUILD_URL = process.env.CIRCLE_BUILD_URL | ||
processValues.CIRCLE_BUILD_NUM = process.env.CIRCLE_BUILD_NUM | ||
processValues.CIRCLE_SHA1 = process.env.CIRCLE_SHA1 | ||
processValues.CIRCLE_PR_NUMBER = process.env.CIRCLE_PR_NUMBER | ||
|
||
//reset values | ||
delete process.env.CIRCLECI | ||
delete process.env.CIRCLE_BRANCH | ||
delete process.env.CIRCLE_JOB | ||
delete process.env.CIRCLE_NODE_INDEX | ||
delete process.env.CIRCLE_BUILD_URL | ||
delete process.env.CIRCLE_BUILD_NUM | ||
delete process.env.CIRCLE_SHA1 | ||
delete process.env.CIRCLE_PR_NUMBER | ||
}) | ||
|
||
afterEach(() => { | ||
// Replace values | ||
process.env.CIRCLECI = processValues.CIRCLECI | ||
process.env.CIRCLE_BRANCH = processValues.CIRCLE_BRANCH | ||
process.env.CIRCLE_JOB = processValues.CIRCLE_JOB | ||
process.env.CIRCLE_NODE_INDEX = processValues.CIRCLE_NODE_INDEX | ||
process.env.CIRCLE_BUILD_URL = processValues.CIRCLE_BUILD_URL | ||
process.env.CIRCLE_BUILD_NUM = processValues.CIRCLE_BUILD_NUM | ||
process.env.CIRCLE_SHA1 = processValues.CIRCLE_SHA1 | ||
process.env.CIRCLE_PR_NUMBER = processValues.CIRCLE_PR_NUMBER | ||
}) | ||
|
||
describe('detect', () => { | ||
it('returns an empty resource', () => { | ||
const resource = circleCiDetectorSync.detect() | ||
|
||
expect(resource.attributes).to.be.empty | ||
}) | ||
}) | ||
}) | ||
|
||
describe('defined values', () => { | ||
const processValues: any = {} | ||
|
||
beforeEach(() => { | ||
// cache values | ||
processValues.CIRCLECI = process.env.CIRCLECI | ||
processValues.CIRCLE_BRANCH = process.env.CIRCLE_BRANCH | ||
processValues.CIRCLE_JOB = process.env.CIRCLE_JOB | ||
processValues.CIRCLE_NODE_INDEX = process.env.CIRCLE_NODE_INDEX | ||
processValues.CIRCLE_BUILD_URL = process.env.CIRCLE_BUILD_URL | ||
processValues.CIRCLE_BUILD_NUM = process.env.CIRCLE_BUILD_NUM | ||
processValues.CIRCLE_SHA1 = process.env.CIRCLE_SHA1 | ||
processValues.CIRCLE_PR_NUMBER = process.env.CIRCLE_PR_NUMBER | ||
|
||
//reset values | ||
process.env.CIRCLECI = 'circleCi' | ||
process.env.CIRCLE_BRANCH = 'circleBranch' | ||
process.env.CIRCLE_JOB = 'circleJob' | ||
process.env.CIRCLE_NODE_INDEX = 'circleNodeIndex' | ||
process.env.CIRCLE_BUILD_URL = 'circleBuildUrl' | ||
process.env.CIRCLE_BUILD_NUM = 'circleBuildNum' | ||
process.env.CIRCLE_SHA1 = 'circleSha1' | ||
process.env.CIRCLE_PR_NUMBER = 'circlePrNumber' | ||
}) | ||
|
||
afterEach(() => { | ||
// Replace values | ||
process.env.CIRCLECI = processValues.CIRCLECI | ||
process.env.CIRCLE_BRANCH = processValues.CIRCLE_BRANCH | ||
process.env.CIRCLE_JOB = processValues.CIRCLE_JOB | ||
process.env.CIRCLE_NODE_INDEX = processValues.CIRCLE_NODE_INDEX | ||
process.env.CIRCLE_BUILD_URL = processValues.CIRCLE_BUILD_URL | ||
process.env.CIRCLE_BUILD_NUM = processValues.CIRCLE_BUILD_NUM | ||
process.env.CIRCLE_SHA1 = processValues.CIRCLE_SHA1 | ||
process.env.CIRCLE_PR_NUMBER = processValues.CIRCLE_PR_NUMBER | ||
}) | ||
|
||
describe('detect', () => { | ||
it('returns a resource with attributes', () => { | ||
const resource = circleCiDetectorSync.detect() | ||
|
||
console.log(resource.attributes) | ||
|
||
expect(resource.attributes['ci.circle']).to.equal('circleCi') | ||
expect(resource.attributes['ci.branch']).to.equal('circleBranch') | ||
expect(resource.attributes['ci.job']).to.equal('circleJob') | ||
expect(resource.attributes['ci.node']).to.equal('circleNodeIndex') | ||
expect(resource.attributes['ci.build-url']).to.equal('circleBuildUrl') | ||
expect(resource.attributes['ci.build-number']).to.equal('circleBuildNum') | ||
expect(resource.attributes['SHA1']).to.equal('circleSha1') | ||
expect(resource.attributes['ci.pr-number']).to.equal('circlePrNumber') | ||
}) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
2a8d078
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Circle has built the
linux arm64
version of the Test Runner.Learn more about this pre-release build at https://on.cypress.io/advanced-installation#Install-pre-release-version
Run this command to install the pre-release locally:
2a8d078
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Circle has built the
linux x64
version of the Test Runner.Learn more about this pre-release build at https://on.cypress.io/advanced-installation#Install-pre-release-version
Run this command to install the pre-release locally:
2a8d078
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Circle has built the
darwin arm64
version of the Test Runner.Learn more about this pre-release build at https://on.cypress.io/advanced-installation#Install-pre-release-version
Run this command to install the pre-release locally:
2a8d078
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Circle has built the
darwin x64
version of the Test Runner.Learn more about this pre-release build at https://on.cypress.io/advanced-installation#Install-pre-release-version
Run this command to install the pre-release locally:
2a8d078
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Circle has built the
win32 x64
version of the Test Runner.Learn more about this pre-release build at https://on.cypress.io/advanced-installation#Install-pre-release-version
Run this command to install the pre-release locally: