Skip to content

Commit

Permalink
initial fs support (#814)
Browse files Browse the repository at this point in the history
* initial fs support

* allow `yarn lint --fix`

* support large payloads in test agent

* don't trace fs operations unless there's a parent span
  • Loading branch information
bengl committed Jan 23, 2020
1 parent 147520b commit 34beab0
Show file tree
Hide file tree
Showing 15 changed files with 2,572 additions and 7 deletions.
27 changes: 27 additions & 0 deletions .circleci/config.yml
Expand Up @@ -339,6 +339,27 @@ jobs:
environment:
- PLUGINS=fastify

node-fs-8:
<<: *node-plugin-base
docker:
- image: node:8
environment:
- PLUGINS=fs

node-fs-10:
<<: *node-plugin-base
docker:
- image: node:10
environment:
- PLUGINS=fs

node-fs-12:
<<: *node-plugin-base
docker:
- image: node:12
environment:
- PLUGINS=fs

node-generic-pool:
<<: *node-plugin-base
docker:
Expand Down Expand Up @@ -818,6 +839,9 @@ workflows:
- node-elasticsearch
- node-express
- node-fastify
- node-fs-8
- node-fs-10
- node-fs-12
- node-generic-pool
- node-graphql
- node-grpc
Expand Down Expand Up @@ -969,6 +993,9 @@ workflows:
- node-elasticsearch
- node-express
- node-fastify
- node-fs-8
- node-fs-10
- node-fs-12
- node-generic-pool
- node-graphql
- node-grpc
Expand Down
2 changes: 1 addition & 1 deletion .eslintrc.json
@@ -1,6 +1,6 @@
{
"parserOptions": {
"ecmaVersion": 2017
"ecmaVersion": 2018
},
"extends": [
"eslint:recommended",
Expand Down
1 change: 1 addition & 0 deletions LICENSE-3rdparty.csv
Expand Up @@ -59,6 +59,7 @@ dev,nock,MIT,Copyright 2017 Pedro Teixeira and other contributors
dev,nyc,ISC,Copyright 2015 Contributors
dev,proxyquire,MIT,Copyright 2013 Thorsten Lorenz
dev,retry,MIT,Copyright 2011 Tim Koschützki Felix Geisendörfer
dev,rimraf,ISC,Copyright Isaac Z. Schlueter and Contributors
dev,semver,ISC,Copyright Isaac Z. Schlueter and Contributors
dev,sinon,BSD-3-Clause,Copyright 2010-2017 Christian Johansen
dev,sinon-chai,WTFPL and BSD-2-Clause,Copyright 2004 Sam Hocevar 2012–2017 Domenic Denicola
Expand Down
2 changes: 2 additions & 0 deletions docs/API.md
Expand Up @@ -217,6 +217,7 @@ tracer.use('pg', {
<h5 id="express-config"></h5>
<h5 id="generic-pool"></h5>
<h5 id="fastify"></h5>
<h5 id="fs"></h5>
<h5 id="graphql"></h5>
<h5 id="graphql-tags"></h5>
<h5 id="graphql-config"></h5>
Expand Down Expand Up @@ -276,6 +277,7 @@ tracer.use('pg', {
* [elasticsearch](./interfaces/plugins.elasticsearch.html)
* [express](./interfaces/plugins.express.html)
* [fastify](./interfaces/plugins.fastify.html)
* [fs](./interfaces/plugins.fs.html)
* [generic-pool](./interfaces/plugins.generic_pool.html)
* [graphql](./interfaces/plugins.graphql.html)
* [grpc](./interfaces/plugins.grpc.html)
Expand Down
1 change: 1 addition & 0 deletions docs/test.ts
Expand Up @@ -138,6 +138,7 @@ tracer.use('express');
tracer.use('express', httpServerOptions);
tracer.use('fastify');
tracer.use('fastify', httpServerOptions);
tracer.use('fs');
tracer.use('generic-pool');
tracer.use('graphql', graphqlOptions);
tracer.use('graphql', { variables: ['foo', 'bar'] });
Expand Down
19 changes: 18 additions & 1 deletion index.d.ts
Expand Up @@ -69,6 +69,9 @@ export declare interface Tracer extends opentracing.Tracer {
* span will finish when that callback is called.
* * The function doesn't accept a callback and doesn't return a promise, in
* which case the span will finish at the end of the function execution.
*
* If the `orphanable` option is set to false, the function will not be traced
* unless there is already an active span or `childOf` option.
*/
trace<T>(name: string, fn: (span?: Span, fn?: (error?: Error) => any) => T): T;
trace<T>(name: string, options: TraceOptions & SpanOptions, fn: (span?: Span, done?: (error?: Error) => string) => T): T;
Expand All @@ -87,8 +90,9 @@ export declare interface Tracer extends opentracing.Tracer {
* * The function doesn't accept a callback and doesn't return a promise, in
* which case the span will finish at the end of the function execution.
*/
wrap<T = (...args: any[]) => any>(name: string, fn: T): T;
wrap<T = (...args: any[]) => any>(name: string, fn: T, requiresParent?: boolean): T;
wrap<T = (...args: any[]) => any>(name: string, options: TraceOptions & SpanOptions, fn: T): T;
wrap<T = (...args: any[]) => any>(name: string, options: (...args: any[]) => TraceOptions & SpanOptions, fn: T): T;
}

export declare interface TraceOptions extends Analyzable {
Expand Down Expand Up @@ -348,6 +352,12 @@ export declare interface TracerOptions {
* @default 'debug'
*/
logLevel?: 'error' | 'debug'

/**
* If false, require a parent in order to trace.
* @default true
*/
orphanable?: boolean
}

/** @hidden */
Expand Down Expand Up @@ -419,6 +429,7 @@ interface Plugins {
"elasticsearch": plugins.elasticsearch;
"express": plugins.express;
"fastify": plugins.fastify;
"fs": plugins.fs;
"generic-pool": plugins.generic_pool;
"graphql": plugins.graphql;
"grpc": plugins.grpc;
Expand Down Expand Up @@ -680,6 +691,12 @@ declare namespace plugins {
*/
interface fastify extends HttpServer {}

/**
* This plugin automatically instruments the
* [fs](https://nodejs.org/api/fs.html) module.
*/
interface fs extends Instrumentation {}

/**
* This plugin patches the [generic-pool](https://github.com/coopernurse/node-pool)
* module to bind the callbacks the the caller context.
Expand Down
3 changes: 2 additions & 1 deletion package.json
Expand Up @@ -17,7 +17,7 @@
"bench": "node benchmark",
"type:doc": "cd docs && yarn && yarn build",
"type:test": "cd docs && yarn && yarn test",
"lint": "eslint . && node scripts/check_licenses.js",
"lint": "node scripts/check_licenses.js && eslint .",
"services": "node ./scripts/install_plugin_modules && node packages/dd-trace/test/setup/services",
"tdd": "node scripts/tdd.js",
"test": "SERVICES=* yarn services && mocha --exit --expose-gc 'packages/dd-trace/test/setup/node.js' 'packages/*/test/**/*.spec.js'",
Expand Down Expand Up @@ -112,6 +112,7 @@
"nyc": "^14.1.1",
"proxyquire": "^1.8.0",
"retry": "^0.10.1",
"rimraf": "^3.0.0",
"sinon": "^8.0.4",
"sinon-chai": "^3.4.0",
"tape": "^4.9.1",
Expand Down

0 comments on commit 34beab0

Please sign in to comment.