Skip to content

Add Logging interceptor #2321

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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,43 @@
gaxOptions?: CallOptions;
}

const loggingInterceptor = (options, nextCall) => {
return new grpc.InterceptingCall(nextCall(options), {

Check failure on line 187 in src/index.ts

View workflow job for this annotation

GitHub Actions / lint

Delete `····`
start: function (metadata, listener, next) {

Check failure on line 188 in src/index.ts

View workflow job for this annotation

GitHub Actions / lint

Delete `····`
console.log(`[Interceptor LOG] Method: ${options.method_definition.path}`);

Check failure on line 189 in src/index.ts

View workflow job for this annotation

GitHub Actions / lint

Replace `····console.log(`[Interceptor·LOG]·Method:·${options.method_definition.path}`);` with `console.log(⏎········`[Interceptor·LOG]·Method:·${options.method_definition.path}`,`
console.log('[Interceptor LOG] Outgoing Metadata:', metadata.getMap());

Check failure on line 190 in src/index.ts

View workflow job for this annotation

GitHub Actions / lint

Replace `····` with `······);⏎`

const newListener = {

Check failure on line 192 in src/index.ts

View workflow job for this annotation

GitHub Actions / lint

Replace `··········` with `······`
onReceiveMetadata: function (metadata, next) {

Check failure on line 193 in src/index.ts

View workflow job for this annotation

GitHub Actions / lint

Delete `····`
console.log('[Interceptor LOG] Incoming Metadata:', metadata.getMap());

Check failure on line 194 in src/index.ts

View workflow job for this annotation

GitHub Actions / lint

Replace `····console.log('[Interceptor·LOG]·Incoming·Metadata:',·metadata.getMap());` with `console.log(⏎············'[Interceptor·LOG]·Incoming·Metadata:',⏎············metadata.getMap(),`
next(metadata);

Check failure on line 195 in src/index.ts

View workflow job for this annotation

GitHub Actions / lint

Replace `······` with `··);⏎··········`
},

Check failure on line 196 in src/index.ts

View workflow job for this annotation

GitHub Actions / lint

Delete `····`
onReceiveMessage: function (message, next) {

Check failure on line 197 in src/index.ts

View workflow job for this annotation

GitHub Actions / lint

Delete `····`
console.log('[Interceptor LOG] Incoming Message (type):', message ? message.constructor.name : null);
next(message);
},
onReceiveStatus: function (status, next) {
console.log('[Interceptor LOG] Status:', status);
next(status);
},
};
next(metadata, newListener);
},
sendMessage: function (message, next) {
console.log('[Interceptor LOG] Outgoing Message (type):', message ? message.constructor.name : null);
next(message);
},
halfClose: function (next) {
console.log('[Interceptor LOG] Half Close');
next();
},
cancel: function (next) {
console.log('[Interceptor LOG] Cancelled');
next();
},
});
};

/**
* Translates enum values to string keys.
*
Expand Down Expand Up @@ -1572,6 +1609,9 @@
extend(true, {}, config.gaxOpts, {
otherArgs: {
headers: config.headers,
options: {
interceptors: [loggingInterceptor],
},
},
}),
);
Expand Down
Loading