diff --git a/src/index.ts b/src/index.ts index 23b5d3ae..c8d2708e 100644 --- a/src/index.ts +++ b/src/index.ts @@ -593,9 +593,13 @@ class Logging { reqOpts.resourceNames = arrify(reqOpts.resourceNames!); this.projectId = await this.auth.getProjectId(); const resourceName = 'projects/' + this.projectId; - if (reqOpts.resourceNames.indexOf(resourceName) === -1) { - reqOpts.resourceNames.push(resourceName); - } + const isReadFromBucket = reqOpts.resourceNames.some(resourceName => + resourceName.startsWith(resourceName) + ); + if ( + reqOpts.resourceNames.indexOf(resourceName) === -1 && + !isReadFromBucket + ) { delete reqOpts.autoPaginate; delete reqOpts.gaxOptions; let gaxOptions = extend( diff --git a/test/index.ts b/test/index.ts index 3127db6b..372829a4 100644 --- a/test/index.ts +++ b/test/index.ts @@ -616,6 +616,30 @@ describe('Logging', () => { await logging.getEntries(options); }); + it('should not push project id if include logging bucket view', async () => { + const options = { + resourceNames: [ + 'projects/' + + logging.projectId + + '/locations/global/buckets/test-bucket/views/test-view', + ], + }; + + logging.loggingService.listLogEntries = async ( + // eslint-disable-next-line @typescript-eslint/no-explicit-any + reqOpts: any + ) => { + assert.deepStrictEqual(reqOpts.resourceNames, [ + 'projects/' + + logging.projectId + + '/locations/global/buckets/test-bucket/views/test-view', + ]); + return [[]]; + }; + + await logging.getEntries(options); + }); + describe('error', () => { const error = new Error('Error.');