Skip to content

Commit 962f843

Browse files
DominicKramerJustinBeckwith
authored andcommitted
chore(deps): upgrade to gts 1.0.0 (#299)
1 parent 20d329d commit 962f843

File tree

9 files changed

+444
-336
lines changed

9 files changed

+444
-336
lines changed

handwritten/nodejs-logging-bunyan/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@
7676
"eslint-plugin-node": "^8.0.0",
7777
"eslint-plugin-prettier": "^3.0.0",
7878
"express": "^4.16.3",
79-
"gts": "^0.9.0",
79+
"gts": "^1.0.0",
8080
"intelli-espower-loader": "^1.0.1",
8181
"jsdoc": "^3.5.5",
8282
"jsdoc-baseline": "git+https://github.com/hegemonic/jsdoc-baseline.git",

handwritten/nodejs-logging-bunyan/src/index.ts

Lines changed: 36 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -137,17 +137,16 @@ function getCurrentTraceFromAgent() {
137137
*/
138138
export class LoggingBunyan extends Writable {
139139
private logName: string;
140-
private resource: types.MonitoredResource|undefined;
140+
private resource: types.MonitoredResource | undefined;
141141
private serviceContext?: types.ServiceContext;
142-
stackdriverLog:
143-
types.StackdriverLog; // TODO: add type for @google-cloud/logging
142+
stackdriverLog: types.StackdriverLog; // TODO: add type for @google-cloud/logging
144143
constructor(options?: types.Options) {
145144
options = options || {};
146145
super({objectMode: true});
147146
this.logName = options.logName || 'bunyan_log';
148147
this.resource = options.resource;
149148
this.serviceContext = options.serviceContext;
150-
this.stackdriverLog = (new Logging(options)).log(this.logName, {
149+
this.stackdriverLog = new Logging(options).log(this.logName, {
151150
removeCircular: true,
152151
});
153152

@@ -160,20 +159,21 @@ export class LoggingBunyan extends Writable {
160159
// that serviceContext.service is specified.
161160
if (this.serviceContext && !this.serviceContext.service) {
162161
throw new Error(
163-
`If 'serviceContext' is specified then ` +
164-
`'serviceContext.service' is required.`);
162+
`If 'serviceContext' is specified then ` +
163+
`'serviceContext.service' is required.`
164+
);
165165
}
166166

167167
/* Asynchrnously attempt to discover the service context. */
168168
if (!this.serviceContext) {
169-
detectServiceContext(this.stackdriverLog.logging.auth)
170-
.then(
171-
(serviceContext: types.ServiceContext) => {
172-
this.serviceContext = serviceContext;
173-
},
174-
() => {
175-
/* swallow any errors. */
176-
});
169+
detectServiceContext(this.stackdriverLog.logging.auth).then(
170+
(serviceContext: types.ServiceContext) => {
171+
this.serviceContext = serviceContext;
172+
},
173+
() => {
174+
/* swallow any errors. */
175+
}
176+
);
177177
}
178178
}
179179

@@ -188,10 +188,11 @@ export class LoggingBunyan extends Writable {
188188
/**
189189
* Format a bunyan record into a Stackdriver log entry.
190190
*/
191-
private formatEntry_(record: string|types.BunyanLogRecord) {
191+
private formatEntry_(record: string | types.BunyanLogRecord) {
192192
if (typeof record === 'string') {
193193
throw new Error(
194-
'@google-cloud/logging-bunyan only works as a raw bunyan stream type.');
194+
'@google-cloud/logging-bunyan only works as a raw bunyan stream type.'
195+
);
195196
}
196197
// Stackdriver Log Viewer picks up the summary line from the 'message' field
197198
// of the payload. Unless the user has provided a 'message' property also,
@@ -216,7 +217,7 @@ export class LoggingBunyan extends Writable {
216217
const entryMetadata: types.StackdriverEntryMetadata = {
217218
resource: this.resource,
218219
timestamp: record.time,
219-
severity: BUNYAN_TO_STACKDRIVER.get(Number(record.level))
220+
severity: BUNYAN_TO_STACKDRIVER.get(Number(record.level)),
220221
};
221222

222223
// If the record contains a httpRequest property, provide it on the entry
@@ -268,15 +269,18 @@ export class LoggingBunyan extends Writable {
268269
* we may well be in a different continuation.
269270
*/
270271
write(record: types.BunyanLogRecord, callback?: Function): boolean;
271-
write(record: types.BunyanLogRecord, encoding?: string, callback?: Function):
272-
boolean;
272+
write(
273+
record: types.BunyanLogRecord,
274+
encoding?: string,
275+
callback?: Function
276+
): boolean;
273277
// Writable.write used 'any' in function signature.
274278
// tslint:disable-next-line:no-any
275279
write(...args: any[]): boolean {
276280
let record = args[0];
277-
let encoding: string|null = null;
278-
type Callback = (error: Error|null|undefined) => void;
279-
let callback: Callback|string;
281+
let encoding: string | null = null;
282+
type Callback = (error: Error | null | undefined) => void;
283+
let callback: Callback | string;
280284
if (typeof args[1] === 'string') {
281285
encoding = args[1];
282286
callback = args[2];
@@ -312,15 +316,15 @@ export class LoggingBunyan extends Writable {
312316
*/
313317
// Writable._write used 'any' in function signature.
314318
_writev(
315-
chunks: Array<{
316-
// tslint:disable-next-line:no-any
317-
chunk: any; encoding: string;
318-
}>,
319-
callback: Function) {
320-
const entries = chunks.map((request: {
321-
// tslint:disable-next-line:no-any
322-
chunk: any; encoding: string;
323-
}) => {
319+
chunks: Array<{
320+
// tslint:disable-next-line:no-any
321+
chunk: any;
322+
encoding: string;
323+
}>,
324+
callback: Function
325+
) {
326+
const entries = chunks.map((request: {// tslint:disable-next-line:no-any
327+
chunk: any; encoding: string}) => {
324328
return this.formatEntry_(request.chunk);
325329
});
326330

@@ -336,4 +340,4 @@ module.exports.BUNYAN_TO_STACKDRIVER = BUNYAN_TO_STACKDRIVER;
336340
* @name LoggingBunyan.LOGGING_TRACE_KEY
337341
* @type {string}
338342
*/
339-
module.exports.LOGGING_TRACE_KEY = LOGGING_TRACE_KEY;
343+
module.exports.LOGGING_TRACE_KEY = LOGGING_TRACE_KEY;

handwritten/nodejs-logging-bunyan/src/middleware/express.ts

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
import {HttpRequest, middleware as commonMiddleware} from '@google-cloud/logging';
16+
import {
17+
HttpRequest,
18+
middleware as commonMiddleware,
19+
} from '@google-cloud/logging';
1720
import * as bunyan from 'bunyan';
1821
import {GCPEnv} from 'google-auth-library';
1922

@@ -38,25 +41,30 @@ export interface MiddlewareReturnType {
3841
/**
3942
* Express middleware
4043
*/
41-
export async function middleware(options?: MiddlewareOptions):
42-
Promise<MiddlewareReturnType> {
44+
export async function middleware(
45+
options?: MiddlewareOptions
46+
): Promise<MiddlewareReturnType> {
4347
const defaultOptions = {logName: 'bunyan_log', level: 'info'};
4448
options = Object.assign({}, defaultOptions, options);
4549

46-
const loggingBunyanApp = new LoggingBunyan(Object.assign({}, options, {
47-
// For request bundling to work, the parent (request) and child (app) logs
48-
// need to have distinct names. For exact requirements see:
49-
// https://cloud.google.com/appengine/articles/logging#linking_app_logs_and_requests
50-
logName: `${options.logName}_${APP_LOG_SUFFIX}`
51-
}));
50+
const loggingBunyanApp = new LoggingBunyan(
51+
Object.assign({}, options, {
52+
// For request bundling to work, the parent (request) and child (app) logs
53+
// need to have distinct names. For exact requirements see:
54+
// https://cloud.google.com/appengine/articles/logging#linking_app_logs_and_requests
55+
logName: `${options.logName}_${APP_LOG_SUFFIX}`,
56+
})
57+
);
5258
const logger = bunyan.createLogger({
5359
name: `${options.logName}_${APP_LOG_SUFFIX}`,
54-
streams: [loggingBunyanApp.stream(options.level as types.LogLevel)]
60+
streams: [loggingBunyanApp.stream(options.level as types.LogLevel)],
5561
});
5662

5763
const auth = loggingBunyanApp.stackdriverLog.logging.auth;
58-
const [env, projectId] =
59-
await Promise.all([auth.getEnv(), auth.getProjectId()]);
64+
const [env, projectId] = await Promise.all([
65+
auth.getEnv(),
66+
auth.getProjectId(),
67+
]);
6068

6169
// Unless we are running on Google App Engine or Cloud Functions, generate a
6270
// parent request log entry that all the request-specific logs ("app logs")
@@ -67,7 +75,7 @@ export async function middleware(options?: MiddlewareOptions):
6775
const loggingBunyanReq = new LoggingBunyan(options);
6876
const requestLogger = bunyan.createLogger({
6977
name: options.logName!,
70-
streams: [loggingBunyanReq.stream(options.level as types.LogLevel)]
78+
streams: [loggingBunyanReq.stream(options.level as types.LogLevel)],
7179
});
7280
emitRequestLog = (httpRequest: HttpRequest, trace: string) => {
7381
requestLogger.info({[LOGGING_TRACE_KEY]: trace, httpRequest});
@@ -77,7 +85,10 @@ export async function middleware(options?: MiddlewareOptions):
7785
return {
7886
logger,
7987
mw: commonMiddleware.express.makeMiddleware(
80-
projectId, makeChildLogger, emitRequestLog)
88+
projectId,
89+
makeChildLogger,
90+
emitRequestLog
91+
),
8192
};
8293

8394
function makeChildLogger(trace: string) {

handwritten/nodejs-logging-bunyan/system-test/errors-transport.ts

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export interface ErrorGroupStats {
4141
}
4242

4343
export interface ApiResponse {
44-
body: {errorGroupStats: ErrorGroupStats[]; errorEvents: ErrorEvent[];};
44+
body: {errorGroupStats: ErrorGroupStats[]; errorEvents: ErrorEvent[]};
4545
}
4646

4747
/* @const {String} Base Error Reporting API */
@@ -54,7 +54,7 @@ export class ErrorsApiTransport extends common.Service {
5454
super({
5555
baseUrl: 'https://clouderrorreporting.googleapis.com/v1beta1',
5656
scopes: ['https://www.googleapis.com/auth/cloud-platform'],
57-
packageJson
57+
packageJson,
5858
});
5959
}
6060

@@ -70,7 +70,7 @@ export class ErrorsApiTransport extends common.Service {
7070
const projectId = await this.getProjectId();
7171
const options = {
7272
uri: [API, projectId, 'groupStats?' + ONE_HOUR_API].join('/'),
73-
method: 'GET'
73+
method: 'GET',
7474
};
7575
const response = await this.request(options);
7676
return response.body.errorGroupStats || [];
@@ -80,18 +80,22 @@ export class ErrorsApiTransport extends common.Service {
8080
const projectId = await this.getProjectId();
8181
const options = {
8282
uri: [
83-
API, projectId,
84-
'events?groupId=' + groupId + '&pageSize=10&' + ONE_HOUR_API
83+
API,
84+
projectId,
85+
'events?groupId=' + groupId + '&pageSize=10&' + ONE_HOUR_API,
8586
].join('/'),
86-
method: 'GET'
87+
method: 'GET',
8788
};
8889

8990
const response = await this.request(options);
9091
return response.body.errorEvents || [];
9192
}
9293

93-
async pollForNewEvents(service: string, time: number, timeout: number):
94-
Promise<ErrorEvent[]> {
94+
async pollForNewEvents(
95+
service: string,
96+
time: number,
97+
timeout: number
98+
): Promise<ErrorEvent[]> {
9599
const timeLimit = Date.now() + timeout;
96100
let groupId;
97101
// wait for a group
@@ -102,9 +106,10 @@ export class ErrorsApiTransport extends common.Service {
102106
const groups = await this.getAllGroups();
103107
if (!groups.length) continue;
104108
// find an error group that matches the service
105-
groups.forEach((group) => {
109+
groups.forEach(group => {
106110
const match = group.affectedServices.find(
107-
context => context.service === service);
111+
context => context.service === service
112+
);
108113
if (match) {
109114
groupId = group.group.groupId;
110115
}
@@ -116,8 +121,10 @@ export class ErrorsApiTransport extends common.Service {
116121

117122
const events = await this.getGroupEvents(groupId);
118123
const filteredEvents = events.filter(
119-
event => event.serviceContext.service === service &&
120-
(new Date(event.eventTime).getTime() >= time));
124+
event =>
125+
event.serviceContext.service === service &&
126+
new Date(event.eventTime).getTime() >= time
127+
);
121128
if (filteredEvents.length) {
122129
return filteredEvents;
123130
}

0 commit comments

Comments
 (0)