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
Copy file name to clipboardExpand all lines: src/connections/functions/destination-functions.md
+18-18Lines changed: 18 additions & 18 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -28,7 +28,7 @@ All functions are scoped to your workspace, so members of other workspaces can't
28
28
After you click **Next: Build Function**, a code editor appears. Use the editor to write the code for your function, configure settings, and test the function's behavior.
29
29
30
30
> success ""
31
-
> **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"}.
31
+
> 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"}.
32
32
33
33
34
34
## Code the destination function
@@ -53,10 +53,10 @@ Destination functions can define handlers for each message type in the [Segment
53
53
54
54
Each of the functions above accepts two arguments:
55
55
56
-
-**event** - Segment event object, where fields and values depend on the event type. For example, in "Identify" events, Segment formats the object to match the [Identify spec](/docs/connections/spec/identify/).
57
-
-**settings** - Set of [settings](#create-settings-and-secrets) for this function.
56
+
-**event**: Segment event object, where fields and values depend on the event type. For example, in Identify events, Segment formats the object to match the [Identify spec](/docs/connections/spec/identify/).
57
+
-**settings**: Set of [settings](#create-settings-and-secrets) for this function.
58
58
59
-
The example below shows a destination function that listens for "Track" events, and sends some details about them to an external service.
59
+
The example below shows a destination function that listens for Track events, and sends some details about them to an external service.
60
60
61
61
```js
62
62
asyncfunctiononTrack(event) {
@@ -74,7 +74,7 @@ async function onTrack(event) {
74
74
}
75
75
```
76
76
77
-
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.
77
+
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.
78
78
79
79
> info ""
80
80
> 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.
@@ -89,9 +89,9 @@ The handler for destination functions is event-specific. For example, you might
89
89
90
90
{% include content/functions/errors-and-error-handling.md %}
91
91
92
-
You can incorporate a a `try-catch` block to ensure smooth operation of functions even when fetch calls fail. This allows for the interception of any errors during the API call, enabling the application of specific error handling procedures, such as error logging for future debugging, or the assignment of fallback values when the API call is unsuccessful. By positioning the continuation logic either outside the `try-catch` block or within a `finally` block, the function is guaranteed to proceed with its execution, maintaining its workflow irrespective of the outcome of the API call.
92
+
You can incorporate a `try-catch` block to ensure smooth operation of functions even when fetch calls fail. This allows for the interception of any errors during the API call, enabling the application of specific error handling procedures, such as error logging for future debugging, or the assignment of fallback values when the API call is unsuccessful. By positioning the continuation logic either outside the `try-catch` block or within a `finally` block, the function is guaranteed to proceed with its execution, maintaining its workflow irrespective of the outcome of the API call.
93
93
94
-
You can read more about [error handling](#destination-functions-logs-and-errors)below.
94
+
See [error handling](#destination-functions-logs-and-errors)for additional details.
95
95
96
96
### Runtime and dependencies
97
97
@@ -140,8 +140,8 @@ You can also manually include your own JSON payload of a Segment event, instead
140
140
141
141
If your function fails, you can check the error details and logs in the **Output** section.
142
142
143
-
-**Error Message** - This shows the error surfaced from your function.
144
-
-**Logs** - This section displays any messages to `console.log()` from the function.
143
+
-**Error Message**: The error surfaced from your function.
144
+
-**Logs**: Messages to `console.log()` from the function.
145
145
146
146
## Batching the destination function
147
147
@@ -152,7 +152,7 @@ Batch handlers are an extension of destination functions. When you define an `on
152
152
153
153
### When to use batching
154
154
155
-
Consider creating a batch handler if:
155
+
Create a batch handler when:
156
156
157
157
-**Your function sends data to a service that has a batch endpoint.** Batch endpoints may allow you both to send more data downstream and stay within the rate limits imposed by the service. Batch handlers that use one or more batch endpoints improve the efficiency of the function, and enable it to scale more easily. Specifically, you can use batch handlers to build [list-based](/docs/engage/using-engage-data/#personas-destination-types-event-vs-list) Engage destinations.
158
158
-**You have a high-throughput function and want to reduce cost.** When you define a batch handler, Segment invokes the function once per *batch*, rather than once per event. As long as the function's execution time isn't adversely affected, the reduction in invocations should lead to a reduction in cost.
@@ -165,7 +165,7 @@ Consider creating a batch handler if:
165
165
Segment collects the events over a short period of time and combines them into a batch. The system flushes them when the batch reaches a certain number of events, or when the batch has been waiting for a specified wait time.
166
166
167
167
To create a batch handler, define an `onBatch` function within your destination function.
168
-
You can also use the "Default Batch" template found in the Functions editor to get started quickly.
168
+
You can also use the "Default Batch" template found in the functions editor to get started quickly.
169
169
170
170
```js
171
171
asyncfunctiononBatch(events, settings){
@@ -316,7 +316,7 @@ Standard [function error types](/docs/connections/functions/destination-function
316
316
317
317
For example, after receiving the responses above from the `onBatch` handler, Segment only retries **event_4** and **event_5**.
318
318
319
-
| Error Type| Result |
319
+
| Error type| Result |
320
320
| ---------------------- | ------- |
321
321
| Bad Request | Discard |
322
322
| Invalid Settings | Discard |
@@ -334,14 +334,14 @@ Once you do that, the destination function appears on the **Functions** page in
334
334
335
335
If you're editing an existing function, you can **Save** changes without updating instances of the function that are already deployed and running.
336
336
337
-
You can also choose to**Save & Deploy** to save the changes, and then choose which of the already-deployed functions to update with your changes. [You might need additional permissions](#functions-permissions) to update existing functions.
337
+
You can click**Save & Deploy** to save the changes, and then choose which of the already-deployed functions to update with your changes. [You might need additional permissions](#functions-permissions) to update existing functions.
338
338
339
339
## Destination functions logs and errors
340
340
341
341
{% include content/functions/logs.md %}
342
342
343
343
> warning ""
344
-
> **Warning:**Do not log sensitive data, such as personally-identifying information (PII), authentication tokens, or other secrets. Avoid logging entire request/response payloads. The **Function Logs** tab may be visible to other workspace members if they have the necessary permissions.
344
+
> Do not log sensitive data, such as personally-identifying information (PII), authentication tokens, or other secrets. Avoid logging entire request/response payloads. The **Function Logs** tab may be visible to other workspace members if they have the necessary permissions.
345
345
346
346
## Caching in destination functions
347
347
@@ -381,7 +381,7 @@ If you are a **Workspace Owner** or **Functions Admin**, you can manage your fun
381
381
382
382
### Monitoring destination functions
383
383
384
-
You can use[Destination Event Delivery](/docs/connections/event-delivery/) to understand if Segment encounters any issues delivering your source data to destinations. Errors that the Function throws appear here.
384
+
Use[Destination Event Delivery](/docs/connections/event-delivery/) to understand if Segment encounters any issues delivering your source data to destinations. Errors that the Function throws appear here.
385
385
386
386
If any of your deployed function instances are failing consistently, they will also appear in [Connection Health](/docs/segment-app/#health).
387
387
@@ -444,10 +444,10 @@ If you're sending your batch to an external service, the execution time of the f
444
444
##### Can I use a Destination Function to send data to another Segment source?
445
445
Yes, to do so, remove the `messageId` and the `writeKey` from the payload in your Function code. Leaving either field on your payload will cause unexpected behavior that may cause your event to be delivered to the wrong source or to not be delivered at all.
446
446
447
-
##### Can I view console.log() outputs in Destination Functions?
447
+
##### Can I view console.log() outputs in destination functions?
448
448
449
-
Incorporating console.log() statements in your Destination Function code aids in debugging. However, logs generated by these statements will only be accessible in the [Event Delivery](/docs/connections/event-delivery/) view if the payloads encounter errors during processing. Logs from successfully processed payloads are not displayed.
449
+
Incorporating console.log() statements in your destination function code aids in debugging. However, logs generated by these statements will only be accessible in the [Event Delivery](/docs/connections/event-delivery/) view if the payloads encounter errors during processing. Logs from successfully processed payloads are not displayed.
450
450
451
451
##### What is the maximum data size that can be displayed in console.logs() when testing a Function?
452
452
453
-
The test function interface has a 4KB console logging limit. Outputs larger than this limit are not visible in the user interface.
453
+
The test function interface has a 4 KB console logging limit. Outputs larger than this limit are not visible in the user interface.
0 commit comments