
Security News
TC39 Advances 11 Proposals for Math Precision, Binary APIs, and More
TC39 advances 11 JavaScript proposals, with two moving to Stage 4, bringing better math, binary APIs, and more features one step closer to the ECMAScript spec.
@codecov/node-codecov-opentelemetry
Advanced tools
This package is intended to support Codecov's [Impact Analysis](https://docs.codecov.com/docs/impact-analysis) feature.
This package is intended to support Codecov's Impact Analysis feature.
Note that this packaged requires, at minimum, Node 15.1.0 due to the inclusion of v8.takeCoverage(). See https://nodejs.org/api/v8.html#v8_v8_takecoverage.
Install dependencies:
npm install @codecov/node-codecov-opentelemetry
Set environment variable for coverage export. You will not need to access this directory yourself, but the application will read coverage reports from this directory:
export NODE_V8_COVERAGE=codecov_reports
An example application is included in this repository, it can be run as follows:
node examples/app.js
IMPORTANT: Be sure you're running Node JS 15.1 or above. Any version beneath this one will not have the interface to V8 required to collect traces.
The following code should be used in the startup of your application, typically this is app.js
. For a basic express app, it would look as follows:
// Include Dependencies
const { CodeCovOpenTelemetry } = require('@codecov/node-codecov-opentelemetry');
const { NodeTracerProvider } = require('@opentelemetry/sdk-trace-node');
const { BatchSpanProcessor } = require("@opentelemetry/sdk-trace-base");
const { SpanKind } = require("@opentelemetry/api");
// Setup OpenTelemetry
const sampleRate = 1;
const untrackedExportRate = 1;
const code = 'production::v0.0.1' //<environment>::<versionIdentifier>
const provider = new NodeTracerProvider();
provider.register();
// Setup Codecov OTEL
const codecov = new CodeCovOpenTelemetry(
{
repositoryToken: "your-impact-analysis-token", //from repository settings page on Codecov.
environment: "production", //or others as appropriate
versionIdentifier: "v0.0.1", //semver, commit SHA, etc
filters: {
allowedSpanKinds: [SpanKind.SERVER],
},
codecovEndpoint: "api.codecov.io",
sampleRate,
untrackedExportRate,
code
}
)
provider.addSpanProcessor(codecov.processor);
provider.addSpanProcessor(new BatchSpanProcessor(codecov.exporter))
Once initialized, your application can continue as expected:
//...example express setup
const express = require('express');
const port = 3000;
const app = express();
app.get('/', (req, res) => {
res.send('Hello World!');
})
takeCoverage
This package relies heavily on the takeCoverage
and other supporting methods added to with Node 15.1.0. While these methods are generally useful and allow Impact Analysis to function properly, there are some caveats to consider:
takeCoverage
again and again and using snapshots), coverage tracking cannot be paused, and may run in a way that poses an impact on performance.
stopCoverage
is not a possibility, because once stopCoverage
is called, takeCoverage
raises errors.takeCoverage()
et al being native.NODE_V8_COVERAGE
could be mapped to memory, that could be more performant solution.spancontext
as a function, but that is not a function. Before fielding this in a production context, opentelemetry-js will need a fix.
// ...
{
"scriptId": "115",
"url": "file:///Users/thiagorramos/Projects/opentelem-node/examples/app.js",
"functions": [
{
"functionName": "",
"ranges": [
{
"startOffset": 1062,
"endOffset": 1107,
"count": 1
}
],
"isBlockCoverage": true
}
]
}
// ...
which shows byte ranges (1062 to 1107 in this case). This means that coverage is on the statement block level, rather than line coverage. To compensate for this discrepancy, for now, this package assumes that if bytes A to B involve lines C to D, then all lines from C to D are covered. 6. This package assumes that the "byte intervals" that show up in node coverage are presented in pre-order when looking at the interval tree. This package makes no assumption that byte intervals are presented in pre-order, and thus will reorder if needed, However, the package still assumes they are tree intervals and that there will be no unusual overlaps (as in, two intervals that overlap but are not contained one inside another).
app.get('/hello', (req, res) => {
console.log("WE ARE INSIDE THE REQUEST")
res.send('SPECIAL Hello ' + req.query.name + req.query.value);
let a = parseInt(req.query.value);
let b = a + b;
if (a > 10) {
console.log("It's higher than 10")
// some extra logic
}
}
Opentelemetry will execute onEnd
right after res.send
happens. Which means that it won't wait for the extra logic to run.
let a ...;
) and 69 (let b = ...;
) are in the same statement block as line 66 (console.log("WE...")
). Due to the async nature of js, coverage stopped tracking before they were executed, so they should not show up on the coverage result. But they do, because since line 66 was executed, and they are part of the same statement block, it doesn't make sense for them to not have been executed.if
statement on line 70, for example. Line 71 (console.log("It's higher...")
) also clearly runs on some cases (where a > 10
), but is always considered not covered on the reports, because it is on a separate statement block and happens after a res.send
.FAQs
This package is intended to support Codecov's [Impact Analysis](https://docs.codecov.com/docs/impact-analysis) feature.
The npm package @codecov/node-codecov-opentelemetry receives a total of 0 weekly downloads. As such, @codecov/node-codecov-opentelemetry popularity was classified as not popular.
We found that @codecov/node-codecov-opentelemetry demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
TC39 advances 11 JavaScript proposals, with two moving to Stage 4, bringing better math, binary APIs, and more features one step closer to the ECMAScript spec.
Research
/Security News
A flawed sandbox in @nestjs/devtools-integration lets attackers run code on your machine via CSRF, leading to full Remote Code Execution (RCE).
Product
Customize license detection with Socket’s new license overlays: gain control, reduce noise, and handle edge cases with precision.