-
Notifications
You must be signed in to change notification settings - Fork 14
AppSignals Functionality - add AlwaysRecordSampler and Utility files, add pr-build workflow #9
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
Merged
Merged
Changes from 10 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
48c2f91
AppSignals Functionality - add AlwaysRecordSampler and Utility files
jj22ee 1ac03b1
add workflow files for pr_build and lint
jj22ee 5b57d2d
run markdown lint
jj22ee 75921dd
address comments
jj22ee 76ce1e7
add unit tests for files in this branch
jj22ee b8dddb8
force pr_build workflow
jj22ee f9240e5
remove test:ci:changed from pr_build workflow
jj22ee 1561d5a
fix pr_build failure for node 14
jj22ee 84c3139
actions/setup-node@v4
jj22ee 8979263
run pr_build only on main/release branches
jj22ee 733ed0a
update test comment for testIsLocalRoot
jj22ee ab89b6d
update AWS_SDK_INSTRUMENTATION_SCOPE_PREFIX value
jj22ee ffefbd0
rename pr_build.yml to pr-build.yml
jj22ee 94ca251
update comments
jj22ee File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,59 @@ | ||
name: JavaScript Instrumentation PR Build | ||
on: | ||
pull_request: | ||
branches: | ||
- main | ||
- "release/v*" | ||
|
||
permissions: | ||
id-token: write | ||
contents: read | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
fail-fast: false # ensures the entire test matrix is run, even if one permutation fails | ||
matrix: | ||
node: ["14", "16", "18", "20", "22"] | ||
env: | ||
NPM_CONFIG_UNSAFE_PERM: true | ||
steps: | ||
- name: Checkout Contrib Repo @ SHA - ${{ github.sha }} | ||
uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 | ||
- uses: actions/setup-node@v4 | ||
with: | ||
node-version: ${{ matrix.node }} | ||
|
||
- name: Update npm to a version that supports workspaces (v7 or later) | ||
jj22ee marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if: ${{ matrix.node < 16 }} | ||
run: npm install -g npm@9 # npm@9 supports node >=14.17.0 | ||
- name: Install | ||
jj22ee marked this conversation as resolved.
Show resolved
Hide resolved
|
||
run: npm ci | ||
- name: Build | ||
run: npm run compile | ||
- name: Unit tests (Full) | ||
if: matrix.code-coverage | ||
run: npm run test | ||
- name: Report Coverage | ||
if: ${{ matrix.code-coverage && !cancelled()}} | ||
uses: codecov/codecov-action@v4 | ||
with: | ||
verbose: true | ||
|
||
lint: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: actions/setup-node@v4 | ||
with: | ||
node-version: 18 | ||
cache: 'npm' | ||
- run: npm ci | ||
jj22ee marked this conversation as resolved.
Show resolved
Hide resolved
|
||
- name: Lint | ||
run: | | ||
npm run lint | ||
npm run lint:markdown | ||
npm run lint:readme |
This file contains hidden or 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,17 @@ | ||
// https://github.com/open-telemetry/opentelemetry-js-contrib/blob/d52d4218235528dcecc706867425b86bac49b1f0/.markdownlint-cli2.jsonc | ||
{ | ||
"config": { | ||
// https://github.com/DavidAnson/markdownlint/blob/main/README.md#rules--aliases | ||
"MD013": false, | ||
"MD024": false, | ||
"MD033": false, | ||
"MD041": false, | ||
// MD004/ul-style. We prefer dash, but generated CHANGELOG.md files use | ||
// asterisk. The default "consistent" is a good compromise. | ||
"MD004": { "style": "consistent" }, | ||
"MD012": false // no-multiple-blanks; disabled because common in CHANGELOG.md files | ||
jj22ee marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}, | ||
"gitignore": true, | ||
"noBanner": true, | ||
"noProgress": true | ||
} |
This file contains hidden or 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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
## Code of Conduct | ||
|
||
This project has adopted the [Amazon Open Source Code of Conduct](https://aws.github.io/code-of-conduct). | ||
For more information see the [Code of Conduct FAQ](https://aws.github.io/code-of-conduct-faq) or contact | ||
[email protected] with any additional questions or comments. | ||
<[email protected]> with any additional questions or comments. |
This file contains hidden or 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 |
---|---|---|
|
@@ -21,6 +21,7 @@ reported the issue. Please try to include as much information as you can. Detail | |
|
||
|
||
## Contributing via Pull Requests | ||
|
||
Contributions via pull requests are much appreciated. Before sending us a pull request, please ensure that: | ||
|
||
1. You are working against the latest source on the *main* branch. | ||
|
@@ -47,52 +48,61 @@ The following are useful commands that can be run within the `root` directory of | |
Use `npm install` within the root directory to initialize all package directories before running any of the following commands. | ||
|
||
### Build TypeScript into JavaScript | ||
``` | ||
|
||
```shell | ||
npm run compile | ||
``` | ||
|
||
### Lint | ||
``` | ||
|
||
```shell | ||
npm run lint | ||
``` | ||
|
||
### Lint automatic fixing | ||
``` | ||
|
||
```shell | ||
npm run lint:fix | ||
``` | ||
|
||
### Test the local ADOT JS package with your own local NodeJS project | ||
|
||
In the `./aws-distro-opentelemetry-node-autoinstrumentation` directory, run: | ||
``` | ||
|
||
```shell | ||
npm install | ||
npm run compile | ||
npm link | ||
``` | ||
|
||
In the target local NodeJS project to be instrumented, run | ||
|
||
``` | ||
```shell | ||
npm install | ||
npm link @aws/aws-distro-opentelemetry-node-autoinstrumentation | ||
``` | ||
|
||
Your NodeJS project can now be run with your local copy of the ADOT NodeJS code with: | ||
``` | ||
|
||
```shell | ||
node --require '@aws/aws-distro-opentelemetry-node-autoinstrumentation/register' your-application.js.js | ||
``` | ||
|
||
|
||
## Finding contributions to work on | ||
|
||
Looking at the existing issues is a great way to find something to contribute on. As our projects, by default, use the default GitHub issue labels (enhancement/bug/duplicate/help wanted/invalid/question/wontfix), looking at any 'help wanted' issues is a great place to start. | ||
|
||
|
||
## Code of Conduct | ||
|
||
This project has adopted the [Amazon Open Source Code of Conduct](https://aws.github.io/code-of-conduct). | ||
For more information see the [Code of Conduct FAQ](https://aws.github.io/code-of-conduct-faq) or contact | ||
[email protected] with any additional questions or comments. | ||
<[email protected]> with any additional questions or comments. | ||
|
||
|
||
## Security issue notifications | ||
|
||
If you discover a potential security issue in this project we ask that you notify AWS/Amazon Security via our [vulnerability reporting page](http://aws.amazon.com/security/vulnerability-reporting/). Please do **not** create a public github issue. | ||
|
||
|
||
|
This file contains hidden or 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 hidden or 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 hidden or 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
4 changes: 2 additions & 2 deletions
4
aws-distro-opentelemetry-node-autoinstrumentation/src/aws-opentelemetry-configurator.ts
This file contains hidden or 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 hidden or 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
4 changes: 2 additions & 2 deletions
4
aws-distro-opentelemetry-node-autoinstrumentation/src/register.ts
This file contains hidden or 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
79 changes: 79 additions & 0 deletions
79
aws-distro-opentelemetry-node-autoinstrumentation/test/always-record-sampler.test.ts
This file contains hidden or 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,79 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import { Attributes, SpanKind, TraceState, context, createTraceState } from '@opentelemetry/api'; | ||
import { | ||
AlwaysOffSampler, | ||
RandomIdGenerator, | ||
Sampler, | ||
SamplingDecision, | ||
SamplingResult, | ||
} from '@opentelemetry/sdk-trace-base'; | ||
import { expect } from 'expect'; | ||
import { AlwaysRecordSampler } from '../src/always-record-sampler'; | ||
|
||
let mockedSampler: Sampler; | ||
let sampler: AlwaysRecordSampler; | ||
|
||
describe('AlwaysRecordSamplerTest', () => { | ||
beforeEach(() => { | ||
mockedSampler = new AlwaysOffSampler(); | ||
sampler = AlwaysRecordSampler.create(mockedSampler); | ||
}); | ||
|
||
it('testGetDescription', () => { | ||
mockedSampler.toString = () => 'mockDescription'; | ||
expect(sampler.toString()).toEqual('AlwaysRecordSampler{mockDescription}'); | ||
}); | ||
|
||
it('testRecordAndSampleSamplingDecision', () => { | ||
validateShouldSample(SamplingDecision.RECORD_AND_SAMPLED, SamplingDecision.RECORD_AND_SAMPLED); | ||
}); | ||
|
||
it('testRecordOnlySamplingDecision', () => { | ||
validateShouldSample(SamplingDecision.RECORD, SamplingDecision.RECORD); | ||
}); | ||
|
||
it('testDropSamplingDecision', () => { | ||
validateShouldSample(SamplingDecision.NOT_RECORD, SamplingDecision.RECORD); | ||
}); | ||
}); | ||
|
||
function validateShouldSample(rootDecision: SamplingDecision, expectedDecision: SamplingDecision): void { | ||
const rootResult: SamplingResult = buildRootSamplingResult(rootDecision); | ||
mockedSampler.shouldSample = () => { | ||
return rootResult; | ||
}; | ||
|
||
const actualResult: SamplingResult = sampler.shouldSample( | ||
context.active(), | ||
new RandomIdGenerator().generateTraceId(), | ||
'spanName', | ||
SpanKind.CLIENT, | ||
{}, | ||
[] | ||
); | ||
|
||
if (rootDecision === expectedDecision) { | ||
expect(actualResult).toBe(rootResult); | ||
expect(actualResult.decision).toBe(rootDecision); | ||
} else { | ||
expect(actualResult).not.toBe(rootResult); | ||
expect(actualResult.decision).toBe(expectedDecision); | ||
} | ||
|
||
expect(actualResult.attributes).toEqual(rootResult.attributes); | ||
expect(actualResult.traceState).toEqual(rootResult.traceState); | ||
} | ||
|
||
function buildRootSamplingResult(samplingDecision: SamplingDecision): SamplingResult { | ||
const samplingAttr: Attributes = { key: SamplingDecision[samplingDecision] }; | ||
const samplingTraceState: TraceState = createTraceState(); | ||
samplingTraceState.set('key', SamplingDecision[samplingDecision]); | ||
const samplingResult: SamplingResult = { | ||
decision: samplingDecision, | ||
attributes: samplingAttr, | ||
traceState: samplingTraceState, | ||
}; | ||
return samplingResult; | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.