Skip to content
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

feat: add request/response debug logging to gapics #1670

Draft
wants to merge 11 commits into
base: main
Choose a base branch
from
2 changes: 2 additions & 0 deletions .bazeliskrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# See https://github.com/bazelbuild/bazelisk
USE_BAZEL_VERSION=6.3.0
137 changes: 130 additions & 7 deletions baselines/asset-esm/esm/src/v1/asset_service_client.ts.baseline
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import {fileURLToPath} from 'url';
import {getJSON} from '../json-helper.cjs';
// @ts-ignore
const dirname = path.dirname(fileURLToPath(import.meta.url));
import * as logging from 'google-logging-utils';

/**
* Client JSON configuration object, loaded from
Expand Down Expand Up @@ -62,6 +63,7 @@ export class AssetServiceClient {
private _defaults: {[method: string]: gax.CallSettings};
private _universeDomain: string;
private _servicePath: string;
private _log = logging.log('asset');
auth: gax.GoogleAuth;
descriptors: Descriptors = {
page: {},
Expand Down Expand Up @@ -472,7 +474,24 @@ export class AssetServiceClient {
'parent': request.parent ?? '',
});
this.initialize();
return this.innerApiCalls.batchGetAssetsHistory(request, options, callback);
this._log.info('batchGetAssetsHistory request %j', request);
const wrappedCallback: Callback<
protos.google.cloud.asset.v1.IBatchGetAssetsHistoryResponse,
protos.google.cloud.asset.v1.IBatchGetAssetsHistoryRequest|null|undefined,
{}|null|undefined>|undefined = callback
? (error, response, options, rawResponse) => {
this._log.info('batchGetAssetsHistory response %j', response);
callback(error, response, options, rawResponse);
}
: undefined;
return this.innerApiCalls.batchGetAssetsHistory(request, options, wrappedCallback)
?.then(([response, options, rawResponse]: [
protos.google.cloud.asset.v1.IBatchGetAssetsHistoryResponse,
protos.google.cloud.asset.v1.IBatchGetAssetsHistoryRequest|undefined, {}|undefined
]) => {
this._log.info('batchGetAssetsHistory response %j', response);
return [response, options, rawResponse];
});
}
/**
* Creates a feed in a parent project/folder/organization to listen to its
Expand Down Expand Up @@ -556,7 +575,24 @@ export class AssetServiceClient {
'parent': request.parent ?? '',
});
this.initialize();
return this.innerApiCalls.createFeed(request, options, callback);
this._log.info('createFeed request %j', request);
const wrappedCallback: Callback<
protos.google.cloud.asset.v1.IFeed,
protos.google.cloud.asset.v1.ICreateFeedRequest|null|undefined,
{}|null|undefined>|undefined = callback
? (error, response, options, rawResponse) => {
this._log.info('createFeed response %j', response);
callback(error, response, options, rawResponse);
}
: undefined;
return this.innerApiCalls.createFeed(request, options, wrappedCallback)
?.then(([response, options, rawResponse]: [
protos.google.cloud.asset.v1.IFeed,
protos.google.cloud.asset.v1.ICreateFeedRequest|undefined, {}|undefined
]) => {
this._log.info('createFeed response %j', response);
return [response, options, rawResponse];
});
}
/**
* Gets details about an asset feed.
Expand Down Expand Up @@ -629,7 +665,24 @@ export class AssetServiceClient {
'name': request.name ?? '',
});
this.initialize();
return this.innerApiCalls.getFeed(request, options, callback);
this._log.info('getFeed request %j', request);
const wrappedCallback: Callback<
protos.google.cloud.asset.v1.IFeed,
protos.google.cloud.asset.v1.IGetFeedRequest|null|undefined,
{}|null|undefined>|undefined = callback
? (error, response, options, rawResponse) => {
this._log.info('getFeed response %j', response);
callback(error, response, options, rawResponse);
}
: undefined;
return this.innerApiCalls.getFeed(request, options, wrappedCallback)
?.then(([response, options, rawResponse]: [
protos.google.cloud.asset.v1.IFeed,
protos.google.cloud.asset.v1.IGetFeedRequest|undefined, {}|undefined
]) => {
this._log.info('getFeed response %j', response);
return [response, options, rawResponse];
});
}
/**
* Lists all asset feeds in a parent project/folder/organization.
Expand Down Expand Up @@ -701,7 +754,24 @@ export class AssetServiceClient {
'parent': request.parent ?? '',
});
this.initialize();
return this.innerApiCalls.listFeeds(request, options, callback);
this._log.info('listFeeds request %j', request);
const wrappedCallback: Callback<
protos.google.cloud.asset.v1.IListFeedsResponse,
protos.google.cloud.asset.v1.IListFeedsRequest|null|undefined,
{}|null|undefined>|undefined = callback
? (error, response, options, rawResponse) => {
this._log.info('listFeeds response %j', response);
callback(error, response, options, rawResponse);
}
: undefined;
return this.innerApiCalls.listFeeds(request, options, wrappedCallback)
?.then(([response, options, rawResponse]: [
protos.google.cloud.asset.v1.IListFeedsResponse,
protos.google.cloud.asset.v1.IListFeedsRequest|undefined, {}|undefined
]) => {
this._log.info('listFeeds response %j', response);
return [response, options, rawResponse];
});
}
/**
* Updates an asset feed configuration.
Expand Down Expand Up @@ -779,7 +849,24 @@ export class AssetServiceClient {
'feed.name': request.feed!.name ?? '',
});
this.initialize();
return this.innerApiCalls.updateFeed(request, options, callback);
this._log.info('updateFeed request %j', request);
const wrappedCallback: Callback<
protos.google.cloud.asset.v1.IFeed,
protos.google.cloud.asset.v1.IUpdateFeedRequest|null|undefined,
{}|null|undefined>|undefined = callback
? (error, response, options, rawResponse) => {
this._log.info('updateFeed response %j', response);
callback(error, response, options, rawResponse);
}
: undefined;
return this.innerApiCalls.updateFeed(request, options, wrappedCallback)
?.then(([response, options, rawResponse]: [
protos.google.cloud.asset.v1.IFeed,
protos.google.cloud.asset.v1.IUpdateFeedRequest|undefined, {}|undefined
]) => {
this._log.info('updateFeed response %j', response);
return [response, options, rawResponse];
});
}
/**
* Deletes an asset feed.
Expand Down Expand Up @@ -852,7 +939,24 @@ export class AssetServiceClient {
'name': request.name ?? '',
});
this.initialize();
return this.innerApiCalls.deleteFeed(request, options, callback);
this._log.info('deleteFeed request %j', request);
const wrappedCallback: Callback<
protos.google.protobuf.IEmpty,
protos.google.cloud.asset.v1.IDeleteFeedRequest|null|undefined,
{}|null|undefined>|undefined = callback
? (error, response, options, rawResponse) => {
this._log.info('deleteFeed response %j', response);
callback(error, response, options, rawResponse);
}
: undefined;
return this.innerApiCalls.deleteFeed(request, options, wrappedCallback)
?.then(([response, options, rawResponse]: [
protos.google.protobuf.IEmpty,
protos.google.cloud.asset.v1.IDeleteFeedRequest|undefined, {}|undefined
]) => {
this._log.info('deleteFeed response %j', response);
return [response, options, rawResponse];
});
}

/**
Expand Down Expand Up @@ -949,7 +1053,24 @@ export class AssetServiceClient {
'parent': request.parent ?? '',
});
this.initialize();
return this.innerApiCalls.exportAssets(request, options, callback);
const wrappedCallback: Callback<
protos.google.longrunning.IOperation,
protos.google.cloud.asset.v1.IExportAssetsRequest|null|undefined,
{}|null|undefined>|undefined = callback
? (error, response, options, rawResponse) => {
this._log.info('exportAssets response %j', response);
callback(error, response, options, rawResponse);
}
: undefined;
this._log.info('exportAssets request %j', request);
return this.innerApiCalls.exportAssets(request, options, wrappedCallback)
?.then(([response, options, rawResponse]: [
protos.google.longrunning.IOperation,
protos.google.cloud.asset.v1.IExportAssetsRequest|undefined, {}|undefined
]) => {
this._log.info('exportAssets response %j', response);
return [response, options, rawResponse];
});
}
/**
* Check the status of the long running operation returned by `exportAssets()`.
Expand All @@ -963,6 +1084,7 @@ export class AssetServiceClient {
* region_tag:cloudasset_v1_generated_AssetService_ExportAssets_async
*/
async checkExportAssetsProgress(name: string): Promise<LROperation<protos.google.cloud.asset.v1.ExportAssetsResponse, protos.google.cloud.asset.v1.ExportAssetsRequest>>{
this._log.info('exportAssets long-running');
const request = new this._gaxModule.operationsProtos.google.longrunning.GetOperationRequest({name});
const [operation] = await this.operationsClient.getOperation(request);
const decodeOperation = new this._gaxModule.Operation(operation, this.descriptors.longrunning.exportAssets, this._gaxModule.createDefaultBackoffSettings());
Expand Down Expand Up @@ -1089,6 +1211,7 @@ export class AssetServiceClient {
close(): Promise<void> {
if (this.assetServiceStub && !this._terminated) {
return this.assetServiceStub.then(stub => {
this._log.info('ending gRPC channel');
this._terminated = true;
stub.close();
this.operationsClient.close();
Expand Down
3 changes: 2 additions & 1 deletion baselines/asset/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@
"test": "c8 mocha build/test"
},
"dependencies": {
"google-gax": "^4.4.0"
"google-gax": "^4.4.0",
"google-logging-utils": "next"
},
"devDependencies": {
"@types/mocha": "^10.0.7",
Expand Down
Loading
Loading