Skip to content
This repository was archived by the owner on Mar 11, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@
"@google-cloud/pubsub": "^0.24.0",
"@google-cloud/storage": "^2.2.0",
"@types/arrify": "^1.0.4",
"@types/express": "^4.16.0",
"@types/extend": "^3.0.0",
"@types/is": "0.0.21",
"@types/mocha": "^5.2.5",
Expand Down
5 changes: 2 additions & 3 deletions src/middleware/express/make-http-request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,12 @@
* limitations under the License.
*/

// Types-only import.
import {Request, Response} from 'express';
import * as http from 'http';

import {StackdriverHttpRequest} from '../../http-request';

export function makeHttpRequestData(
req: Request, res: Response,
req: http.IncomingMessage, res: http.ServerResponse,
latencyMilliseconds: number): StackdriverHttpRequest {
return {
status: res.statusCode,
Expand Down
9 changes: 5 additions & 4 deletions src/middleware/express/make-middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@
* limitations under the License.
*/

import * as http from 'http';
import onFinished = require('on-finished');
import {getOrInjectContext, makeHeaderWrapper} from '../context';
// Types-only import.
import {Request, Response, NextFunction} from 'express';

import {makeHttpRequestData} from './make-http-request';
import {StackdriverHttpRequest} from '../../http-request';

export interface AnnotatedRequestType<LoggerType> extends Request {
interface AnnotatedRequestType<LoggerType> extends http.IncomingMessage {
log: LoggerType;
}

Expand All @@ -45,7 +45,8 @@ export function makeMiddleware<LoggerType>(
projectId: string, makeChildLogger: (trace: string) => LoggerType,
emitRequestLog?: (httpRequest: StackdriverHttpRequest, trace: string) =>
void) {
return (req: Request, res: Response, next: NextFunction) => {
return (req: http.IncomingMessage, res: http.ServerResponse,
next: Function) => {
// TODO(ofrobots): use high-resolution timer.
const requestStartMs = Date.now();

Expand Down
10 changes: 5 additions & 5 deletions test/middleware/express/test-make-http-request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@
*/

import * as assert from 'assert';
// Types-only import.
import {Request, Response} from 'express';
import {IncomingMessage, ServerResponse} from 'http';
import {makeHttpRequestData} from '../../../src/middleware/express/make-http-request';

describe('middleware/express/make-http-request', () => {
Expand All @@ -25,16 +24,17 @@ describe('middleware/express/make-http-request', () => {
const fakeResponse = {};

const h1 = makeHttpRequestData(
fakeRequest as Request, fakeResponse as Response, 1003);
fakeRequest as IncomingMessage, fakeResponse as ServerResponse, 1003);
assert.deepStrictEqual(h1.latency, {seconds: 1, nanos: 3e6});

const h2 = makeHttpRequestData(
fakeRequest as Request, fakeResponse as Response, 9003.1);
fakeRequest as IncomingMessage, fakeResponse as ServerResponse, 9003.1);
assert.deepStrictEqual(h2.latency, {seconds: 9, nanos: 3.1e6});

// Make sure we nanos is uint32.
const h3 = makeHttpRequestData(
fakeRequest as Request, fakeResponse as Response, 1.0000000001);
fakeRequest as IncomingMessage, fakeResponse as ServerResponse,
1.0000000001);
assert.deepStrictEqual(h3.latency, {seconds: 0, nanos: 1e6});
});
});