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(sdk): automatically log http calls to API #3081

Merged
merged 6 commits into from
Dec 3, 2024

Conversation

bodinsamuel
Copy link
Collaborator

Changes

  • Automatically log http calls to API
    While doing fix(sdk): expose getIntegration() #3080 I noticed we don't log calls to our own API which can lead to confusion when you expect something to happen but don't manually log the result. Thanks to recent change, we now have a way to plug into axios and just listen to requests.
    It will log everything (i.e: triggerAction, getConnection, getIntegration, etc.), except proxy which doesn't go through node-client.

NB: This will for sure increase the log amount but just slightly since we do cache a lot.

Screenshot 2024-11-28 at 16 11 02

@bodinsamuel bodinsamuel self-assigned this Nov 28, 2024
@bodinsamuel bodinsamuel requested a review from a team November 28, 2024 15:38
Copy link
Contributor

@nalanj nalanj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a few small comments :shipit:

return res;
}

const valuesToFilter: string[] = [
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a small thought for the future: Could we compute our filter array once up front before any runner work and have the logger lean on it across all logging?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agreed. The valuesToFilter should not changed within a single execution

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually it's changing because connection's credentials can change during execution, but the value could be cached indeed. I'll add a comment

packages/shared/lib/sdk/sync.ts Outdated Show resolved Hide resolved
Copy link
Collaborator

@TBonnin TBonnin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

small comments. The most important is about precomputing valuesToFilter

onFulfilled: this.logAPICall.bind(this)
}
};
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do I read correctly that it doesn't override the interceptors defined a few lines above that is used for snapshoting in dry-mode?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes exactly, I'll add a comment

logger[logLevelToLogger[level] ?? 'info'].apply(null, [args[0], { status: args[1]?.response?.code || 'xxx' }] as any);
} else {
logger[logLevelToLogger[level] ?? 'info'].apply(null, args as any);
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would something like this be easier to read

const status = args[1]?.type == 'http' ? args[1].response?.code: undefined
const logArgs =  status ? [args[0], { status }] : args
logger[logLevelToLogger[level] ?? 'info'].apply(null, logArgs as any);

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

honestly I don't know ahah
I have split the repetitive part

return res;
}

const valuesToFilter: string[] = [
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agreed. The valuesToFilter should not changed within a single execution

@bodinsamuel bodinsamuel merged commit c53fdc6 into master Dec 3, 2024
21 checks passed
@bodinsamuel bodinsamuel deleted the sam/24_11_28/feat/sdk-log-http-req branch December 3, 2024 10:02
@bodinsamuel bodinsamuel restored the sam/24_11_28/feat/sdk-log-http-req branch December 3, 2024 10:13
@bodinsamuel bodinsamuel deleted the sam/24_11_28/feat/sdk-log-http-req branch December 3, 2024 10:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants