From 4420f8455446f9e9567cc9447d54869f787118e7 Mon Sep 17 00:00:00 2001 From: Shivanee Persaud Date: Fri, 30 Oct 2026 15:19:01 -0700 Subject: [PATCH] feat(gax): remove experimental logging flag and add logging sample --- core/packages/gax/samples/observability.js | 125 ++++++++++++++---- .../samples/system-test/test.observability.js | 1 + core/packages/gax/src/clientInterface.ts | 10 +- core/packages/gax/src/gax.ts | 15 +-- core/packages/gax/src/grpc.ts | 10 +- core/packages/gax/src/observability/util.ts | 30 ++--- core/packages/gax/test/unit/apiCallable.ts | 4 - core/packages/gax/test/unit/gax.ts | 10 +- core/packages/gax/test/unit/grpc-fallback.ts | 51 ++++--- core/packages/gax/test/unit/grpc.ts | 4 +- core/packages/gax/test/unit/iamService.ts | 2 - .../packages/gax/test/unit/locationService.ts | 2 - .../packages/gax/test/unit/operationClient.ts | 2 - core/packages/gax/test/unit/util.ts | 31 ++--- 14 files changed, 162 insertions(+), 135 deletions(-) diff --git a/core/packages/gax/samples/observability.js b/core/packages/gax/samples/observability.js index ab2318a803ac..3b6e7c1472ef 100644 --- a/core/packages/gax/samples/observability.js +++ b/core/packages/gax/samples/observability.js @@ -17,31 +17,38 @@ // [START gax_observability] 'use strict'; -// 1. IMPORT OPENTELEMETRY MODULES -const {NodeTracerProvider} = require('@opentelemetry/sdk-trace-node'); -const {BatchSpanProcessor} = require('@opentelemetry/sdk-trace-base'); -const { - TraceExporter, -} = require('@google-cloud/opentelemetry-cloud-trace-exporter'); - -// 2. CONFIGURE TRACING: SET UP A TRACER PROVIDER AND EXPORTER -const cloudTraceExporter = new TraceExporter(); -const spanProcessor = new BatchSpanProcessor(cloudTraceExporter); - -const provider = new NodeTracerProvider({ - spanProcessors: [spanProcessor], -}); -provider.register(); - -// 3. ENABLE TRACING SPANS WITH ENV VARIABLE -// Sets the flag before client libraries or RPC callers initialize -process.env.GOOGLE_SDK_NODE_ENABLE_TRACING = 'true'; - -// 4. IMPORT CLIENT LIBRARIES AFTER OPENTELEMETRY SETUP -// Replace with your Google Cloud client library, for example: -// const { SecretManagerServiceClient } = require('@google-cloud/secret-manager'); +// Logging and tracing in Google Cloud Node.js client libraries are completely +// orthogonal: you can enable logging without OpenTelemetry tracing +// (`!tracingEnabled && loggingEnabled`), tracing without logging, or both +// simultaneously. When both are active, failed RPC logs automatically include +// `telemetryTraceId` and `telemetrySpanId` for trace-log correlation. -async function main() { +// [START gax_observability_tracing] +async function enableTracing() { + // 1. IMPORT OPENTELEMETRY MODULES + const {NodeTracerProvider} = require('@opentelemetry/sdk-trace-node'); + const {BatchSpanProcessor} = require('@opentelemetry/sdk-trace-base'); + const { + TraceExporter, + } = require('@google-cloud/opentelemetry-cloud-trace-exporter'); + + // 2. CONFIGURE TRACING: SET UP A TRACER PROVIDER AND EXPORTER + const cloudTraceExporter = new TraceExporter(); + const spanProcessor = new BatchSpanProcessor(cloudTraceExporter); + + const provider = new NodeTracerProvider({ + spanProcessors: [spanProcessor], + }); + provider.register(); + + // 3. ENABLE TRACING SPANS + // Set the flag before client libraries or RPC callers initialize, or pass + // `{enableTelemetryTracing: true}` to an individual client constructor. + process.env.GOOGLE_SDK_NODE_ENABLE_TRACING = 'true'; + + // 4. IMPORT CLIENT LIBRARIES AFTER OPENTELEMETRY SETUP + // Replace with your Google Cloud client library, for example: + // const {SecretManagerServiceClient} = require('@google-cloud/secret-manager'); // const client = new SecretManagerServiceClient(); // await client.listSecrets({parent: 'projects/my-project'}); @@ -50,6 +57,76 @@ async function main() { await provider.forceFlush(); console.log('Tracing initialized successfully.'); } +// [END gax_observability_tracing] + +// [START gax_observability_logging] +async function enableLogging() { + // Telemetry logging does not require OpenTelemetry setup (`!tracingEnabled && loggingEnabled`). + const util = require('util'); + const {loggingUtils} = require('google-gax'); + + // 1. ENABLE TELEMETRY LOGGING + // In production, prefer `{enableTelemetryLogging: true}` on the client or a + // service-scoped filter (e.g. `GOOGLE_SDK_NODE_LOGGING=secretmanager`) over + // `*`, `true`, or `all` so `'auth'` debug logs remain disabled. + process.env.GOOGLE_SDK_NODE_LOGGING = 'secretmanager'; + + // Or enable logging for a specific client without setting an env variable: + // const {SecretManagerServiceClient} = require('@google-cloud/secret-manager'); + // const client = new SecretManagerServiceClient({enableTelemetryLogging: true}); + + // 2. CONFIGURE AN OUTPUT BACKEND (DEFAULT NODEBACKEND OR PLUGGABLE BACKEND) + // Option A — Default `NodeBackend` (writes formatted log lines to `stderr`): + // No configuration is needed to use the default backend (`undefined` resets to default). + loggingUtils.setBackend(undefined); + + // Option B — Built-in structured JSON backend (writes Cloud Logging JSON): + // loggingUtils.setBackend(loggingUtils.getStructuredBackend()); + + // Option C — Pluggable custom backend (e.g. Pino, Winston, Bunyan, or custom filtering): + const customBackend = { + setFilters() { + // Receives filters parsed from `GOOGLE_SDK_NODE_LOGGING`, if needed. + }, + log(namespace, fields, ...args) { + // Skip `'auth'` debug logs if only client RPC telemetry logs are desired. + if (namespace === 'auth') { + return; + } + const entry = { + namespace, + severity: fields.severity, + message: util.format(...args), + ...(fields.telemetryTraceId + ? {telemetryTraceId: fields.telemetryTraceId} + : {}), + ...(fields.telemetrySpanId + ? {telemetrySpanId: fields.telemetrySpanId} + : {}), + ...(fields.other || {}), + }; + // Forward `entry` to your preferred logger (Pino, Winston, stdout, etc.): + console.log(JSON.stringify(entry)); + }, + }; + loggingUtils.setBackend(customBackend); + + // 3. CALL CLIENT LIBRARIES AS USUAL + // Failed API calls emit structured `WARNING` logs and failed transport + // attempts emit `DEBUG` logs through the configured backend. + // await client.listSecrets({parent: 'projects/my-project'}); + + console.log('Logging initialized successfully.'); +} +// [END gax_observability_logging] + +async function main() { + // Enable logging independently (works with or without OpenTelemetry tracing): + await enableLogging(); + + // Enable OpenTelemetry tracing independently (works with or without logging): + await enableTracing(); +} main().catch(console.error); // [END gax_observability] diff --git a/core/packages/gax/samples/system-test/test.observability.js b/core/packages/gax/samples/system-test/test.observability.js index 5f8eb0d5b22c..d82ba8e6ded7 100644 --- a/core/packages/gax/samples/system-test/test.observability.js +++ b/core/packages/gax/samples/system-test/test.observability.js @@ -29,6 +29,7 @@ const cwd = path.join(__dirname, '..'); describe('Observability', () => { it('should run observability sample', async () => { const stdout = execSync('node observability.js', {cwd}); + assert(/Logging initialized successfully/.test(stdout)); assert(/Tracing initialized successfully/.test(stdout)); }); }); diff --git a/core/packages/gax/src/clientInterface.ts b/core/packages/gax/src/clientInterface.ts index e9eb4fdad8f1..0954d03baa0d 100644 --- a/core/packages/gax/src/clientInterface.ts +++ b/core/packages/gax/src/clientInterface.ts @@ -53,11 +53,11 @@ export interface ClientOptions /** * Whether to enable telemetry logging for the client. * - * Logging is only enabled when `GOOGLE_SDK_NODE_EXPERIMENTAL_LOGGING` is enabled - * AND either `enableTelemetryLogging: true` is passed here or, when unset, the - * `GOOGLE_SDK_NODE_LOGGING` environment variable matches the client service - * namespace. Explicitly setting `enableTelemetryLogging: false` disables logging - * for this client even when `GOOGLE_SDK_NODE_LOGGING` matches. + * Logging is only enabled when `enableTelemetryLogging: true` is passed here + * or, when unset, the `GOOGLE_SDK_NODE_LOGGING` environment variable matches + * the client service namespace. Explicitly setting + * `enableTelemetryLogging: false` disables logging for this client even when + * `GOOGLE_SDK_NODE_LOGGING` matches. */ enableTelemetryLogging?: boolean; } diff --git a/core/packages/gax/src/gax.ts b/core/packages/gax/src/gax.ts index 9434d3e61b31..7c3b78a5abd2 100644 --- a/core/packages/gax/src/gax.ts +++ b/core/packages/gax/src/gax.ts @@ -921,12 +921,8 @@ export function constructSettings( ? isEnvEnabled : Boolean(enableTelemetryTracing); - const experimentalLogging = - env.GOOGLE_SDK_NODE_EXPERIMENTAL_LOGGING?.trim().toLowerCase(); - const isExperimentalLoggingEnabled = - experimentalLogging === 'true' || experimentalLogging === '1'; const isLoggingEnvEnabled = - isExperimentalLoggingEnabled && enableTelemetryLogging === undefined + enableTelemetryLogging === undefined ? checkLoggingEnabled(new CallSettings({apiName: serviceName})) : false; const resolvedLogging = @@ -935,8 +931,7 @@ export function constructSettings( : isLoggingEnvEnabled ? true : undefined; - const loggingRequested = - isExperimentalLoggingEnabled && Boolean(resolvedLogging); + const loggingRequested = Boolean(resolvedLogging); otherArgs = otherArgs || {}; @@ -1007,11 +1002,7 @@ export function constructSettings( : otherArgs, apiName, enableTelemetryTracing: isEnvSet ? isEnvEnabled : enableTelemetryTracing, - enableTelemetryLogging: isExperimentalLoggingEnabled - ? resolvedLogging - : enableTelemetryLogging !== undefined - ? false - : undefined, + enableTelemetryLogging: resolvedLogging, }); } diff --git a/core/packages/gax/src/grpc.ts b/core/packages/gax/src/grpc.ts index e9e1658e48ed..b8677b303bfb 100644 --- a/core/packages/gax/src/grpc.ts +++ b/core/packages/gax/src/grpc.ts @@ -67,11 +67,11 @@ export interface GrpcClientOptions extends GoogleAuthOptions { /** * Whether to enable telemetry logging for the client. * - * Logging is only enabled when `GOOGLE_SDK_NODE_EXPERIMENTAL_LOGGING` is enabled - * AND either `enableTelemetryLogging: true` is passed here or, when unset, the - * `GOOGLE_SDK_NODE_LOGGING` environment variable matches the client service - * namespace. Explicitly setting `enableTelemetryLogging: false` disables logging - * for this client even when `GOOGLE_SDK_NODE_LOGGING` matches. + * Logging is only enabled when `enableTelemetryLogging: true` is passed here + * or, when unset, the `GOOGLE_SDK_NODE_LOGGING` environment variable matches + * the client service namespace. Explicitly setting + * `enableTelemetryLogging: false` disables logging for this client even when + * `GOOGLE_SDK_NODE_LOGGING` matches. */ enableTelemetryLogging?: boolean; } diff --git a/core/packages/gax/src/observability/util.ts b/core/packages/gax/src/observability/util.ts index d69cd706cd4c..beb98aeb5733 100644 --- a/core/packages/gax/src/observability/util.ts +++ b/core/packages/gax/src/observability/util.ts @@ -71,29 +71,18 @@ function matchesLoggingEnvFilter(envOptIn: string, namespace: string): boolean { /** * Checks if telemetry logging is enabled. * - * Logging is only enabled when `GOOGLE_SDK_NODE_EXPERIMENTAL_LOGGING` is enabled - * AND either a user explicitly passes `enableTelemetryLogging: true` in their - * client/call options or, when `enableTelemetryLogging` is unset, the - * `GOOGLE_SDK_NODE_LOGGING` environment variable matches the client service - * namespace using `google-logging-utils` filter semantics (`'*'`, exact `'all'` / - * `'true'`, or comma-separated wildcard patterns). Passing - * `enableTelemetryLogging: false` suppresses logging for that client/call even - * when `GOOGLE_SDK_NODE_LOGGING` matches. + * Logging is only enabled when a user explicitly passes + * `enableTelemetryLogging: true` in their client/call options or, when + * `enableTelemetryLogging` is unset, the `GOOGLE_SDK_NODE_LOGGING` environment + * variable matches the client service namespace using `google-logging-utils` + * filter semantics (`'*'`, exact `'all'` / `'true'`, or comma-separated + * wildcard patterns). Passing `enableTelemetryLogging: false` suppresses + * logging for that client/call even when `GOOGLE_SDK_NODE_LOGGING` matches. * * @param settings * @returns true if telemetry logging is enabled, false otherwise */ export function checkLoggingEnabled(settings?: CallSettings): boolean { - const env: Record = - typeof process === 'object' && typeof process.env === 'object' - ? process.env - : {}; - const experimentalOptIn = - env.GOOGLE_SDK_NODE_EXPERIMENTAL_LOGGING?.trim().toLowerCase(); - if (experimentalOptIn !== 'true' && experimentalOptIn !== '1') { - return false; - } - if (typeof settings?.enableTelemetryLogging === 'boolean') { return settings.enableTelemetryLogging; } @@ -101,6 +90,11 @@ export function checkLoggingEnabled(settings?: CallSettings): boolean { return true; } + const env: Record = + typeof process === 'object' && typeof process.env === 'object' + ? process.env + : {}; + const envOptIn = env.GOOGLE_SDK_NODE_LOGGING; if (!envOptIn) { return false; diff --git a/core/packages/gax/test/unit/apiCallable.ts b/core/packages/gax/test/unit/apiCallable.ts index 85ea95f4396e..4b147134c398 100644 --- a/core/packages/gax/test/unit/apiCallable.ts +++ b/core/packages/gax/test/unit/apiCallable.ts @@ -1876,14 +1876,12 @@ describe('createApiCall', () => { loggingUtils.setBackend(sink); harness = new OtelHarness(); harness.setup(); - process.env.GOOGLE_SDK_NODE_EXPERIMENTAL_LOGGING = 'true'; }); afterEach(() => { clearMetadataCache(); loggingUtils.setBackend(undefined); harness.teardown(); - delete process.env.GOOGLE_SDK_NODE_EXPERIMENTAL_LOGGING; delete process.env.GOOGLE_SDK_NODE_LOGGING; delete process.env.GOOGLE_SDK_NODE_ENABLE_TRACING; }); @@ -2809,11 +2807,9 @@ describe('createApiCall', () => { for (const childEnv of [ { - GOOGLE_SDK_NODE_EXPERIMENTAL_LOGGING: 'true', CHILD_ENABLE_OPT: 'true', }, { - GOOGLE_SDK_NODE_EXPERIMENTAL_LOGGING: 'true', GOOGLE_SDK_NODE_LOGGING: 'storage,example', }, ]) { diff --git a/core/packages/gax/test/unit/gax.ts b/core/packages/gax/test/unit/gax.ts index 87e163f5c6ca..6e42d634ffa5 100644 --- a/core/packages/gax/test/unit/gax.ts +++ b/core/packages/gax/test/unit/gax.ts @@ -102,7 +102,6 @@ describe('gax construct settings', () => { afterEach(() => { delete process.env.GOOGLE_SDK_NODE_ENABLE_TRACING; delete process.env.GOOGLE_SDK_NODE_LOGGING; - delete process.env.GOOGLE_SDK_NODE_EXPERIMENTAL_LOGGING; }); it('creates settings', () => { @@ -280,8 +279,7 @@ describe('gax construct settings', () => { assert.strictEqual(settings.otherArgs.internalMethodName, undefined); }); - it('creates settings with enableTelemetryLogging when GOOGLE_SDK_NODE_EXPERIMENTAL_LOGGING=true', () => { - process.env.GOOGLE_SDK_NODE_EXPERIMENTAL_LOGGING = 'true'; + it('creates settings with enableTelemetryLogging', () => { const otherArgs = {key: 'value'}; const defaults = gax.constructSettings( SERVICE_NAME, @@ -301,7 +299,7 @@ describe('gax construct settings', () => { assert.strictEqual(settings.otherArgs.enableTelemetryLogging, true); }); - it('disables logging when GOOGLE_SDK_NODE_EXPERIMENTAL_LOGGING is not set even if enableTelemetryLogging=true', () => { + it('creates settings with enableTelemetryLogging set to false', () => { const defaults = gax.constructSettings( SERVICE_NAME, A_CONFIG, @@ -310,7 +308,7 @@ describe('gax construct settings', () => { {}, undefined, undefined, - true, + false, ); const settings = defaults.bundlingMethod; assert.strictEqual(settings.enableTelemetryLogging, false); @@ -318,7 +316,6 @@ describe('gax construct settings', () => { }); it('enables logging when enableTelemetryLogging is unset and GOOGLE_SDK_NODE_LOGGING matches the service namespace or wildcard', () => { - process.env.GOOGLE_SDK_NODE_EXPERIMENTAL_LOGGING = 'true'; for (const envValue of ['true', '*', 'all', 'auth,interface']) { process.env.GOOGLE_SDK_NODE_LOGGING = envValue; const defaults = gax.constructSettings( @@ -360,7 +357,6 @@ describe('gax construct settings', () => { }); it('preserves enableTelemetryLogging=true when GOOGLE_SDK_NODE_LOGGING targets another namespace or is false', () => { - process.env.GOOGLE_SDK_NODE_EXPERIMENTAL_LOGGING = 'true'; for (const envValue of ['auth,storage', 'false']) { process.env.GOOGLE_SDK_NODE_LOGGING = envValue; const enabledDefaults = gax.constructSettings( diff --git a/core/packages/gax/test/unit/grpc-fallback.ts b/core/packages/gax/test/unit/grpc-fallback.ts index ddf1039b9294..58244ccda73c 100644 --- a/core/packages/gax/test/unit/grpc-fallback.ts +++ b/core/packages/gax/test/unit/grpc-fallback.ts @@ -327,37 +327,32 @@ describe('grpc-fallback', () => { } }); - it('constructSettings should enable logging when enableTelemetryLogging: true is passed in client options and GOOGLE_SDK_NODE_EXPERIMENTAL_LOGGING=true', () => { - process.env.GOOGLE_SDK_NODE_EXPERIMENTAL_LOGGING = 'true'; - try { - const gapicConfig = { - interfaces: { - 'google.showcase.v1beta1.Echo': { - retry_codes: {}, - retry_params: {}, - methods: { - Echo: { - timeout_millis: 60000, - }, + it('constructSettings should enable logging when enableTelemetryLogging: true is passed in client options', () => { + const gapicConfig = { + interfaces: { + 'google.showcase.v1beta1.Echo': { + retry_codes: {}, + retry_params: {}, + methods: { + Echo: { + timeout_millis: 60000, }, }, }, - }; - const clientWithLogging = new GrpcClient({ - ...opts, - enableTelemetryLogging: true, - }); - const settings = clientWithLogging.constructSettings( - 'google.showcase.v1beta1.Echo', - gapicConfig, - {}, - {}, - ); - assert.strictEqual(settings.echo.enableTelemetryLogging, true); - assert.strictEqual(settings.echo.otherArgs.internalMethodName, 'Echo'); - } finally { - delete process.env.GOOGLE_SDK_NODE_EXPERIMENTAL_LOGGING; - } + }, + }; + const clientWithLogging = new GrpcClient({ + ...opts, + enableTelemetryLogging: true, + }); + const settings = clientWithLogging.constructSettings( + 'google.showcase.v1beta1.Echo', + gapicConfig, + {}, + {}, + ); + assert.strictEqual(settings.echo.enableTelemetryLogging, true); + assert.strictEqual(settings.echo.otherArgs.internalMethodName, 'Echo'); }); it('constructSettings should preserve GAPIC auth.defaultServicePath as canonical url.domain over emulator servicePath', () => { diff --git a/core/packages/gax/test/unit/grpc.ts b/core/packages/gax/test/unit/grpc.ts index 9bf5dbd7b985..c56a995af1b3 100644 --- a/core/packages/gax/test/unit/grpc.ts +++ b/core/packages/gax/test/unit/grpc.ts @@ -144,7 +144,6 @@ describe('grpc', () => { afterEach(() => { delete process.env.GOOGLE_SDK_NODE_ENABLE_TRACING; delete process.env.GOOGLE_SDK_NODE_LOGGING; - delete process.env.GOOGLE_SDK_NODE_EXPERIMENTAL_LOGGING; }); it('constructs settings without telemetry options', () => { @@ -197,8 +196,7 @@ describe('grpc', () => { ); }); - it('constructs settings when enableTelemetryLogging: true is passed in client options and GOOGLE_SDK_NODE_EXPERIMENTAL_LOGGING=true', () => { - process.env.GOOGLE_SDK_NODE_EXPERIMENTAL_LOGGING = 'true'; + it('constructs settings when enableTelemetryLogging: true is passed in client options', () => { const clientWithLogging = gaxGrpc({ enableTelemetryLogging: true, }); diff --git a/core/packages/gax/test/unit/iamService.ts b/core/packages/gax/test/unit/iamService.ts index e76ffffe15f7..fec217f317be 100644 --- a/core/packages/gax/test/unit/iamService.ts +++ b/core/packages/gax/test/unit/iamService.ts @@ -435,14 +435,12 @@ describe('IAM service', () => { loggingUtils.setBackend(sink); harness = new OtelHarness(); harness.setup(); - process.env.GOOGLE_SDK_NODE_EXPERIMENTAL_LOGGING = 'true'; }); afterEach(() => { clearMetadataCache(); loggingUtils.setBackend(undefined); harness.teardown(); - delete process.env.GOOGLE_SDK_NODE_EXPERIMENTAL_LOGGING; delete process.env.GOOGLE_SDK_NODE_LOGGING; delete process.env.GOOGLE_SDK_NODE_ENABLE_TRACING; }); diff --git a/core/packages/gax/test/unit/locationService.ts b/core/packages/gax/test/unit/locationService.ts index 3fc13cff24ce..2ad5a97f19e0 100644 --- a/core/packages/gax/test/unit/locationService.ts +++ b/core/packages/gax/test/unit/locationService.ts @@ -417,14 +417,12 @@ describe('LocationsClient', () => { loggingUtils.setBackend(sink); harness = new OtelHarness(); harness.setup(); - process.env.GOOGLE_SDK_NODE_EXPERIMENTAL_LOGGING = 'true'; }); afterEach(() => { clearMetadataCache(); loggingUtils.setBackend(undefined); harness.teardown(); - delete process.env.GOOGLE_SDK_NODE_EXPERIMENTAL_LOGGING; delete process.env.GOOGLE_SDK_NODE_LOGGING; delete process.env.GOOGLE_SDK_NODE_ENABLE_TRACING; }); diff --git a/core/packages/gax/test/unit/operationClient.ts b/core/packages/gax/test/unit/operationClient.ts index d48c22dc42ea..78f9ff610eca 100644 --- a/core/packages/gax/test/unit/operationClient.ts +++ b/core/packages/gax/test/unit/operationClient.ts @@ -797,14 +797,12 @@ describe('operation client', () => { loggingUtils.setBackend(sink); harness = new OtelHarness(); harness.setup(); - process.env.GOOGLE_SDK_NODE_EXPERIMENTAL_LOGGING = 'true'; }); afterEach(() => { clearMetadataCache(); loggingUtils.setBackend(undefined); harness.teardown(); - delete process.env.GOOGLE_SDK_NODE_EXPERIMENTAL_LOGGING; delete process.env.GOOGLE_SDK_NODE_LOGGING; delete process.env.GOOGLE_SDK_NODE_ENABLE_TRACING; }); diff --git a/core/packages/gax/test/unit/util.ts b/core/packages/gax/test/unit/util.ts index 9ebb44fd05be..40f083e27137 100644 --- a/core/packages/gax/test/unit/util.ts +++ b/core/packages/gax/test/unit/util.ts @@ -312,7 +312,6 @@ describe('util.ts', () => { describe('checkLoggingEnabled', () => { afterEach(() => { delete process.env.GOOGLE_SDK_NODE_LOGGING; - delete process.env.GOOGLE_SDK_NODE_EXPERIMENTAL_LOGGING; delete process.env.GOOGLE_SDK_NODE_CLIENT_SERVICE; delete process.env.GCP_CLIENT_SERVICE; delete process.env.GOOGLE_SDK_NODE_ARTIFACT; @@ -327,24 +326,11 @@ describe('util.ts', () => { apiName: 'google.cloud.storage.v1.Storage', }); - it('returns false when GOOGLE_SDK_NODE_EXPERIMENTAL_LOGGING is not set even if logging is enabled', () => { - process.env.GOOGLE_SDK_NODE_LOGGING = 'true'; - assert.strictEqual(checkLoggingEnabled(mockSettings), false); - }); - - it('returns false when GOOGLE_SDK_NODE_EXPERIMENTAL_LOGGING is false', () => { - process.env.GOOGLE_SDK_NODE_EXPERIMENTAL_LOGGING = 'false'; - process.env.GOOGLE_SDK_NODE_LOGGING = 'true'; - assert.strictEqual(checkLoggingEnabled(mockSettings), false); - }); - - it('returns true when GOOGLE_SDK_NODE_EXPERIMENTAL_LOGGING=true and settings have enableTelemetryLogging', () => { - process.env.GOOGLE_SDK_NODE_EXPERIMENTAL_LOGGING = 'true'; + it('returns true when settings have enableTelemetryLogging', () => { assert.strictEqual(checkLoggingEnabled(mockSettings), true); }); - it('returns true when GOOGLE_SDK_NODE_EXPERIMENTAL_LOGGING=1 and settings.otherArgs have enableTelemetryLogging', () => { - process.env.GOOGLE_SDK_NODE_EXPERIMENTAL_LOGGING = '1'; + it('returns true when settings.otherArgs have enableTelemetryLogging', () => { const otherArgsSettings = new CallSettings({ otherArgs: {enableTelemetryLogging: true}, }); @@ -352,7 +338,6 @@ describe('util.ts', () => { }); it('returns false when enableTelemetryLogging is false or not set on settings and env var is not set', () => { - process.env.GOOGLE_SDK_NODE_EXPERIMENTAL_LOGGING = 'true'; const disabledSettings = new CallSettings({ enableTelemetryLogging: false, }); @@ -362,7 +347,6 @@ describe('util.ts', () => { }); it('returns true when GOOGLE_SDK_NODE_LOGGING is exact true, all, or *', () => { - process.env.GOOGLE_SDK_NODE_EXPERIMENTAL_LOGGING = 'TRUE'; for (const value of ['true', 'all', '*']) { process.env.GOOGLE_SDK_NODE_LOGGING = value; assert.strictEqual(checkLoggingEnabled(storageSettings), true); @@ -372,7 +356,6 @@ describe('util.ts', () => { }); it('matches comma-separated and wildcard namespace filters identically to NodeBackend.setFilters()', () => { - process.env.GOOGLE_SDK_NODE_EXPERIMENTAL_LOGGING = 'true'; const secretManagerSettings = new CallSettings({ apiName: 'google.cloud.secretmanager.v1.SecretManagerService', }); @@ -418,7 +401,6 @@ describe('util.ts', () => { }); it('gives explicit enableTelemetryLogging precedence over GOOGLE_SDK_NODE_LOGGING', () => { - process.env.GOOGLE_SDK_NODE_EXPERIMENTAL_LOGGING = 'true'; const disabledStorageSettings = new CallSettings({ apiName: 'google.cloud.storage.v1.Storage', enableTelemetryLogging: false, @@ -447,18 +429,21 @@ describe('util.ts', () => { it('does not throw when process is undefined, as in a browser', () => { const globals = globalThis as {process?: NodeJS.Process}; const originalProcess = globals.process; - let result: boolean | undefined; + let enabledResult: boolean | undefined; + let unsetResult: boolean | undefined; let thrown: unknown; delete globals.process; try { - result = checkLoggingEnabled(mockSettings); + enabledResult = checkLoggingEnabled(mockSettings); + unsetResult = checkLoggingEnabled(storageSettings); } catch (e) { thrown = e; } finally { globals.process = originalProcess; } assert.strictEqual(thrown, undefined); - assert.strictEqual(result, false); + assert.strictEqual(enabledResult, true); + assert.strictEqual(unsetResult, false); }); });