From 19cbbcae2c63ba1b0ed1fb9ee70d6e50bda842a0 Mon Sep 17 00:00:00 2001 From: Franziska Hinkelmann Date: Fri, 7 Sep 2018 21:03:43 -0400 Subject: [PATCH] feat: use small HTTP dependency Use teenyRequest instead of request. This saves 900 ms at startup time. --- package.json | 4 ++-- src/trace-writer.ts | 5 +++-- test/test-trace-writer.ts | 2 +- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index 282948363..ebf81b9e7 100644 --- a/package.json +++ b/package.json @@ -63,7 +63,7 @@ "@types/pify": "^3.0.0", "@types/protobufjs": "^5.0.31", "@types/proxyquire": "^1.3.28", - "@types/request": "^2.0.8", + "@types/request": "^2.47.1", "@types/semver": "^5.4.0", "@types/shimmer": "^1.0.1", "@types/tmp": "0.0.33", @@ -103,10 +103,10 @@ "hex2dec": "^1.0.1", "is": "^3.2.0", "methods": "^1.1.1", - "request": "^2.83.0", "require-in-the-middle": "^3.0.0", "semver": "^5.4.1", "shimmer": "^1.2.0", + "teeny-request": "^3.9.0", "uuid": "^3.0.1" } } diff --git a/src/trace-writer.ts b/src/trace-writer.ts index fccb00115..5dd73ce8e 100644 --- a/src/trace-writer.ts +++ b/src/trace-writer.ts @@ -19,7 +19,8 @@ import {AxiosError} from 'axios'; import * as gcpMetadata from 'gcp-metadata'; import {OutgoingHttpHeaders} from 'http'; import * as os from 'os'; -import * as request from 'request'; +import * as r from 'request'; // Only for type declarations. +import {teenyRequest} from 'teeny-request'; import {Constants} from './constants'; import {Logger} from './logger'; @@ -79,7 +80,7 @@ export class TraceWriter extends common.Service { private readonly logger: Logger) { super( { - requestModule: request, + requestModule: teenyRequest as typeof r, packageJson: pjson, projectIdRequired: false, baseUrl: 'https://cloudtrace.googleapis.com/v1', diff --git a/test/test-trace-writer.ts b/test/test-trace-writer.ts index c032d88aa..289014f88 100644 --- a/test/test-trace-writer.ts +++ b/test/test-trace-writer.ts @@ -19,7 +19,7 @@ import * as assert from 'assert'; import {OutgoingHttpHeaders} from 'http'; import * as nock from 'nock'; import * as os from 'os'; -import {Response} from 'request'; +import {Response} from 'request'; // Only for type declarations. import * as shimmer from 'shimmer'; import {SpanKind, Trace} from '../src/trace';