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

fix: fix telemetry for credential creates and updates #4125

Merged
merged 1 commit into from
Sep 16, 2022
Merged
Show file tree
Hide file tree
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
18 changes: 14 additions & 4 deletions packages/cli/src/InternalHooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,12 @@ export class InternalHooksClass implements IInternalHooksClass {

private nodeTypes: INodeTypes;

constructor(private telemetry: Telemetry, versionCli: string, nodeTypes: INodeTypes) {
constructor(
private telemetry: Telemetry,
private instanceId: string,
versionCli: string,
nodeTypes: INodeTypes,
) {
this.versionCli = versionCli;
this.nodeTypes = nodeTypes;
}
Expand Down Expand Up @@ -407,12 +412,14 @@ export class InternalHooksClass implements IInternalHooksClass {
*/

async onUserCreatedCredentials(userCreatedCredentialsData: {
user_id: string;
credential_type: string;
credential_id: string;
public_api: boolean;
}): Promise<void> {
return this.telemetry.track('User created credentials', userCreatedCredentialsData);
return this.telemetry.track('User created credentials', {
...userCreatedCredentialsData,
instance_id: this.instanceId,
});
}

async onUserSharedCredentials(userSharedCredentialsData: {
Expand All @@ -422,7 +429,10 @@ export class InternalHooksClass implements IInternalHooksClass {
user_ids_sharees_added: string[];
sharees_removed: number | null;
}): Promise<void> {
return this.telemetry.track('User updated cred sharing', userSharedCredentialsData);
return this.telemetry.track('User updated cred sharing', {
...userSharedCredentialsData,
instance_id: this.instanceId,
});
}

/**
Expand Down
1 change: 1 addition & 0 deletions packages/cli/src/InternalHooksManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export class InternalHooksManager {
if (!this.internalHooksInstance) {
this.internalHooksInstance = new InternalHooksClass(
new Telemetry(instanceId, versionCli),
instanceId,
versionCli,
nodeTypes,
);
Expand Down
1 change: 0 additions & 1 deletion packages/cli/src/credentials/credentials.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,6 @@ credentialsController.post(
const { id, ...rest } = await CredentialsService.save(newCredential, encryptedData, req.user);

void InternalHooksManager.getInstance().onUserCreatedCredentials({
user_id: req.user.id,
credential_type: rest.type,
credential_id: id.toString(),
public_api: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -796,8 +796,10 @@ export default mixins(showMessage, nodeHelpers).extend({
return null;
}

this.$externalHooks().run('credentials.create', {
credentialTypeData: this.credentialData,
this.$externalHooks().run('credential.saved', {
credential_type: credentialDetails.type,
credential_id: credential.id,
is_new: true,
});

this.$telemetry.track('User created credentials', {
Expand Down Expand Up @@ -828,6 +830,12 @@ export default mixins(showMessage, nodeHelpers).extend({
return null;
}

this.$externalHooks().run('credential.saved', {
credential_type: credentialDetails.type,
credential_id: credential.id,
is_new: false,
});

// Now that the credentials changed check if any nodes use credentials
// which have now a different name
this.updateNodesCredentialsIssues();
Expand Down