Skip to content
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

feat: support restify v9-v11 #1489

Merged
merged 6 commits into from
Apr 25, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion .readme-partials.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ body: |-
* [gRPC](https://www.npmjs.com/package/grpc) server (version ^1.1)
* [hapi](https://www.npmjs.com/package/hapi) (versions 8 - 19)
* [koa](https://www.npmjs.com/package/koa) (version 1 - 2)
* [restify](https://www.npmjs.com/package/restify) (versions 3 - 8)
* [restify](https://www.npmjs.com/package/restify) (versions 3 - 11)

The agent will also automatically trace RPCs from the following modules:
* Outbound HTTP requests through `http`, `https`, and `http2` core modules
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ The trace agent can do automatic tracing of the following web frameworks:
* [gRPC](https://www.npmjs.com/package/grpc) server (version ^1.1)
* [hapi](https://www.npmjs.com/package/hapi) (versions 8 - 19)
* [koa](https://www.npmjs.com/package/koa) (version 1 - 2)
* [restify](https://www.npmjs.com/package/restify) (versions 3 - 8)
* [restify](https://www.npmjs.com/package/restify) (versions 3 - 11)

The agent will also automatically trace RPCs from the following modules:
* Outbound HTTP requests through `http`, `https`, and `http2` core modules
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/plugin-restify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ type Response = restify_5.Response;
type Next = restify_5.Next;
type CreateServerFn = (options?: restify_5.ServerOptions) => restify_5.Server;

const SUPPORTED_VERSIONS = '<=8.x';
const SUPPORTED_VERSIONS = '<=11.x';

function unpatchRestify(restify: Restify5) {
shimmer.unwrap(restify, 'createServer');
Expand Down
15 changes: 15 additions & 0 deletions test/fixtures/plugin-fixtures.json
Original file line number Diff line number Diff line change
Expand Up @@ -243,5 +243,20 @@
"dependencies": {
"restify": "^8.5.1"
}
},
"restify9": {
"dependencies": {
"restify": "^9.0.0"
}
},
"restify10": {
"dependencies": {
"restify": "^10.0.0"
}
},
"restify11": {
"dependencies": {
"restify": "^11.0.0"
}
}
}
6 changes: 6 additions & 0 deletions test/test-trace-web-frameworks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ import {
Restify6,
Restify7,
Restify8,
Restify9,
Restify10,
Restify11,
} from './web-frameworks/restify';

// The type of a stack trace object after being parsed from a trace span's stack
Expand Down Expand Up @@ -70,6 +73,9 @@ const FRAMEWORKS: WebFrameworkConstructor[] = [
Restify6,
Restify7,
Restify8,
Restify9,
Restify10,
Restify11,
];

/**
Expand Down
36 changes: 17 additions & 19 deletions test/web-frameworks/restify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import {
WebFramework,
WebFrameworkAddHandlerOptions,
WebFrameworkResponse,

Check warning on line 20 in test/web-frameworks/restify.ts

View workflow job for this annotation

GitHub Actions / lint

'WebFrameworkResponse' is defined but never used
} from './base';

export class Restify implements WebFramework {
Expand All @@ -35,31 +35,26 @@
);
}
if (options.hasResponse) {
this.server.get(options.path, async (req, res, next) => {
let response: WebFrameworkResponse;
try {
response = await options.fn(req.headers);
} catch (e) {
next(e);
return;
}
res.statusCode = response.statusCode;
res.end(response.message);
next();
this.server.get(options.path, (req, res, next) => {
Promise.resolve()
.then(() => options.fn(req.headers))
.then((response) => {

Check failure on line 41 in test/web-frameworks/restify.ts

View workflow job for this annotation

GitHub Actions / lint

Replace `(response)` with `response`
res.statusCode = response.statusCode;
res.end(response.message);
next();
})
.catch(e => next(e));
6utt3rfly marked this conversation as resolved.
Show resolved Hide resolved
});
} else {
this.server.use(async (req, res, next) => {
this.server.use((req, res, next) => {
if (req.getPath() !== options.path) {
next();
return;
}
try {
await options.fn(req.headers);
} catch (e) {
next(e);
return;
}
next();
Promise.resolve()
.then(() => options.fn(req.headers))
.then(() => next())
.catch(e => next(e));
6utt3rfly marked this conversation as resolved.
Show resolved Hide resolved
});
}
}
Expand Down Expand Up @@ -91,3 +86,6 @@
export const Restify6 = makeRestifyClass(6);
export const Restify7 = makeRestifyClass(7);
export const Restify8 = makeRestifyClass(8);
export const Restify9 = makeRestifyClass(9);
export const Restify10 = makeRestifyClass(10);
export const Restify11 = makeRestifyClass(11);