Source Insert Functions
Use Source Insert Functions to enrich, transform, or filter your data before it flows downstream to destinations.
Source Insert Function is in public beta
Source Insert Function is in public beta, and Segment is actively working on this feature. Some functionality may change before it becomes generally available.
There are two ways you can access source insert functions from your Segment workspace:
- From the Connections catalog.
- From the Sources tab.
Create a Source Insert Function
To create a source insert function from Segment’s catalog:
-
Navigate to Connections > Catalog > Functions and click New Function.
-
In the Select Function Type screen, select Source Insert and click Next: Build Function.
-
Write and test your function code. Enter a sample event and click Run to test the function.
-
Click Next: Configure & Create to add a function name, description (optional), and function logo (optional).
-
Click Create Function to save your insert function. The new source insert function displays in the Functions tab.
You can also go to Conections > Sources to create a source insert function in the Sources tab.
Coding the source insert function
Insert functions can define handlers for the following message types:
onIdentity
onTrack
onPage
onScreen
onGroup
onAlias
onDelete
The default source code template includes handlers for all event types. Implement the types you need. For event types you want to send through, return the event in the respective event handler.
Settings
You can add and edit settings for source insert functions in the code editor. Settings allow you to configure the behavior of your source insert function, which changes how it is displayed to anyone using your function. To set up:
- Go to the Settings tab in the code editor and click Add Setting.
- Add the details about this setting.
- Click Add Setting to save the configuration.
As you change values, such as Label, Name, Type, and Description, a preview updates showing how your setting will look and work. Once saved, the new setting appears in the Settings tab of the function. Here, you can edit or delete the setting.
Testing
You can test your source insert function with sample events or a manual configuration in the code editor. This allows you to test the functions behavior with real incoming data. To do this:
- Go to the Test tab in the code editor and click Use Sample Event or customize the event yourself to set up your test data.
- Click Run to execute the test.
Test results appear under Output, showing whether the function ran successfully or failed.
Connect a source insert function to a source
For data to flow downstream after transformation, connect your source insert function to a source. To do this:
- Select the insert function you want to connect to the source. You can edit, delete, and connect the insert function on the side pane.
- Click Connect a source.
- Select the source you want to connect to and click Connect to Source.
Errors and error handling
Segment considers a function’s execution successful if it completes without error. You can throw
an error to create a failure on purpose. Use these errors to validate event data before processing to make sure the function works as expected.
You can throw
the following pre-defined error types to indicate that the function ran successfully, but the data was not deliverable:
EventNotSupported
InvalidEventPayload
ValidationError
RetryError
DropEvent
This is similar to Source, Destination, and Insert Functions.
The errors listed are all permanent errors, except RetryError
. When a RetryError
is thrown, Segment reattempts to run the function a set number of times before permanently erroring out.
FAQs
Why does the Delivery Overview tab not display any errors that occur within the source insert function?
Errors in the Delivery Overview tab are not yet visible and is a work in progress.
Can I test the function with different event types?
You can test the function with different event types from the Test tab in the code editor, similar to other functions.
Can I use source insert functions for all types of sources?
Source insert functions only work for event sources, not object sources or rETL.
What is the expected latency for a source insert function?
The source insert function typically completes in 200 milliseconds to 5 seconds, depending on its complexity. The default timeout is 5 seconds but can be increased to 60 seconds.
What is the runtime environment?
Segment supports Node.js V18 and installs the dependencies listed here in the function. Segment also installs the following dependencies:
@azure/identity
exposed asazure.identity
@azure/event-hubs
exposed asazure.eventHubs
@azure/synapse
exposed asazure.synapse
jsftp
exposed asjsftp
crypto-js
exposed ascryptojslib.cryptojs
akeyless
exposed asakeylessLabs.akeyless
akeyless-cloud-id
exposed asakeylessLabs.akeylessCloudId
@onesignal/node-onesignal
exposed asoneSignal.oneSignal
pg
exposed aspg.pg
snowflake-sdk
exposed assnowflakesdk.snowflakesdk
@clickhouse/client
exposed asclickHouseClient.clickHouseClient
aws4
exposed asaws4.aws4
@sentry/node
exposed assentrylib.sentry
This page was last modified: 20 Jun 2025
Need support?
Questions? Problems? Need more info? Contact Segment Support for assistance!