Skip to content

Commit b4d12e7

Browse files
authored
Merge pull request #7883 from segmentio/source-functions-review
Source functions overview audit [DOC-1205]
2 parents 4fbcb42 + 525a121 commit b4d12e7

File tree

1 file changed

+17
-13
lines changed

1 file changed

+17
-13
lines changed

src/connections/functions/source-functions.md

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,8 @@ All functions are scoped to your workspace, so members of other workspaces canno
2525

2626
After 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.
2727

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){:target="_blank"}. (Contributions welcome!)
30-
28+
> success "Want to see some example functions?"
29+
> 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!)
3130
3231
![Functions Editor](images/editor-source.png)
3332

@@ -306,16 +305,19 @@ The advantage of testing your source function with webhooks is that all incoming
306305
Note: Segment has updated the webhook URL to `api.segmentapis.com/functions`. To use webhooks with your function, you must:
307306
- [Generate a public API token](https://docs.segmentapis.com/tag/Getting-Started/#section/Get-an-API-token){:target="_blank"}.
308307
- [Create a Public API Token]([url](https://app.segment.com/goto-my-workspace/settings/access-management/tokens)), or follow these steps:
309-
In your Segment Workspace, navigate to SettingsWorkspace settingsAccess ManagementToken. Click `+ Create Token`. Create a description for the token and assign access. Click `Create` and save the access token before clicking `Done`.
308+
In your Segment Workspace, navigate to **Settings** > **Workspace settings** > **Access Management** > **Token**. Click **+ Create Token**. Create a description for the token and assign access. Click **Create** and save the access token before clicking **Done**.
310309
- For POST calls, use this Public API token in the Authorization Header, as `Bearer Token : public_api_token`
311310

312311
### Testing source functions with a webhook
313312

314313
You can use webhooks to test the source function either by sending requests manually (using any HTTP client such as cURL, Postman, or Insomnia), or by pasting the webhook into an external server that supports webhooks (such as Slack).
315-
_A common Segment use case is to connect a Segment [webhooks destination](https://segment.com/docs/connections/destinations/catalog/webhooks/) or [webhook actions destination](https://segment.com/docs/connections/destinations/catalog/actions-webhook/) to a test source, where the Webhook URL/endpoint that is used corresponds to the provided source function's endpoint, then you can trigger test events to send directly to that source, which are routed through your Webhook destination and continue on to the source function: Source → Webhook destination → Source Function._
314+
315+
#### Use case
316+
A common Segment use case is to connect a Segment [webhooks destination](https://segment.com/docs/connections/destinations/catalog/webhooks/) or [webhook actions destination](https://segment.com/docs/connections/destinations/catalog/actions-webhook/) to a test source, where the Webhook URL/endpoint that is used corresponds to the provided source function's endpoint, then you can trigger test events to send directly to that source, which are routed through your Webhook destination and continue on to the source function: **Source** > **Webhook destination** > **Source Function**.
316317

317318
From the source function editor, copy the provided webhook URL (endpoint) from the "Auto-fill via Webhook" dialog.
318-
_**Note** : When a new source is created that utilizes a source function, the new source's endpoint (webhook URL) will differ from the URL that is provided in the source function's test environment._
319+
320+
**Note** : When a new source is created that utilizes a source function, the new source's endpoint (webhook URL) will differ from the URL that is provided in the source function's test environment.
319321

320322
To test the source function:
321323
1. Send a `POST` request to the source function's provided endpoint (webhook URL)
@@ -367,12 +369,14 @@ async function onRequest(request, settings) {
367369
}
368370
```
369371

370-
> warning ""
371-
> **Warning:** Do not log sensitive data, such as personally-identifying information (PII), authentication tokens, or other secrets. You should especially avoid logging entire request/response payloads. Segment only retains the 100 most recent errors and logs for up to 30 days but the **Errors** tab may be visible to other workspace members if they have the necessary permissions.
372+
> warning "**Data may be visible to other workspace members**"
373+
> **Do not log sensitive data**, such as personally-identifying information (PII), authentication tokens, or other secrets. You should especially avoid logging entire request/response payloads.
374+
>
375+
> Segment only retains the 100 most recent errors and logs for up to 30 days but the **Errors** tab may be visible to other workspace members if they have the necessary permissions.
372376
373377
### Error types
374378

375-
- **Bad Request**: is any error thrown by your code not covered by the other errors.
379+
- **Bad Request**: Any error thrown by your code not covered by the other errors.
376380
- **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"}.
377381
- **Message Rejected**: Your code threw `InvalidEventPayload` or `ValidationError` due to invalid input.
378382
- **Unsupported Event Type**: Your code doesn't implement a specific event type (for example, `onTrack()`) or threw an `EventNotSupported` error.
@@ -423,7 +427,7 @@ The maximum payload size for an incoming webhook payload is 512 KiB.
423427

424428
##### What is the timeout for a function to execute?
425429

426-
The execution time limit is five seconds, however Segment strongly recommends that you keep execution time as low as possible. If you are making multiple external requests you can use async / await to make them concurrently, which will help keep your execution time low.
430+
The execution time limit is five seconds, however we strongly recommend that you keep execution time as low as possible. If you are making multiple external requests you can use async or await to make them concurrently, which will help keep your execution time low.
427431

428432
#### Does Segment alter incoming payloads?
429433

@@ -435,18 +439,18 @@ Segment alphabetizes payload fields that come in to **deployed** source function
435439

436440
#### Can I use a Source Function in place of adding a Tracking Pixel to my code?
437441

438-
No. Tracking Pixels operate client-side only and need to be loaded onto your website directly. Source Functions operate server-side only, and aren't able to capture or implement client-side tracking code. If the tool you're hoping to integrate is server-side, then you can use a Source Function to connect it to Segment.
442+
No. Tracking Pixels operate client-side only and need to be loaded onto your website directly. Source functions operate server-side only, and aren't able to capture or implement client-side tracking code. If the tool you're hoping to integrate is server-side, then you can use a Source function to connect it to Segment.
439443

440444
##### What is the maximum data size that can be displayed in console.logs() when testing a Function?
441445

442446
The test function interface has a 4KB console logging limit. Outputs surpassing this limit will not be visible in the user interface.
443447

444448
#### Can I send a custom response from my Source Function to an external tool?
445449

446-
No, Source Functions can't send custom responses to the tool that triggered the Function's webhook. Source Functions can only send a success or failure response, not a custom one.
450+
No, Source functions can't send custom responses to the tool that triggered the Function's webhook. Source functions can only send a success or failure response, not a custom one.
447451

448452
#### Why am I seeing the error "Functions are unable to send data or events back to their originating source" when trying to save my Source Function?
449453

450-
This error occurs because Segment prevents Source Functions from sending data back to their own webhook endpoint (`https://fn.segmentapis.com`). Allowing this could create an infinite loop where the function continuously triggers itself.
454+
This error occurs because Segment prevents Source functions from sending data back to their own webhook endpoint (`https://fn.segmentapis.com`). Allowing this could create an infinite loop where the function continuously triggers itself.
451455

452456
To resolve this error, check your Function code and ensure the URL `https://fn.segmentapis.com` is not included. This URL is used to send data to a Source Function and shouldn't appear in your outgoing requests. Once you remove this URL from your code, you’ll be able to save the Function successfully.

0 commit comments

Comments
 (0)