When you add a transformation and connect it to a cloud mode-supported destination, RudderStack does the following:

  1. Tracks and collects events at the source.
  2. Applies the transformation logic to your events.
  3. Forwards the transformed event to your connected destination.
Transformations workflow

Applying transformation on a batch of events

You can perform any aggregation or roll-up operation on a batch of events using the transformBatch function instead of transformEvent, as shown:

export function transformBatch(events, metadata) {
return events;
}
def transformBatch(events, metadata):
return events
To ensure event ordering when using the transformBatch function, make sure you pass the messageId from the input event to the output event. Without the messageId, RudderStack does not guarantee event ordering.

It is highly recommended to use transformEvent as much as possible, as it ensures event ordering.

Debugging transformations

Once you add a transformation, you can capture any event-related information in the form of logs while running a test on your transformation. You can do this by including the log function in your transformation code.

An example of using the log function is shown below:

export function transformEvent(event, metadata) {
const meta = metadata(event);
event.sourceId = meta.sourceId;
log("Event Name is", event.event, ";", "Message ID is", event.messageId);
log("Source ID is", meta.sourceId);
return event;
}
def transformEvent(event, metadata):
meta = metadata(event)
event['sourceId'] = meta['sourceId']
log("Event Name is", event['event'], ";", "Message ID is", event['messageId'])
log("Source ID is", meta['sourceId'])
return event

On adding the above transformation and clicking Run Test, you can see the resulting log in the Logs section of the dashboard, as shown:

Transformation log
You can pass a string, number, or an object as an argument to the log function.

Limitations

The transformation fails if the following memory and time limits are exceeded:

ParameterLimit
Memory limit128 MB
Execution time limit4 seconds


Contact us

For more information on the topics covered on this page, email us or start a conversation in our Slack community.

On this page