Skip to content
This repository was archived by the owner on Jan 21, 2026. It is now read-only.

Commit 746f30c

Browse files
authored
feat: support restify v9-v11 (#1489)
Fixes #1488 (see also #1250 for reference)
1 parent 81d9d5c commit 746f30c

6 files changed

Lines changed: 40 additions & 27 deletions

File tree

.readme-partials.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ body: |-
6969
* [gRPC](https://www.npmjs.com/package/grpc) server (version ^1.1)
7070
* [hapi](https://www.npmjs.com/package/hapi) (versions 8 - 19)
7171
* [koa](https://www.npmjs.com/package/koa) (version 1 - 2)
72-
* [restify](https://www.npmjs.com/package/restify) (versions 3 - 8)
72+
* [restify](https://www.npmjs.com/package/restify) (versions 3 - 11)
7373
7474
The agent will also automatically trace RPCs from the following modules:
7575
* Outbound HTTP requests through `http`, `https`, and `http2` core modules

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ The trace agent can do automatic tracing of the following web frameworks:
122122
* [gRPC](https://www.npmjs.com/package/grpc) server (version ^1.1)
123123
* [hapi](https://www.npmjs.com/package/hapi) (versions 8 - 19)
124124
* [koa](https://www.npmjs.com/package/koa) (version 1 - 2)
125-
* [restify](https://www.npmjs.com/package/restify) (versions 3 - 8)
125+
* [restify](https://www.npmjs.com/package/restify) (versions 3 - 11)
126126

127127
The agent will also automatically trace RPCs from the following modules:
128128
* Outbound HTTP requests through `http`, `https`, and `http2` core modules

src/plugins/plugin-restify.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ type Response = restify_5.Response;
2525
type Next = restify_5.Next;
2626
type CreateServerFn = (options?: restify_5.ServerOptions) => restify_5.Server;
2727

28-
const SUPPORTED_VERSIONS = '<=8.x';
28+
const SUPPORTED_VERSIONS = '<=11.x';
2929

3030
function unpatchRestify(restify: Restify5) {
3131
shimmer.unwrap(restify, 'createServer');

test/fixtures/plugin-fixtures.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,5 +243,20 @@
243243
"dependencies": {
244244
"restify": "^8.5.1"
245245
}
246+
},
247+
"restify9": {
248+
"dependencies": {
249+
"restify": "^9.0.0"
250+
}
251+
},
252+
"restify10": {
253+
"dependencies": {
254+
"restify": "^10.0.0"
255+
}
256+
},
257+
"restify11": {
258+
"dependencies": {
259+
"restify": "^11.0.0"
260+
}
246261
}
247262
}

test/test-trace-web-frameworks.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ import {
4242
Restify6,
4343
Restify7,
4444
Restify8,
45+
Restify9,
46+
Restify10,
47+
Restify11,
4548
} from './web-frameworks/restify';
4649

4750
// The type of a stack trace object after being parsed from a trace span's stack
@@ -70,6 +73,9 @@ const FRAMEWORKS: WebFrameworkConstructor[] = [
7073
Restify6,
7174
Restify7,
7275
Restify8,
76+
Restify9,
77+
Restify10,
78+
Restify11,
7379
];
7480

7581
/**

test/web-frameworks/restify.ts

Lines changed: 16 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,7 @@
1414

1515
import {restify_5} from '../../src/plugins/types';
1616

17-
import {
18-
WebFramework,
19-
WebFrameworkAddHandlerOptions,
20-
WebFrameworkResponse,
21-
} from './base';
17+
import {WebFramework, WebFrameworkAddHandlerOptions} from './base';
2218

2319
export class Restify implements WebFramework {
2420
server: restify_5.Server;
@@ -35,31 +31,24 @@ export class Restify implements WebFramework {
3531
);
3632
}
3733
if (options.hasResponse) {
38-
this.server.get(options.path, async (req, res, next) => {
39-
let response: WebFrameworkResponse;
40-
try {
41-
response = await options.fn(req.headers);
42-
} catch (e) {
43-
next(e);
44-
return;
45-
}
46-
res.statusCode = response.statusCode;
47-
res.end(response.message);
48-
next();
34+
this.server.get(options.path, (req, res, next) => {
35+
Promise.resolve()
36+
.then(() => options.fn(req.headers))
37+
.then(response => {
38+
res.statusCode = response.statusCode;
39+
res.end(response.message);
40+
})
41+
.then(() => next(), next);
4942
});
5043
} else {
51-
this.server.use(async (req, res, next) => {
44+
this.server.use((req, res, next) => {
5245
if (req.getPath() !== options.path) {
5346
next();
5447
return;
5548
}
56-
try {
57-
await options.fn(req.headers);
58-
} catch (e) {
59-
next(e);
60-
return;
61-
}
62-
next();
49+
Promise.resolve()
50+
.then(() => options.fn(req.headers))
51+
.then(() => next(), next);
6352
});
6453
}
6554
}
@@ -91,3 +80,6 @@ export const Restify5 = makeRestifyClass(5);
9180
export const Restify6 = makeRestifyClass(6);
9281
export const Restify7 = makeRestifyClass(7);
9382
export const Restify8 = makeRestifyClass(8);
83+
export const Restify9 = makeRestifyClass(9, '>12');
84+
export const Restify10 = makeRestifyClass(10, '>12');
85+
export const Restify11 = makeRestifyClass(11, '>12');

0 commit comments

Comments
 (0)