Skip to content

Commit

Permalink
feat: publish metrics events for outgoing integrations/addons
Browse files Browse the repository at this point in the history
  • Loading branch information
daveleek committed Aug 19, 2024
1 parent 6e4adbc commit 3ae5d7e
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/lib/addons/datadog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,13 @@ export default class DatadogAddon extends Addon {
state = 'failed';
const failedMessage = `Datadog Events API request failed with status code: ${res.status}.`;
stateDetails.push(failedMessage);
if (this.flagResolver.isEnabled('addonUsageMetrics')) {
this.eventBus.emit(ADDON_EVENTS_HANDLED, {
result: state,
destination: 'datadog',
});
}

this.logger.warn(failedMessage);
}

Expand Down
8 changes: 8 additions & 0 deletions src/lib/addons/new-relic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
import { gzip } from 'node:zlib';
import { promisify } from 'util';
import type { IntegrationEventState } from '../features/integration-events/integration-events-store';
import { ADDON_EVENTS_HANDLED } from '../metric-events';

const asyncGzip = promisify(gzip);

Expand Down Expand Up @@ -121,6 +122,13 @@ export default class NewRelicAddon extends Addon {
this.logger.warn(failedMessage);
}

if (this.flagResolver.isEnabled('addonUsageMetrics')) {
this.eventBus.emit(ADDON_EVENTS_HANDLED, {
result: state,
destination: 'new-relic',
});
}

this.registerEvent({
integrationId,
state,
Expand Down
7 changes: 7 additions & 0 deletions src/lib/addons/slack-app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,13 @@ export default class SlackAppAddon extends Addon {
stateDetails.push(eventErrorMessage);
this.logger.warn(eventErrorMessage);
const errorMessage = this.parseError(error);
if (this.flagResolver.isEnabled('addonUsageMetrics')) {
this.eventBus.emit(ADDON_EVENTS_HANDLED, {
result: state,
destination: 'slack-app',
});
}

stateDetails.push(errorMessage);
this.logger.warn(errorMessage, error);
} finally {
Expand Down
7 changes: 7 additions & 0 deletions src/lib/addons/slack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,13 @@ export default class SlackAddon extends Addon {
state = 'successWithErrors';
const successWithErrorsMessage = `Some (${failedRequests.length} of ${results.length}) Slack webhook requests failed. Status codes: ${codes}.`;
stateDetails.push(successWithErrorsMessage);
if (this.flagResolver.isEnabled('addonUsageMetrics')) {
this.eventBus.emit(ADDON_EVENTS_HANDLED, {
result: state,
destination: 'slack',
});
}

this.logger.warn(successWithErrorsMessage);
}

Expand Down
7 changes: 7 additions & 0 deletions src/lib/addons/teams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,13 @@ export default class TeamsAddon extends Addon {
state = 'failed';
const failedMessage = `Teams webhook request failed with status code: ${res.status}.`;
stateDetails.push(failedMessage);
if (this.flagResolver.isEnabled('addonUsageMetrics')) {
this.eventBus.emit(ADDON_EVENTS_HANDLED, {
result: state,
destination: 'teams',
});
}

this.logger.warn(failedMessage);
}

Expand Down
7 changes: 7 additions & 0 deletions src/lib/addons/webhook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,13 @@ export default class Webhook extends Addon {
state = 'failed';
const failedMessage = `Webhook request failed with status code: ${res.status}.`;
stateDetails.push(failedMessage);
if (this.flagResolver.isEnabled('addonUsageMetrics')) {
this.eventBus.emit(ADDON_EVENTS_HANDLED, {
result: state,
destination: 'webhook',
});
}

this.logger.warn(failedMessage);
}

Expand Down

0 comments on commit 3ae5d7e

Please sign in to comment.