Skip to content

Commit

Permalink
fix(plugin-server): adjust webhook body (PostHog#19361)
Browse files Browse the repository at this point in the history
  • Loading branch information
bretthoerner authored and jacobwgillespie committed Jan 12, 2024
1 parent 0ae0364 commit eb1da14
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions plugin-server/src/worker/plugins/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,21 +76,26 @@ export async function runOnEvent(hub: Hub, event: ProcessedPluginEvent): Promise
const RUSTY_HOOK_BASE_DELAY_MS = 100
const MAX_RUSTY_HOOK_DELAY_MS = 30_000

interface RustyWebhookPayload extends Webhook {
team_id: number
plugin_id: number
plugin_config_id: number
interface RustyWebhookPayload {
parameters: Webhook
metadata: {
team_id: number
plugin_id: number
plugin_config_id: number
}
}

async function enqueueInRustyHook(hub: Hub, webhook: Webhook, pluginConfig: PluginConfig) {
webhook.method ??= 'POST'
webhook.headers ??= {}

const rustyWebhookPayload: RustyWebhookPayload = {
...webhook,
team_id: pluginConfig.team_id,
plugin_id: pluginConfig.plugin_id,
plugin_config_id: pluginConfig.id,
parameters: webhook,
metadata: {
team_id: pluginConfig.team_id,
plugin_id: pluginConfig.plugin_id,
plugin_config_id: pluginConfig.id,
},
}
const body = JSON.stringify(rustyWebhookPayload, undefined, 4)

Expand Down Expand Up @@ -129,7 +134,10 @@ async function enqueueInRustyHook(hub: Hub, webhook: Webhook, pluginConfig: Plug
.labels(pluginConfig.plugin_id.toString(), 'enqueueRustyHook', 'error')
.observe(new Date().getTime() - timer.getTime())

const redactedWebhook = { ...rustyWebhookPayload, body: '<redacted>' }
const redactedWebhook = {
parameters: { ...rustyWebhookPayload.parameters, body: '<redacted>' },
metadata: rustyWebhookPayload.metadata,
}
status.error('🔴', 'Webhook enqueue to rusty-hook failed', { error, redactedWebhook, attempt })
Sentry.captureException(error, { extra: { redactedWebhook } })
}
Expand Down

0 comments on commit eb1da14

Please sign in to comment.