You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert

12
12
13
13
You can configure the details about this setting, which change how it's displayed to anyone using your function:
14
14
@@ -25,4 +25,4 @@ Click **Add Setting** to save the new setting.
25
25
26
26
Once you save a setting, it appears in the **Settings** tab for the function. You can edit or delete settings from this tab.
Copy file name to clipboardExpand all lines: src/connections/functions/destination-functions.md
+22-24Lines changed: 22 additions & 24 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -11,26 +11,26 @@ Destination functions allow you to transform and annotate your Segment events an
11
11
All functions are scoped to your workspace, so members of other workspaces can't view or use them.
12
12
13
13
> info ""
14
-
> Functions is available to all customer plan types with a free allotment of usage hours. Read more about [Functions usage limits](/docs/connections/functions/usage/), or see [your workspace's Functions usage stats](https://app.segment.com/goto-my-workspace/settings/usage?metric=functions).
14
+
> Functions is available to all customer plan types with a free allotment of usage hours. Read more about [Functions usage limits](/docs/connections/functions/usage/), or see [your workspace's Functions usage stats](https://app.segment.com/goto-my-workspace/settings/usage?metric=functions){:target="_blank"}.
15
15
16
-

16
+

17
17
18
18
19
19
> note ""
20
20
> Destination functions does not accept data from [Object Cloud sources](/docs/connections/sources/#object-cloud-sources).
21
21
22
22
## Create a destination function
23
23
24
-
1. From your workspace, go to the Catalog and click the [Functions tab](https://app.segment.com/goto-my-workspace/functions/catalog).
24
+
1. From your workspace, go to the Catalog and click the [Functions tab](https://app.segment.com/goto-my-workspace/functions/catalog){:target="_blank"}.
25
25
2. Click **New Function**.
26
26
3. Select **Destination Function** and click **Build**.
27
27
28
28
> success ""
29
-
> **Tip:** Want to see some example functions? Check out the templates available in the Functions UI, or in the open-source [Segment Functions Library](https://github.com/segmentio/functions-library). (Contributions welcome!)
29
+
> **Tip:** Want to see some example functions? Check out the templates available in the Functions UI, or in the open-source [Segment Functions Library](https://github.com/segmentio/functions-library){:target="_blank"}. (Contributions welcome!)
30
30
31
31
When you click **Build**, a code editor appears. Use the editor to write the code for your function, configure settings, and test the function's behavior.
32
32
33
-

33
+
<!---  --->
34
34
35
35
## Code the destination function
36
36
@@ -78,7 +78,7 @@ async function onTrack(event) {
78
78
To change which event type the handler listens to, you can rename it to the name of the message type. For example, if you rename this function `onIdentify`, it listens for "Identify" events instead.
79
79
80
80
> info ""
81
-
> Functions' runtime includes a `fetch()` polyfill using a `node-fetch` package. Check out the [node-fetch documentation](https://www.npmjs.com/package/node-fetch) for usage examples.
81
+
> Functions' runtime includes a `fetch()` polyfill using a `node-fetch` package. Check out the [node-fetch documentation](https://www.npmjs.com/package/node-fetch){:target="_blank"} for usage examples.
82
82
83
83
### Errors and error handling
84
84
@@ -140,16 +140,15 @@ You can read more about [error handling](#destination-functions-logs-and-errors)
140
140
{% include content/functions/runtime.md %}
141
141
142
142
143
-
<!-- TODO - could also go into the `runtime.md` include above, if applied identically to both types of functions.
144
-
## Batching in functions -->
143
+
<!-- TODO - could also go into the `runtime.md` include above, if applied identically to both types of functions. -->
145
144
146
145
## Create settings and secrets
147
146
148
147
{% include content/functions/settings.md %}
149
148
150
149
Next, fill out this setting's value in the **Test** tab, so you can run the function and verify that the correct setting value is passed. (This value is only for testing your function.)
151
150
152
-
{:width="500"}
151
+
<!-- {:width="500"}-->
153
152
154
153
Now that you've configured a setting and entered a test value, you can add code to read its value and run the function, as in the example below:
155
154
@@ -162,8 +161,6 @@ async function onTrack(request, settings) {
162
161
163
162
When you deploy your destination function in your workspace, you fill out the settings on the destination configuration page, similar to how you would configure a normal destination.
164
163
165
-

166
-
167
164
## Test the destination function
168
165
169
166
You can test your code directly from the editor in two ways:
@@ -172,15 +169,15 @@ You can test your code directly from the editor in two ways:
172
169
173
170
Click **Use Sample Event** and select the source to use events from.
174
171
175
-

172
+

176
173
177
174
Click **Run** to test your function with the event you selected.
178
175
179
176
### Test using manual input
180
177
181
178
You can also manually include your own JSON payload of a Segment event, instead of fetching a sample from one of your workspace sources.

184
181
185
182
If your function fails, you can check the error details and logs in the **Output** section.
186
183
@@ -282,9 +279,12 @@ By default, Functions waits up to 10 seconds to form a batch of 20 events. You c
282
279
283
280
### Test the batch handler
284
281
285
-
The [Functions editing environment](/docs/connections/functions/environment/) supports testing batch handlers. In the right panel of the Functions editor, click **customize the event yourself** to enter Manual Mode. Add events as a JSON array, with one event per element. Click **Run** to preview the batch handler with the specified events.
282
+
The [Functions editing environment](/docs/connections/functions/environment/) supports testing batch handlers.
1. In the right panel of the Functions editor, click **customize the event yourself** to enter Manual Mode.
286
+
2. Add events as a JSON array, with one event per element.
287
+
3. Click **Run** to preview the batch handler with the specified events.
288
288
289
289
> note ""
290
290
> The Sample Event option tests single events only. You must use Manual Mode to add more than one event so you can test batch handlers.
@@ -322,12 +322,12 @@ You can also choose to **Save & Deploy** to save the changes, and then choose wh
322
322
323
323
A function can throw errors, or Segment might encounter errors while invoking your function. You can view these errors in the [Event Delivery](/docs/connections/event-delivery/) tab for your Destination as in the example below.
324
324
325
-

325
+

326
326
327
327
### Destination functions error types
328
328
329
329
-**Bad Request** - Any error thrown by the function code that is not covered by the other errors.
330
-
-**Invalid Settings** - A configuration error prevented Segment from executing your code. If this error persists for more than an hour, [contact Segment Support](https://segment.com/help/contact/).
330
+
-**Invalid Settings** - A configuration error prevented Segment from executing your code. If this error persists for more than an hour, [contact Segment Support](https://segment.com/help/contact/){:target="_blank"}.
331
331
-**Message Rejected** - Your code threw `InvalidEventPayload` or `ValidationError` due to invalid input.
332
332
-**Unsupported Event Type** - Your code does not implement a specific event type (`onTrack()`, etc.) or threw a `EventNotSupported` error.
333
333
-**Retry** - Your code threw `RetryError` indicating that the function should be retried.
@@ -340,9 +340,7 @@ If your function throws an error, execution halts immediately. Segment captures
340
340
341
341
Segment then displays the captured error information in the [Event Delivery](/docs/connections/event-delivery/) page for your destination function. You can use this information to find and fix unexpected errors.
342
342
343
-

344
-
345
-
You can throw [an error or a custom error](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error) and you can also add helpful context in logs using the [`console` API](https://developer.mozilla.org/en-US/docs/Web/API/console). For example:
343
+
You can throw [an error or a custom error](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error){:target="_blank"} and you can also add helpful context in logs using the [`console` API](https://developer.mozilla.org/en-US/docs/Web/API/console){:target="_blank"}. For example:
346
344
347
345
```js
348
346
asyncfunctiononTrack(event, settings) {
@@ -394,7 +392,7 @@ async function getAccessToken () {
394
392
395
393
### Editing and deleting functions
396
394
397
-
If you are a **Workspace Owner** or **Functions Admin**, you can manage your function from the [Functions](https://app.segment.com/goto-my-workspace/functions/catalog) page.
395
+
If you are a **Workspace Owner** or **Functions Admin**, you can manage your function from the [Functions](https://app.segment.com/goto-my-workspace/functions/catalog){:target="_blank"} page.
398
396
399
397
400
398
### Monitoring destination functions
@@ -429,19 +427,19 @@ Yes, Functions access is logged in the [Audit Trail](/docs/segment-app/iam/audit
429
427
430
428
##### Does Segment retry failed function invocations?
431
429
432
-
Segment retries 9 times over the course of 4 hours. This increases the number of attempts for messages, so we try to re-deliver them another 4 times after some backoff. Segment doesn't retry if your function throws a [non-recoverable error](#errors-and-error-handling).
430
+
Segment retries 9 times over the course of 4 hours. This increases the number of attempts for messages, so Segment tries to re-deliver them another 4 times after some backoff. Segment doesn't retry if your function throws a [non-recoverable error](#errors-and-error-handling).
433
431
434
432
##### Are events guaranteed to send data in order?
435
433
436
434
No, Segment can't guarantee the order in which the events are delivered to an endpoint.
437
435
438
436
##### Can I create a device-mode destination?
439
437
440
-
No, destination functions are currently available as cloud-mode destinations only. We're in the early phases of exploration and discovery for supporting customer "web plugins" for custom device-mode destinations and other use cases, but this is unsupported today.
438
+
No, destination functions are currently available as cloud-mode destinations only. Segment is in the early phases of exploration and discovery for supporting customer "web plugins" for custom device-mode destinations and other use cases, but this is unsupported today.
441
439
442
440
##### How do I publish a destination to the public Segment catalog?
443
441
444
-
If you are a partner, looking to publish your destination and distribute your app through Segment catalog, visit the [Developer Center](https://segment.com/partners/developer-center/) and check out our[partner docs](/docs/partners/).
442
+
If you are a partner, looking to publish your destination and distribute your app through Segment catalog, visit the [Developer Center](https://segment.com/partners/developer-center/){:target="_blank"} and check out the Segment[partner docs](/docs/partners/).
0 commit comments