Skip to content

Commit 82cb12b

Browse files
authored
Merge pull request #449 from segmentio/repo-sync
repo sync
2 parents bca1271 + 0b40736 commit 82cb12b

File tree

2 files changed

+56
-38
lines changed

2 files changed

+56
-38
lines changed

src/_includes/content/functions/settings.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ Settings allow you to pass configurable variables to your function, which is the
44

55
First, add a setting in **Settings** tab in the code editor:
66

7-
![Settings Tab](/docs/connections/functions/images/settings-tab-empty.png){:width="500"}
7+
![A screenshot of the functions settings tab](/docs/connections/functions/images/settings-tab-empty.png){:width="500"}
88

99
Click **Add Setting** to add your new setting.
1010

11-
![Add Setting Dialog](/docs/connections/functions/images/add-setting-dialog.png)
11+
![A screenshot of the "Add Setting" section of the functions settings tab, with apiKey settings included](/docs/connections/functions/images/add-setting-dialog.png)
1212

1313
You can configure the details about this setting, which change how it's displayed to anyone using your function:
1414

@@ -25,4 +25,4 @@ Click **Add Setting** to save the new setting.
2525

2626
Once you save a setting, it appears in the **Settings** tab for the function. You can edit or delete settings from this tab.
2727

28-
![Settings Tab](/docs/connections/functions/images/settings-tab-non-empty.png){:width="500"}
28+
![A screenshot of the functions settings tab, showing the apiKey setting](/docs/connections/functions/images/settings-tab-non-empty.png){:width="500"}

src/connections/functions/destination-functions.md

Lines changed: 53 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -11,27 +11,25 @@ Destination functions allow you to transform and annotate your Segment events an
1111
All functions are scoped to your workspace, so members of other workspaces can't view or use them.
1212

1313
> 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"}.
1515
16-
![](images/destination_functions_overview.png)
16+
![An illusrative graphic showing information flowing from the Segment app, into code, and then into Slack](images/destination_functions_overview.png)
1717

1818

1919
> note ""
2020
> Destination functions does not accept data from [Object Cloud sources](/docs/connections/sources/#object-cloud-sources).
2121
2222
## Create a destination function
2323

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"}.
2525
2. Click **New Function**.
2626
3. Select **Destination Function** and click **Build**.
2727

2828
> 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!)
3030
3131
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.
3232

33-
![Functions Editor](images/editor-dest.png)
34-
3533
## Code the destination function
3634

3735
Segment invokes a separate part of the function (called a "handler") for each event type that you send to your destination function.
@@ -78,7 +76,7 @@ async function onTrack(event) {
7876
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.
7977

8078
> 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.
79+
> 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.
8280
8381
### Errors and error handling
8482

@@ -140,17 +138,14 @@ You can read more about [error handling](#destination-functions-logs-and-errors)
140138
{% include content/functions/runtime.md %}
141139

142140

143-
<!-- TODO - could also go into the `runtime.md` include above, if applied identically to both types of functions.
144-
## Batching in functions -->
141+
<!-- TODO - could also go into the `runtime.md` include above, if applied identically to both types of functions. -->
145142

146143
## Create settings and secrets
147144

148145
{% include content/functions/settings.md %}
149146

150147
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.)
151148

152-
![Test Value For Setting](images/setting-in-test-tab.png){:width="500"}
153-
154149
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:
155150

156151
```js
@@ -162,8 +157,6 @@ async function onTrack(request, settings) {
162157

163158
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.
164159

165-
![Destination Function Settings](images/dest-settings.png)
166-
167160
## Test the destination function
168161

169162
You can test your code directly from the editor in two ways:
@@ -172,32 +165,27 @@ You can test your code directly from the editor in two ways:
172165

173166
Click **Use Sample Event** and select the source to use events from.
174167

175-
![Capture events to test your function](images/autofill-events.gif)
168+
![An animation showing someone using the Use Sample Event button, selecting a source, and clicking "Use Event"](images/autofill-events.gif)
176169

177170
Click **Run** to test your function with the event you selected.
178171

179172
### Test using manual input
180173

181174
You can also manually include your own JSON payload of a Segment event, instead of fetching a sample from one of your workspace sources.
182175

183-
![Functions Editor Event Tester](images/editor-test.gif)
176+
![An animation showing someone clicking the run button in the Test panel and viewing a successful output](images/editor-test.gif)
184177

185178
If your function fails, you can check the error details and logs in the **Output** section.
186179

187180
- **Error Message** - This shows the error surfaced from your function.
188181
- **Logs** - This section displays any messages to `console.log()` from the function.
189182

190-
## Batching the destination function (Beta)
191-
192-
> warning ""
193-
> Batch handling for Functions is available as an early access beta release. By enabling batch handlers for your function, you acknowledge that your use of batch handlers is subject to [Segment's Beta Terms and Conditions](https://segment.com/legal/first-access-beta-preview), or the applicable terms governing Beta Releases found in your subscription agreement with Segment.
194-
>
195-
> If you notice any bugs or have any general feedback on this new feature, please fill out [this form](https://airtable.com/shr9TU4huO0PK0DSU).
183+
## Batching the destination function
196184

197185
Batch handlers are an extension of destination functions. When you define an `onBatch` handler alongside the handler functions for single events (for example: `onTrack` or `onIdentity`), you're telling Segment that the destination function can accept and handle batches of events.
198186

199187
> info ""
200-
> Batching is available to destination functions only.
188+
> Batching is available for destination functions only.
201189
202190
### When to use batching
203191

@@ -283,13 +271,16 @@ async function onIdentifyBatch(events, settings) {
283271

284272
### Configure your batch parameters
285273

286-
You cannot configure batch parameters (either in the code or UI) in this version of the beta. Functions waits up to 10 seconds to form a batch of 20 events. If you would like to change your batch parameters, please fill out [this form](https://airtable.com/shr9TU4huO0PK0DSU) and Support will contact you once this is made available.
274+
By default, Functions waits up to 10 seconds to form a batch of 20 events. You can increase the number of events included in each batch (up to 400 events per batch) by contacting [Segment support](https://segment.com/help/contact/){:target="_blank"}. Segment recommends users who wish to include fewer than 20 events per batch use destination functions without the `onBatch` handler.
287275

288276
### Test the batch handler
289277

290-
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.
278+
The [Functions editing environment](/docs/connections/functions/environment/) supports testing batch handlers.
291279

292-
![Batch handler testing](images/batch-function-editor.png)
280+
To test the batch handler:
281+
1. In the right panel of the Functions editor, click **customize the event yourself** to enter Manual Mode.
282+
2. Add events as a JSON array, with one event per element.
283+
3. Click **Run** to preview the batch handler with the specified events.
293284

294285
> note ""
295286
> 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.
@@ -300,7 +291,35 @@ The [Config API](/docs/config-api/) Functions/Preview endpoint also supports tes
300291

301292
### Handling batching errors
302293

303-
Standard [function error types](/docs/connections/functions/destination-functions/#destination-functions-error-types) apply to batch handlers. Segment attempts to retry the batch in the case of Timeout or Retry errors. For all other error types, Segment discards the batch. If only part of a batch succeeds, Segment does not retry the failing part of the batch.
294+
Standard [function error types](/docs/connections/functions/destination-functions/#destination-functions-error-types) apply to batch handlers. Segment attempts to retry the batch in the case of Timeout or Retry errors. For all other error types, Segment discards the batch. It is also possible to report a partial failure by returning status of each event in the batch. Segment retries only the failed events in a batch until those events are successful or until they result in a permanent error.
295+
296+
```json
297+
[
298+
{
299+
"status": 200
300+
},
301+
{
302+
"status": 400,
303+
"errormessage": "Bad Request"
304+
},
305+
{
306+
"status": 200
307+
},
308+
{
309+
"status": 500,
310+
"errormessage": "Error processing request"
311+
},
312+
{
313+
"status": 500,
314+
"errormessage": "Error processing request"
315+
},
316+
{
317+
"status": 200
318+
},
319+
]
320+
```
321+
322+
After receiving the response from the `onBatch` handler, only **event_3** and **event_4** will be retried.
304323

305324
| Error Type | Result |
306325
| ---------------------- | ------- |
@@ -311,6 +330,7 @@ Standard [function error types](/docs/connections/functions/destination-function
311330
| Timeout | Retry |
312331
| Unsupported Event Type | Discard |
313332

333+
314334
## Save and deploy the function
315335

316336
Once you finish building your destination function, click **Configure** to name it, then click **Create Function** to save it.
@@ -325,12 +345,12 @@ You can also choose to **Save & Deploy** to save the changes, and then choose wh
325345

326346
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.
327347

328-
![Destination Function Event Delivery tab](images/event-delivery.png)
348+
![A screenshot of the event delivery tab, showing 519 failed events broken into categories explaining why they failed](images/event-delivery.png)
329349

330350
### Destination functions error types
331351

332352
- **Bad Request** - Any error thrown by the function code that is not covered by the other errors.
333-
- **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/).
353+
- **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"}.
334354
- **Message Rejected** - Your code threw `InvalidEventPayload` or `ValidationError` due to invalid input.
335355
- **Unsupported Event Type** - Your code does not implement a specific event type (`onTrack()`, etc.) or threw a `EventNotSupported` error.
336356
- **Retry** - Your code threw `RetryError` indicating that the function should be retried.
@@ -343,9 +363,7 @@ If your function throws an error, execution halts immediately. Segment captures
343363

344364
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.
345365

346-
![Destination Function error logs](images/error-logs-dest.png)
347-
348-
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:
366+
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:
349367

350368
```js
351369
async function onTrack(event, settings) {
@@ -397,7 +415,7 @@ async function getAccessToken () {
397415

398416
### Editing and deleting functions
399417

400-
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.
418+
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.
401419

402420

403421
### Monitoring destination functions
@@ -432,19 +450,19 @@ Yes, Functions access is logged in the [Audit Trail](/docs/segment-app/iam/audit
432450

433451
##### Does Segment retry failed function invocations?
434452

435-
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).
453+
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).
436454

437455
##### Are events guaranteed to send data in order?
438456

439457
No, Segment can't guarantee the order in which the events are delivered to an endpoint.
440458

441459
##### Can I create a device-mode destination?
442460

443-
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.
461+
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.
444462

445463
##### How do I publish a destination to the public Segment catalog?
446464

447-
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/).
465+
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/).
448466

449467
##### How does batching affect visibility?
450468

0 commit comments

Comments
 (0)