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

Commit ee350a2

Browse files
renovate[bot]kjin
authored andcommitted
fix(deps): update dependency @google-cloud/common to ^0.23.0 (#834)
1 parent b7296f0 commit ee350a2

18 files changed

Lines changed: 4372 additions & 41 deletions

package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
},
5050
"devDependencies": {
5151
"@types/builtin-modules": "^2.0.0",
52+
"@types/console-log-level": "^1.4.0",
5253
"@types/continuation-local-storage": "^3.2.1",
5354
"@types/extend": "^3.0.0",
5455
"@types/glob": "^5.0.32",
@@ -83,7 +84,6 @@
8384
"nyc": "^13.0.0",
8485
"once": "^1.4.0",
8586
"pify": "^4.0.0",
86-
"request": "^2.83.0",
8787
"retry-axios": "^0.3.2",
8888
"rimraf": "^2.6.2",
8989
"source-map-support": "^0.5.6",
@@ -94,14 +94,16 @@
9494
"typescript": "~3.0.0"
9595
},
9696
"dependencies": {
97-
"@google-cloud/common": "^0.20.3",
97+
"@google-cloud/common": "^0.23.0",
9898
"builtin-modules": "^3.0.0",
99+
"console-log-level": "^1.4.0",
99100
"continuation-local-storage": "^3.2.1",
100101
"extend": "^3.0.0",
101102
"gcp-metadata": "^0.7.0",
102103
"hex2dec": "^1.0.1",
103104
"is": "^3.2.0",
104105
"methods": "^1.1.1",
106+
"request": "^2.83.0",
105107
"require-in-the-middle": "^3.0.0",
106108
"semver": "^5.4.1",
107109
"shimmer": "^1.2.0",

src/cls.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
* limitations under the License.
1515
*/
1616

17-
import {Logger} from '@google-cloud/common';
1817
import {EventEmitter} from 'events';
1918
import * as semver from 'semver';
2019

@@ -24,6 +23,7 @@ import {CLS, Func} from './cls/base';
2423
import {NullCLS} from './cls/null';
2524
import {SingularCLS} from './cls/singular';
2625
import {SpanType} from './constants';
26+
import {Logger} from './logger';
2727
import {RootSpan} from './plugin-types';
2828
import {UNCORRELATED_ROOT_SPAN, UNTRACED_ROOT_SPAN} from './span-data';
2929
import {Trace, TraceSpan} from './trace';

src/logger.ts

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
/**
2+
* Copyright 2018 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
import * as consoleLogLevel from 'console-log-level';
18+
import {defaultConfig} from './config';
19+
20+
export type ConsoleLogLevel = 'error'|'warn'|'info'|'debug';
21+
export type LogLevel = 'silent'|ConsoleLogLevel;
22+
23+
/**
24+
* The list of log levels.
25+
*/
26+
export const LEVELS: ReadonlyArray<LogLevel> =
27+
['silent', 'error', 'warn', 'info', 'debug'];
28+
29+
export interface LoggerConfig {
30+
/**
31+
* The minimum log level that will print to the console.
32+
*/
33+
level: string|false;
34+
35+
/**
36+
* A tag to use in log messages.
37+
*/
38+
tag: string;
39+
}
40+
41+
function logLevelToName(level?: number): LogLevel {
42+
if (typeof level === 'string') {
43+
level = Number(level);
44+
}
45+
if (typeof level !== 'number') {
46+
level = defaultConfig.logLevel;
47+
}
48+
if (level < 0) level = 0;
49+
if (level >= LEVELS.length) level = LEVELS.length - 1;
50+
return LEVELS[level];
51+
}
52+
53+
export class Logger {
54+
private logger: consoleLogLevel.Logger|null;
55+
56+
constructor(opts?: Partial<LoggerConfig>) {
57+
const levelName = opts && opts.level !== undefined ?
58+
opts.level :
59+
logLevelToName(defaultConfig.logLevel);
60+
61+
if (levelName === false || levelName === 'silent') {
62+
this.logger = null;
63+
return;
64+
}
65+
66+
this.logger = consoleLogLevel({
67+
stderr: true,
68+
prefix: opts && opts.tag ? opts.tag : 'unknown',
69+
level: levelName as ConsoleLogLevel
70+
});
71+
}
72+
73+
error(...args: Array<{}>): void {
74+
if (this.logger) {
75+
this.logger.error(...args);
76+
}
77+
}
78+
79+
warn(...args: Array<{}>): void {
80+
if (this.logger) {
81+
this.logger.warn(...args);
82+
}
83+
}
84+
85+
debug(...args: Array<{}>): void {
86+
if (this.logger) {
87+
this.logger.debug(...args);
88+
}
89+
}
90+
91+
info(...args: Array<{}>): void {
92+
if (this.logger) {
93+
this.logger.info(...args);
94+
}
95+
}
96+
}

src/trace-api.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@
1414
* limitations under the License.
1515
*/
1616

17-
import {Logger} from '@google-cloud/common';
1817
import * as is from 'is';
1918
import * as uuid from 'uuid';
2019

2120
import {cls, RootContext} from './cls';
2221
import {Constants, SpanType} from './constants';
22+
import {Logger} from './logger';
2323
import {Func, RootSpan, RootSpanOptions, Span, SpanOptions, Tracer} from './plugin-types';
2424
import {RootSpanData, UNCORRELATED_CHILD_SPAN, UNCORRELATED_ROOT_SPAN, UNTRACED_CHILD_SPAN, UNTRACED_ROOT_SPAN} from './span-data';
2525
import {TraceLabels} from './trace-labels';

src/trace-plugin-loader.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@
1414
* limitations under the License.
1515
*/
1616

17-
import {Logger} from '@google-cloud/common';
1817
import * as builtinModules from 'builtin-modules';
1918
import * as path from 'path';
2019
import * as hook from 'require-in-the-middle';
2120
import * as semver from 'semver';
2221

22+
import {Logger} from './logger';
2323
import {Intercept, Monkeypatch, Plugin} from './plugin-types';
2424
import {StackdriverTracer, StackdriverTracerConfig} from './trace-api';
2525
import {Singleton} from './util';

src/trace-writer.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,10 @@ import {AxiosError} from 'axios';
1919
import * as gcpMetadata from 'gcp-metadata';
2020
import {OutgoingHttpHeaders} from 'http';
2121
import * as os from 'os';
22+
import * as request from 'request';
2223

2324
import {Constants} from './constants';
25+
import {Logger} from './logger';
2426
import {SpanKind, Trace} from './trace';
2527
import {TraceLabels} from './trace-labels';
2628
import {Singleton} from './util';
@@ -74,9 +76,10 @@ export class TraceWriter extends common.Service {
7476
*/
7577
constructor(
7678
private readonly config: TraceWriterConfig,
77-
private readonly logger: common.Logger) {
79+
private readonly logger: Logger) {
7880
super(
7981
{
82+
requestModule: request,
8083
packageJson: pjson,
8184
projectIdRequired: false,
8285
baseUrl: 'https://cloudtrace.googleapis.com/v1',

src/tracing.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@
1414
* limitations under the License.
1515
*/
1616

17-
import {Logger, logger} from '@google-cloud/common';
1817
import * as path from 'path';
1918

2019
import {cls, TraceCLSConfig, TraceCLSMechanism} from './cls';
2120
import {CLSMechanism} from './config';
21+
import {LEVELS, Logger} from './logger';
2222
import {StackdriverTracer} from './trace-api';
2323
import {pluginLoader, PluginLoaderConfig} from './trace-plugin-loader';
2424
import {traceWriter, TraceWriterConfig} from './trace-writer';
@@ -54,9 +54,7 @@ export class Tracing implements Component {
5454
this.config = config;
5555
let logLevel = config.enabled ? config.logLevel : 0;
5656
// Clamp the logger level.
57-
// TODO(kjin): When @google-cloud/[email protected] is released, use
58-
// Logger.LEVELS instead.
59-
const defaultLevels = logger.LEVELS;
57+
const defaultLevels = LEVELS;
6058
if (logLevel < 0) {
6159
logLevel = 0;
6260
} else if (logLevel >= defaultLevels.length) {

test/logger.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
import {Logger, logger, LoggerConfig} from '@google-cloud/common';
17+
import {LEVELS, Logger, LoggerConfig} from '../src/logger';
1818

1919
const PASS_THROUGH_LOG_LEVEL = Number(process.env.GCLOUD_TEST_LOG_LEVEL || 0);
2020
// Capture the value of common.Logger so that we don't enter an infinite loop
@@ -26,13 +26,13 @@ const OriginalLogger = Logger;
2626
type LoggerFunction<R> = (message: any, ...args: any[]) => R;
2727

2828
export class TestLogger extends Logger {
29-
private logs: {[k in keyof Logger]: string[]} =
30-
{silent: [], error: [], warn: [], info: [], debug: [], silly: []};
29+
private logs: {[k in keyof Logger]:
30+
string[]} = {error: [], warn: [], info: [], debug: []};
3131
private innerLogger =
32-
new OriginalLogger({level: logger.LEVELS[PASS_THROUGH_LOG_LEVEL]});
32+
new OriginalLogger({level: LEVELS[PASS_THROUGH_LOG_LEVEL]});
3333

3434
constructor(options?: Partial<LoggerConfig>) {
35-
super(options);
35+
super(Object.assign({tag: '@google-cloud/trace-agent'}, options));
3636
}
3737

3838
private makeLoggerFn(logLevel: keyof Logger): LoggerFunction<this> {
@@ -50,7 +50,6 @@ export class TestLogger extends Logger {
5050
warn = this.makeLoggerFn('warn');
5151
info = this.makeLoggerFn('info');
5252
debug = this.makeLoggerFn('debug');
53-
silly = this.makeLoggerFn('silly');
5453

5554
getLogs(logLevel: keyof Logger): string[] {
5655
return this.logs[logLevel];

test/plugins/common.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ import { StackdriverTracer } from '../../src/trace-api';
3030
import { traceWriter } from '../../src/trace-writer';
3131
import * as TracingPolicy from '../../src/tracing-policy';
3232
import { SpanType } from '../../src/constants';
33+
import { TestLogger } from '../logger';
3334

3435
var semver = require('semver');
3536

36-
var logger = require('@google-cloud/common').logger;
3737
var trace = require('../../..');
3838
if (semver.satisfies(process.version, '>=8')) {
3939
// Monkeypatch Mocha's it() to create a fresh context with each test case.
@@ -75,7 +75,7 @@ shimmer.wrap(trace, 'start', function(original) {
7575
ignoreContextHeader: false,
7676
rootSpanNameOverride: (name: string) => name,
7777
samplingRate: 0
78-
}, logger());
78+
}, new TestLogger());
7979
testTraceAgent.policy = new TracingPolicy.TraceAllPolicy();
8080
return result;
8181
};

test/test-config-plugins.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@
1414
* limitations under the License.
1515
*/
1616

17-
import {Logger} from '@google-cloud/common';
1817
import * as assert from 'assert';
1918

2019
import {defaultConfig} from '../src/config';
20+
import {Logger} from '../src/logger';
2121
import {PluginLoader, PluginLoaderConfig} from '../src/trace-plugin-loader';
2222

2323
import * as testTraceModule from './trace';

0 commit comments

Comments
 (0)