Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

fix(cdp): stop the pagerduty destination failing on source and region (#108213)

Meikel Ratz383a60f627b6
diff --git a/nodejs/src/cdp/templates/_destinations/pagerduty/pagerduty.template.test.ts b/nodejs/src/cdp/templates/_destinations/pagerduty/pagerduty.template.test.ts
index 195c960a3565..eeff70bd3721 100644
--- a/nodejs/src/cdp/templates/_destinations/pagerduty/pagerduty.template.test.ts
+++ b/nodejs/src/cdp/templates/_destinations/pagerduty/pagerduty.template.test.ts
@@ -104,6 +104,35 @@ describe('pagerduty template', () => {
expect(sentBody(response).payload.severity).toBe('error')
})
+ it.each([
+ ['the event property when it is set', 'checkout-api', 'checkout-api'],
+ ['the project name when the event property is empty', '', 'project-name'],
+ ['the project name when the event property is missing', undefined, 'project-name'],
+ ])('defaults the source to %s', async (_label, eventSource, expected) => {
+ const { source: _omitted, ...withoutSource } = inputs()
+ const response = await tester.invoke(
+ withoutSource,
+ eventSource === undefined ? {} : { event: { properties: { source: eventSource } } }
+ )
+
+ expect(sentBody(response).payload.source).toBe(expected)
+ })
+
+ it.each(['', null])('sends a fallback source when the source renders as %p', async (source) => {
+ const response = await tester.invoke(inputs({ source }))
+
+ expect(sentBody(response).payload.source).toBe('PostHog')
+ })
+
+ it.each([
+ ['us', ENQUEUE_URL],
+ ['eu', 'https://events.eu.pagerduty.com/v2/enqueue'],
+ ])('posts to the %s endpoint', async (region, url) => {
+ const response = await tester.invoke(inputs({ region }))
+
+ expect(response.invocation.queueParameters).toMatchObject({ url })
+ })
+
it('cuts the summary to the PagerDuty limit', async () => {
const response = await tester.invoke(inputs({ summary: 'x'.repeat(1100) }))
diff --git a/nodejs/src/cdp/templates/_destinations/pagerduty/pagerduty.template.ts b/nodejs/src/cdp/templates/_destinations/pagerduty/pagerduty.template.ts
index d4a084997979..0e09e78c2a44 100644
--- a/nodejs/src/cdp/templates/_destinations/pagerduty/pagerduty.template.ts
+++ b/nodejs/src/cdp/templates/_destinations/pagerduty/pagerduty.template.ts
@@ -31,9 +31,17 @@ if (action == 'trigger') {
severity := 'error'
}
+ // PagerDuty answers a blank payload.source with a 400 that names the field, which reads as a
+ // configuration mistake. The default value ends at project.name, which is empty when the team
+ // row carries no name, so a correctly configured destination can still send nothing.
+ let source := inputs.source
+ if (empty(source)) {
+ source := 'PostHog'
+ }
+
let payload := {
'summary': substring(inputs.summary, 1, 1024),
- 'source': inputs.source,
+ 'source': source,
'severity': severity
}
if (notEmpty(inputs.component)) {
@@ -55,7 +63,12 @@ if (action == 'trigger') {
throw Error(f'A dedup key is required to {action} an incident.')
}
-let res := fetch('https://events.pagerduty.com/v2/enqueue', {
+let endpoint := 'https://events.pagerduty.com/v2/enqueue'
+if (inputs.region == 'eu') {
+ endpoint := 'https://events.eu.pagerduty.com/v2/enqueue'
+}
+
+let res := fetch(endpoint, {
'method': 'POST',
'headers': {
'Content-Type': 'application/json'
@@ -76,6 +89,20 @@ if (res.status < 200 or res.status >= 300) {
secret: true,
required: true,
},
+ {
+ key: 'region',
+ type: 'choice',
+ label: 'Region',
+ description:
+ 'The PagerDuty service region your account runs in. A routing key only works in its own region.',
+ choices: [
+ { label: 'US', value: 'us' },
+ { label: 'EU', value: 'eu' },
+ ],
+ default: 'us',
+ secret: false,
+ required: true,
+ },
{
key: 'event_action',
type: 'choice',
@@ -115,7 +142,7 @@ if (res.status < 200 or res.status >= 300) {
type: 'string',
label: 'Source',
description: 'The system that has the problem.',
- default: '{project.name}',
+ default: '{notEmpty(event.properties.source) ? event.properties.source : project.name}',
secret: false,
required: true,
},
diff --git a/nodejs/tests/fixtures/hog-bytecode/29385c852f546a9b210e11c8bdeb4f88c62a6ae4f8aa884db1331f09e2acedee.json b/nodejs/tests/fixtures/hog-bytecode/29385c852f546a9b210e11c8bdeb4f88c62a6ae4f8aa884db1331f09e2acedee.json
new file mode 100644
index 000000000000..903a7bc6d510
--- /dev/null
+++ b/nodejs/tests/fixtures/hog-bytecode/29385c852f546a9b210e11c8bdeb4f88c62a6ae4f8aa884db1331f09e2acedee.json
@@ -0,0 +1 @@
+["_H",1,32,"us",38]
diff --git a/nodejs/tests/fixtures/hog-bytecode/29566ce981e7541a9e9934054521ee134505f7f843ccc262a8a8a9869fccda55.json b/nodejs/tests/fixtures/hog-bytecode/29566ce981e7541a9e9934054521ee134505f7f843ccc262a8a8a9869fccda55.json
new file mode 100644
index 000000000000..f9435cc0f42b
--- /dev/null
+++ b/nodejs/tests/fixtures/hog-bytecode/29566ce981e7541a9e9934054521ee134505f7f843ccc262a8a8a9869fccda55.json
@@ -0,0 +1 @@
+["_H",1,32,"k",38]
diff --git a/nodejs/tests/fixtures/hog-bytecode/500d7ebac76aff550817c07c4bf6e3b1e63b2224b2f3e66a9a2a5f1aef4639ed.json b/nodejs/tests/fixtures/hog-bytecode/500d7ebac76aff550817c07c4bf6e3b1e63b2224b2f3e66a9a2a5f1aef4639ed.json
new file mode 100644
index 000000000000..210badcb151b
--- /dev/null
+++ b/nodejs/tests/fixtures/hog-bytecode/500d7ebac76aff550817c07c4bf6e3b1e63b2224b2f3e66a9a2a5f1aef4639ed.json
@@ -0,0 +1 @@
+["_H",1,32,"event_action",32,"inputs",1,2,32,"trigger",32,"acknowledge",32,"resolve",43,3,36,0,2,"has",2,5,40,13,32,"Unsupported event action \"",36,0,32,"\". Use trigger, acknowledge or resolve.",2,"concat",3,2,"Error",1,49,32,"routing_key",32,"routing_key",32,"inputs",1,2,32,"event_action",36,0,42,2,32,"dedup_key",32,"inputs",1,2,2,"notEmpty",1,40,11,36,1,32,"dedup_key",32,"dedup_key",32,"inputs",1,2,46,32,"trigger",36,0,11,40,177,32,"severity",32,"inputs",1,2,32,"critical",32,"error",32,"warning",32,"info",43,4,36,2,2,"has",2,5,40,4,32,"error",37,2,32,"source",32,"inputs",1,2,36,3,2,"empty",1,40,4,32,"PostHog",37,3,32,"summary",32,"summary",32,"inputs",1,2,33,1,33,1024,2,"substring",3,32,"source",36,3,32,"severity",36,2,42,3,32,"component",32,"inputs",1,2,2,"notEmpty",1,40,11,36,4,32,"component",32,"component",32,"inputs",1,2,46,32,"event_class",32,"inputs",1,2,2,"notEmpty",1,40,11,36,4,32,"class",32,"event_class",32,"inputs",1,2,46,32,"custom_details",32,"inputs",1,2,2,"notEmpty",1,40,11,36,4,32,"custom_details",32,"custom_details",32,"inputs",1,2,46,36,1,32,"payload",36,4,46,36,1,32,"client",32,"PostHog",46,32,"links",32,"inputs",1,2,2,"notEmpty",1,40,11,36,1,32,"links",32,"links",32,"inputs",1,2,46,35,35,35,39,24,32,"dedup_key",32,"inputs",1,2,2,"empty",1,40,13,32,"A dedup key is required to ",36,0,32," an incident.",2,"concat",3,2,"Error",1,49,32,"https://events.pagerduty.com/v2/enqueue",32,"method",32,"POST",32,"headers",32,"Content-Type",32,"application/json",42,1,32,"body",36,1,42,3,2,"fetch",2,33,200,36,2,32,"status",45,15,33,300,36,2,32,"status",45,14,4,2,40,21,32,"PagerDuty rejected the event: ",36,2,32,"status",45,32,": ",36,2,32,"body",45,2,"concat",4,2,"Error",1,49,35,35,35]
diff --git a/nodejs/tests/fixtures/hog-bytecode/6a7be255f66a1ccf2c78299ec4a48484565597029d4052bcf9c1adbada33a56f.json b/nodejs/tests/fixtures/hog-bytecode/6a7be255f66a1ccf2c78299ec4a48484565597029d4052bcf9c1adbada33a56f.json
new file mode 100644
index 000000000000..cfed676ef753
--- /dev/null
+++ b/nodejs/tests/fixtures/hog-bytecode/6a7be255f66a1ccf2c78299ec4a48484565597029d4052bcf9c1adbada33a56f.json
@@ -0,0 +1 @@
+["_H",1,32,"name",32,"project",1,2,38]
diff --git a/nodejs/tests/fixtures/hog-bytecode/7906bdf8543e14dd0106fcd98fb970e8f30094a25e3591ca2239c9aac9f8068c.json b/nodejs/tests/fixtures/hog-bytecode/7906bdf8543e14dd0106fcd98fb970e8f30094a25e3591ca2239c9aac9f8068c.json
new file mode 100644
index 000000000000..7ab72816c7e5
--- /dev/null
+++ b/nodejs/tests/fixtures/hog-bytecode/7906bdf8543e14dd0106fcd98fb970e8f30094a25e3591ca2239c9aac9f8068c.json
@@ -0,0 +1 @@
+["_H",1,32,"source",32,"properties",32,"event",1,3,2,"notEmpty",1,40,10,32,"source",32,"properties",32,"event",1,3,39,6,32,"name",32,"project",1,2,38]
diff --git a/nodejs/tests/fixtures/hog-bytecode/7a4a1db95eb00971e1c98477ebeee366142cb323618ccfa6c746820b86d89ec6.json b/nodejs/tests/fixtures/hog-bytecode/7a4a1db95eb00971e1c98477ebeee366142cb323618ccfa6c746820b86d89ec6.json
new file mode 100644
index 000000000000..cc048e00fd84
--- /dev/null
+++ b/nodejs/tests/fixtures/hog-bytecode/7a4a1db95eb00971e1c98477ebeee366142cb323618ccfa6c746820b86d89ec6.json
@@ -0,0 +1 @@
+["_H",1,32,"source",32,"properties",32,"event",1,3,47,7,35,32,"name",32,"project",1,2,38]
diff --git a/nodejs/tests/fixtures/hog-bytecode/8d9c5ce5508b882885b46c1e0db1b0f37d25cf3fdcbf93d0f9b319e4c3394a76.json b/nodejs/tests/fixtures/hog-bytecode/8d9c5ce5508b882885b46c1e0db1b0f37d25cf3fdcbf93d0f9b319e4c3394a76.json
new file mode 100644
index 000000000000..45efd6eba453
--- /dev/null
+++ b/nodejs/tests/fixtures/hog-bytecode/8d9c5ce5508b882885b46c1e0db1b0f37d25cf3fdcbf93d0f9b319e4c3394a76.json
@@ -0,0 +1 @@
+["_H",1,32,"event_action",32,"inputs",1,2,32,"trigger",32,"acknowledge",32,"resolve",43,3,36,0,2,"has",2,5,40,13,32,"Unsupported event action \"",36,0,32,"\". Use trigger, acknowledge or resolve.",2,"concat",3,2,"Error",1,49,32,"routing_key",32,"routing_key",32,"inputs",1,2,32,"event_action",36,0,42,2,32,"dedup_key",32,"inputs",1,2,2,"notEmpty",1,40,11,36,1,32,"dedup_key",32,"dedup_key",32,"inputs",1,2,46,32,"trigger",36,0,11,40,177,32,"severity",32,"inputs",1,2,32,"critical",32,"error",32,"warning",32,"info",43,4,36,2,2,"has",2,5,40,4,32,"error",37,2,32,"source",32,"inputs",1,2,36,3,2,"empty",1,40,4,32,"PostHog",37,3,32,"summary",32,"summary",32,"inputs",1,2,33,1,33,1024,2,"substring",3,32,"source",36,3,32,"severity",36,2,42,3,32,"component",32,"inputs",1,2,2,"notEmpty",1,40,11,36,4,32,"component",32,"component",32,"inputs",1,2,46,32,"event_class",32,"inputs",1,2,2,"notEmpty",1,40,11,36,4,32,"class",32,"event_class",32,"inputs",1,2,46,32,"custom_details",32,"inputs",1,2,2,"notEmpty",1,40,11,36,4,32,"custom_details",32,"custom_details",32,"inputs",1,2,46,36,1,32,"payload",36,4,46,36,1,32,"client",32,"PostHog",46,32,"links",32,"inputs",1,2,2,"notEmpty",1,40,11,36,1,32,"links",32,"links",32,"inputs",1,2,46,35,35,35,39,24,32,"dedup_key",32,"inputs",1,2,2,"empty",1,40,13,32,"A dedup key is required to ",36,0,32," an incident.",2,"concat",3,2,"Error",1,49,32,"https://events.pagerduty.com/v2/enqueue",32,"eu",32,"region",32,"inputs",1,2,11,40,4,32,"https://events.eu.pagerduty.com/v2/enqueue",37,2,36,2,32,"method",32,"POST",32,"headers",32,"Content-Type",32,"application/json",42,1,32,"body",36,1,42,3,2,"fetch",2,33,200,36,3,32,"status",45,15,33,300,36,3,32,"status",45,14,4,2,40,21,32,"PagerDuty rejected the event: ",36,3,32,"status",45,32,": ",36,3,32,"body",45,2,"concat",4,2,"Error",1,49,35,35,35,35]
diff --git a/nodejs/tests/fixtures/hog-bytecode/90ef20b108abaf1693deda90fe8176fef34f987fe61e961b4eb2c12b3d965ae6.json b/nodejs/tests/fixtures/hog-bytecode/90ef20b108abaf1693deda90fe8176fef34f987fe61e961b4eb2c12b3d965ae6.json
new file mode 100644
index 000000000000..2f720eef914f
--- /dev/null
+++ b/nodejs/tests/fixtures/hog-bytecode/90ef20b108abaf1693deda90fe8176fef34f987fe61e961b4eb2c12b3d965ae6.json
@@ -0,0 +1 @@
+["_H",1,32,"View event in PostHog",38]
diff --git a/nodejs/tests/fixtures/hog-bytecode/af7a13f9444626da5f2299fefaba23eb07f06895a0f14ba30829dcb1f835e06f.json b/nodejs/tests/fixtures/hog-bytecode/af7a13f9444626da5f2299fefaba23eb07f06895a0f14ba30829dcb1f835e06f.json
new file mode 100644
index 000000000000..86d3e9883ce4
--- /dev/null
+++ b/nodejs/tests/fixtures/hog-bytecode/af7a13f9444626da5f2299fefaba23eb07f06895a0f14ba30829dcb1f835e06f.json
@@ -0,0 +1 @@
+["_H",1,32,"eu",38]
diff --git a/nodejs/tests/fixtures/hog-bytecode/b1c413bc1e089c467a1cc907e77e681c8d89cca5aec132c8344bc7a1afd19391.json b/nodejs/tests/fixtures/hog-bytecode/b1c413bc1e089c467a1cc907e77e681c8d89cca5aec132c8344bc7a1afd19391.json
new file mode 100644
index 000000000000..b9ec24b30ad2
--- /dev/null
+++ b/nodejs/tests/fixtures/hog-bytecode/b1c413bc1e089c467a1cc907e77e681c8d89cca5aec132c8344bc7a1afd19391.json
@@ -0,0 +1 @@
+["_H",1,32,"error",38]
diff --git a/nodejs/tests/fixtures/hog-bytecode/d77e9e21bf59b1e8e39c15a3f4f1b7af0ea68a037221f2f03d3f8ee47e359f3e.json b/nodejs/tests/fixtures/hog-bytecode/d77e9e21bf59b1e8e39c15a3f4f1b7af0ea68a037221f2f03d3f8ee47e359f3e.json
new file mode 100644
index 000000000000..27fece470ea0
--- /dev/null
+++ b/nodejs/tests/fixtures/hog-bytecode/d77e9e21bf59b1e8e39c15a3f4f1b7af0ea68a037221f2f03d3f8ee47e359f3e.json
@@ -0,0 +1 @@
+["_H",1,32,"url",32,"event",1,2,38]
diff --git a/nodejs/tests/fixtures/hog-bytecode/e81c4ad70e6fa7b492b2880e250dc2af49a0bcc7f92bfb1a8d87dc777b16e65c.json b/nodejs/tests/fixtures/hog-bytecode/e81c4ad70e6fa7b492b2880e250dc2af49a0bcc7f92bfb1a8d87dc777b16e65c.json
new file mode 100644
index 000000000000..c638d717bcb5
--- /dev/null
+++ b/nodejs/tests/fixtures/hog-bytecode/e81c4ad70e6fa7b492b2880e250dc2af49a0bcc7f92bfb1a8d87dc777b16e65c.json
@@ -0,0 +1 @@
+["_H",1,32,"event",32,"event",1,2,32," by ",32,"name",32,"person",1,2,2,"concat",3,38]
diff --git a/nodejs/tests/fixtures/hog-bytecode/ed0ca13973ea6893befa55b3d17540fc3f112d1f19f798bd1f562f02fadb4f86.json b/nodejs/tests/fixtures/hog-bytecode/ed0ca13973ea6893befa55b3d17540fc3f112d1f19f798bd1f562f02fadb4f86.json
new file mode 100644
index 000000000000..210badcb151b
--- /dev/null
+++ b/nodejs/tests/fixtures/hog-bytecode/ed0ca13973ea6893befa55b3d17540fc3f112d1f19f798bd1f562f02fadb4f86.json
@@ -0,0 +1 @@
+["_H",1,32,"event_action",32,"inputs",1,2,32,"trigger",32,"acknowledge",32,"resolve",43,3,36,0,2,"has",2,5,40,13,32,"Unsupported event action \"",36,0,32,"\". Use trigger, acknowledge or resolve.",2,"concat",3,2,"Error",1,49,32,"routing_key",32,"routing_key",32,"inputs",1,2,32,"event_action",36,0,42,2,32,"dedup_key",32,"inputs",1,2,2,"notEmpty",1,40,11,36,1,32,"dedup_key",32,"dedup_key",32,"inputs",1,2,46,32,"trigger",36,0,11,40,177,32,"severity",32,"inputs",1,2,32,"critical",32,"error",32,"warning",32,"info",43,4,36,2,2,"has",2,5,40,4,32,"error",37,2,32,"source",32,"inputs",1,2,36,3,2,"empty",1,40,4,32,"PostHog",37,3,32,"summary",32,"summary",32,"inputs",1,2,33,1,33,1024,2,"substring",3,32,"source",36,3,32,"severity",36,2,42,3,32,"component",32,"inputs",1,2,2,"notEmpty",1,40,11,36,4,32,"component",32,"component",32,"inputs",1,2,46,32,"event_class",32,"inputs",1,2,2,"notEmpty",1,40,11,36,4,32,"class",32,"event_class",32,"inputs",1,2,46,32,"custom_details",32,"inputs",1,2,2,"notEmpty",1,40,11,36,4,32,"custom_details",32,"custom_details",32,"inputs",1,2,46,36,1,32,"payload",36,4,46,36,1,32,"client",32,"PostHog",46,32,"links",32,"inputs",1,2,2,"notEmpty",1,40,11,36,1,32,"links",32,"links",32,"inputs",1,2,46,35,35,35,39,24,32,"dedup_key",32,"inputs",1,2,2,"empty",1,40,13,32,"A dedup key is required to ",36,0,32," an incident.",2,"concat",3,2,"Error",1,49,32,"https://events.pagerduty.com/v2/enqueue",32,"method",32,"POST",32,"headers",32,"Content-Type",32,"application/json",42,1,32,"body",36,1,42,3,2,"fetch",2,33,200,36,2,32,"status",45,15,33,300,36,2,32,"status",45,14,4,2,40,21,32,"PagerDuty rejected the event: ",36,2,32,"status",45,32,": ",36,2,32,"body",45,2,"concat",4,2,"Error",1,49,35,35,35]
diff --git a/nodejs/tests/fixtures/hog-bytecode/f05b4f47f219b272b8d447c0f02043329a6abd7625900ef36088c58460d1ac18.json b/nodejs/tests/fixtures/hog-bytecode/f05b4f47f219b272b8d447c0f02043329a6abd7625900ef36088c58460d1ac18.json
new file mode 100644
index 000000000000..6876dceeda88
--- /dev/null
+++ b/nodejs/tests/fixtures/hog-bytecode/f05b4f47f219b272b8d447c0f02043329a6abd7625900ef36088c58460d1ac18.json
@@ -0,0 +1 @@
+["_H",1,32,"abc123",38]