-
Notifications
You must be signed in to change notification settings - Fork 97
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
refactor: add web framework plugin types and script to fetch types #621
Conversation
f10d0a5
to
1335a4f
Compare
d5f73f7
to
7f25b90
Compare
Codecov Report
@@ Coverage Diff @@
## master #621 +/- ##
==========================================
- Coverage 91% 90.59% -0.42%
==========================================
Files 30 30
Lines 1390 1403 +13
Branches 275 288 +13
==========================================
+ Hits 1265 1271 +6
- Misses 53 54 +1
- Partials 72 78 +6
Continue to review full report at Codecov.
|
CI failures are due to flakes. In anticipation of pending reviews I'm not restarting them right now |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mostly nits
scripts/index.ts
Outdated
@@ -2,6 +2,7 @@ const [bin, script, ...steps] = process.argv; | |||
|
|||
import { checkInstall } from './check-install'; | |||
import { encryptCredentials, decryptCredentials } from './credentials'; | |||
import { getPluginTypes } from './get-plugin-types'; |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
src/plugins/plugin-connect.ts
Outdated
|
||
const SUPPORTED_VERSIONS = '3.x'; | ||
|
||
function getFirstHeader(req: IncomingMessage, key: string) { |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
src/plugins/plugin-connect.ts
Outdated
@@ -42,8 +66,8 @@ function createMiddleware(api) { | |||
api.wrapEmitter(req); | |||
api.wrapEmitter(res); | |||
|
|||
var url = (req.headers['X-Forwarded-Proto'] || 'http') + | |||
'://' + req.headers.host + req.originalUrl; | |||
const url = (req.headers['X-Forwarded-Proto'] || 'http') + '://' + |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
src/plugins/plugin-express.ts
Outdated
@@ -55,16 +58,16 @@ function patchModuleRoot(express, api) { | |||
api.wrapEmitter(req); | |||
api.wrapEmitter(res); | |||
|
|||
var url = req.protocol + '://' + req.hostname + req.originalUrl; | |||
const url = req.protocol + '://' + req.hostname + req.originalUrl; |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
src/plugins/plugin-hapi.ts
Outdated
|
||
const SUPPORTED_VERSIONS = '8 - 16'; | ||
|
||
function getFirstHeader(req: IncomingMessage, key: string) { |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
src/plugins/plugin-hapi.ts
Outdated
var url = (req.headers['X-Forwarded-Proto'] || 'http') + | ||
'://' + req.headers.host + req.url; | ||
|
||
const url = (req.headers['X-Forwarded-Proto'] || 'http') + '://' + |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
interface KoaModule<T> { | ||
// TypeScript isn't expressive enough, but KoaModule#use should return `this`. | ||
// tslint:disable-next-line:no-any | ||
readonly prototype: {use: (m: T) => any}; |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
src/plugins/plugin-koa.ts
Outdated
// propagateContext flag. The type of "next" differs between Koa 1 and 2. | ||
type GetNextFn<T> = (propagateContext: boolean) => T; | ||
|
||
function getFirstHeader(req: IncomingMessage, key: string) { |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
src/plugins/plugin-koa.ts
Outdated
} | ||
|
||
api.wrapEmitter(req); | ||
api.wrapEmitter(res); | ||
|
||
const url = (req.headers['X-Forwarded-Proto'] || 'http') + | ||
'://' + req.headers.host + req.url; | ||
const url = (req.headers['X-Forwarded-Proto'] || 'http') + '://' + |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
src/plugins/plugin-koa.ts
Outdated
|
||
function createMiddleware(api: PluginTypes.TraceAgent): koa_1.Middleware { | ||
// Koa 1 type definitions use any here. | ||
// tslint:disable-next-line:no-any |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
f98e5c8
to
544bbb7
Compare
New changes are in 1393994 only |
Ignoring codecov for now... will be fixed in follow-up PR. |
Fixes #620
This change adds TypeScript types for all web framework tracing plugins and subjects them to
gts
,In addition, it introduces an npm verb to download type definitions separately into a directory distinct fromnode_modules
. The purpose of this is to depend on several versions of type definitions, something that isn't supported by npm. Currently, this doesn't apply to any type definitions (Koa 1 and 2 have different types, but @types/koa@1 doesn't exist, and the minimal type definitions for koa 1 can share types with koa 2).I'm considering avoiding this entirely (it adds a considerable amount of complexity to the codebase), and having the Trace Agent simply depend on one version of each module instead. So far this is feasible, but it might not be in the long term. I would like to get thoughts on this.This change also fixes a bug where framework-specific routing trace labels aren't generated because the Trace Agent expects them on the wrong property. This is apparent in
koa
(#620) andconnect
(because AFAIK connect's route path is the original URL).Update: Changed this so that plugin types are simply installed under devDependencies. There is no script to fetch types anymore. I might add that later, thinking of crossing that bridge when the times comes (currently, besides Koa 1 which has no
@types
module anyway, there are no modules whose interfaces change dramatically between versions)