Repository navigation
chore(gax): add observability logging flag #9656
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
base: main
Are you sure you want to change the base?
Changes from all commits
2900daf
6ca3ebc
11c2b9e
36a8e1d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,7 +24,7 @@ import {warn} from './warnings'; | |
| import {GoogleError} from './googleError'; | ||
| import {BundleOptions} from './bundlingCalls/bundleExecutor'; | ||
| import {toLowerCamelCase} from './util'; | ||
| import {checkTelemetryEnabled} from './observability/util'; | ||
| import {checkTracingEnabled, checkLoggingEnabled} from './observability/util'; | ||
| import {Status} from './status'; | ||
| import {RequestType} from './apitypes'; | ||
|
|
||
|
|
@@ -173,6 +173,7 @@ export interface CallOptions { | |
| apiName?: string; | ||
| retryRequestOptions?: RetryRequestOptions; | ||
| enableTelemetryTracing?: boolean; | ||
| enableTelemetryLogging?: boolean; | ||
| /** | ||
| * Internal context used by resumable upload methods. Populated by | ||
| * GAPIC-generated client libraries; do not set manually. | ||
|
|
@@ -195,6 +196,7 @@ export class CallSettings { | |
| apiName?: string; | ||
| retryRequestOptions?: RetryRequestOptions; | ||
| enableTelemetryTracing?: boolean; | ||
| enableTelemetryLogging?: boolean; | ||
| resumableUpload?: ResumableUploadContext; | ||
|
|
||
| /** | ||
|
|
@@ -230,6 +232,7 @@ export class CallSettings { | |
| this.apiName = settings.apiName ?? undefined; | ||
| this.retryRequestOptions = settings.retryRequestOptions; | ||
| this.enableTelemetryTracing = settings.enableTelemetryTracing; | ||
| this.enableTelemetryLogging = settings.enableTelemetryLogging; | ||
| this.resumableUpload = | ||
| 'resumableUpload' in settings ? settings.resumableUpload : undefined; | ||
| } | ||
|
|
@@ -256,6 +259,7 @@ export class CallSettings { | |
| let apiName = this.apiName; | ||
| let retryRequestOptions = this.retryRequestOptions; | ||
| let enableTelemetryTracing = this.enableTelemetryTracing; | ||
| let enableTelemetryLogging = this.enableTelemetryLogging; | ||
| let resumableUpload = this.resumableUpload; | ||
|
|
||
| // If the user provides a timeout to the method, that timeout value will be used | ||
|
|
@@ -315,6 +319,9 @@ export class CallSettings { | |
| if ('enableTelemetryTracing' in options) { | ||
| enableTelemetryTracing = options.enableTelemetryTracing; | ||
| } | ||
| if ('enableTelemetryLogging' in options) { | ||
| enableTelemetryLogging = options.enableTelemetryLogging; | ||
| } | ||
| if ('resumableUpload' in options) { | ||
| resumableUpload = options.resumableUpload; | ||
| } | ||
|
|
@@ -331,6 +338,7 @@ export class CallSettings { | |
| apiName, | ||
| retryRequestOptions, | ||
| enableTelemetryTracing, | ||
| enableTelemetryLogging, | ||
| resumableUpload, | ||
| }); | ||
| } | ||
|
|
@@ -807,6 +815,9 @@ export interface ClientConfig { | |
| * calls. | ||
| * @param {boolean} [enableTelemetryTracing] - Flag to enable telemetry tracing | ||
| * when passed in client options (or overridden by `GOOGLE_SDK_NODE_ENABLE_TRACING`). | ||
| * @param {unknown} [_legacyTelemetryInfo] - Unused legacy parameter kept for backward compatibility. | ||
| * @param {boolean} [enableTelemetryLogging] - Flag to enable telemetry logging | ||
| * when passed in client options (or overridden by `GOOGLE_SDK_NODE_ENABLE_LOGGING`). | ||
| * @return {Object} A mapping from method name to CallSettings, or null if the | ||
| * service is not found in the config. | ||
| */ | ||
|
|
@@ -819,6 +830,7 @@ export function constructSettings( | |
| enableTelemetryTracing?: boolean, | ||
| // eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
| _legacyTelemetryInfo?: unknown, | ||
| enableTelemetryLogging?: boolean, | ||
| ) { | ||
|
Comment on lines
830
to
834
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The shifting logic inside Please update the shifting logic inside the function body to also shift if (
status &&
!Object.prototype.hasOwnProperty.call(status, 'OK')
) {
enableTelemetryLogging = _legacyTelemetryInfo as boolean;
_legacyTelemetryInfo = enableTelemetryTracing;
enableTelemetryTracing = otherArgs as boolean;
otherArgs = status;
status = undefined;
} |
||
| const env: Record<string, string | undefined> = | ||
| typeof process === 'object' && typeof process.env === 'object' | ||
|
|
@@ -827,7 +839,7 @@ export function constructSettings( | |
| const envTracing = env.GOOGLE_SDK_NODE_ENABLE_TRACING?.trim(); | ||
| const isEnvSet = envTracing !== undefined && envTracing !== ''; | ||
|
|
||
| const isEnvEnabled = checkTelemetryEnabled(); | ||
| const isEnvEnabled = checkTracingEnabled(); | ||
|
|
||
| // Tracing is only enabled via GOOGLE_SDK_NODE_ENABLE_TRACING or when the user | ||
| // passes enableTelemetryTracing: true in their client options. If | ||
|
|
@@ -836,6 +848,18 @@ export function constructSettings( | |
| ? isEnvEnabled | ||
| : Boolean(enableTelemetryTracing); | ||
|
|
||
| const experimentalLogging = | ||
| env.GOOGLE_SDK_NODE_EXPERIMENTAL_LOGGING?.trim().toLowerCase(); | ||
| const isExperimentalLoggingEnabled = | ||
| experimentalLogging === 'true' || experimentalLogging === '1'; | ||
| const envLogging = env.GOOGLE_SDK_NODE_ENABLE_LOGGING?.trim(); | ||
| const isLoggingEnvSet = envLogging !== undefined && envLogging !== ''; | ||
| const isLoggingEnvEnabled = checkLoggingEnabled(); | ||
|
|
||
| const loggingRequested = | ||
| isExperimentalLoggingEnabled && | ||
| (isLoggingEnvSet ? isLoggingEnvEnabled : Boolean(enableTelemetryLogging)); | ||
|
|
||
| otherArgs = otherArgs || {}; | ||
| // eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
| const defaults: any = {}; | ||
|
|
@@ -893,11 +917,24 @@ export function constructSettings( | |
| bundleOptions: bundlingConfig | ||
| ? createBundleOptions(bundlingConfig) | ||
| : null, | ||
| otherArgs: tracingRequested | ||
| ? {...otherArgs, internalMethodName: methodName} | ||
| : otherArgs, | ||
| otherArgs: | ||
| tracingRequested || loggingRequested | ||
| ? { | ||
| ...otherArgs, | ||
| internalMethodName: methodName, | ||
| enableTelemetryTracing: tracingRequested, | ||
| enableTelemetryLogging: loggingRequested, | ||
| } | ||
| : otherArgs, | ||
| apiName, | ||
| enableTelemetryTracing: isEnvSet ? isEnvEnabled : enableTelemetryTracing, | ||
| enableTelemetryLogging: isExperimentalLoggingEnabled | ||
| ? isLoggingEnvSet | ||
| ? isLoggingEnvEnabled | ||
| : enableTelemetryLogging | ||
| : enableTelemetryLogging !== undefined || isLoggingEnvSet | ||
| ? false | ||
| : undefined, | ||
| }); | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,3 @@ | ||
| /** | ||
| * Copyright 2020 Google LLC | ||
| * | ||
|
|
@@ -63,6 +63,14 @@ | |
| * options. | ||
| */ | ||
| enableTelemetryTracing?: boolean; | ||
| /** | ||
| * Whether to enable telemetry logging for the client. | ||
| * | ||
| * Logging is only enabled when `GOOGLE_SDK_NODE_EXPERIMENTAL_LOGGING` is enabled | ||
| * AND either the `GOOGLE_SDK_NODE_ENABLE_LOGGING` environment variable is enabled | ||
| * or a user passes `enableTelemetryLogging: true` in their client options. | ||
| */ | ||
| enableTelemetryLogging?: boolean; | ||
| } | ||
|
|
||
| export interface MetadataValue { | ||
|
|
@@ -134,6 +142,7 @@ | |
| private _servicePath?: string; | ||
| private _port?: number; | ||
| private _enableTelemetryTracing?: boolean; | ||
| private _enableTelemetryLogging?: boolean; | ||
| /** | ||
| * Base directory for resolving client certificates. | ||
| * | ||
|
|
@@ -193,6 +202,7 @@ | |
| ? parseInt(options.port, 10) | ||
| : options.port; | ||
| this._enableTelemetryTracing = options.enableTelemetryTracing; | ||
| this._enableTelemetryLogging = options.enableTelemetryLogging; | ||
|
|
||
| const minimumVersion = 10; | ||
| const major = Number(process.version.match(/^v(\d+)/)?.[1]); | ||
|
|
@@ -396,6 +406,8 @@ | |
| * @param {Object} headers - A dictionary of additional HTTP header name to | ||
| * its value. | ||
| * @param {boolean} [enableTelemetryTracing] - Flag to enable telemetry tracing. | ||
| * @param {unknown} [_legacyTelemetryInfo] - Unused legacy parameter kept for backward compatibility. | ||
| * @param {boolean} [enableTelemetryLogging] - Flag to enable telemetry logging. | ||
| * @return {Object} A mapping of method names to CallSettings. | ||
| */ | ||
| constructSettings( | ||
|
|
@@ -406,6 +418,7 @@ | |
| enableTelemetryTracing?: boolean, | ||
| // eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
| _legacyTelemetryInfo?: unknown, | ||
| enableTelemetryLogging?: boolean, | ||
| ) { | ||
| const otherArgs: Record<string, unknown> = { | ||
| metadataBuilder: this.metadataBuilder(headers), | ||
|
|
@@ -423,6 +436,8 @@ | |
| this.grpc.status, | ||
| otherArgs, | ||
| enableTelemetryTracing ?? this._enableTelemetryTracing, | ||
| _legacyTelemetryInfo, | ||
| enableTelemetryLogging ?? this._enableTelemetryLogging, | ||
| ); | ||
| } | ||
|
Comment on lines
436
to
442
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is a parameter mismatch when calling the imported By passing You should explicitly pass this.grpc.status,
otherArgs,
undefined,
enableTelemetryTracing ?? this._enableTelemetryTracing,
_legacyTelemetryInfo,
enableTelemetryLogging ?? this._enableTelemetryLogging,
); |
||
|
|
||
|
|
||
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.
There is a parameter mismatch when calling the imported
constructSettingsfunction fromgax.ts. Ingax.ts, the 6th parameter isapiName?: string, andenableTelemetryTracingis the 7th parameter.By passing
enableTelemetryTracing ?? this._enableTelemetryTracingas the 6th argument, it is mapped toapiNameingax.ts. Consequently,enableTelemetryTracingingax.tsreceives_legacyTelemetryInfo(the 7th argument), andenableTelemetryLoggingreceivesundefinedbecause it is not passed as the 9th argument.You should explicitly pass
undefinedfor theapiNameparameter to align the arguments correctly.