Snap Object Properties
The snap object provides access to Snap-level runtime information and metadata in expressions. These properties are available within any Snap and provide context about the current Snap execution, including identification, view statistics, and document counts.
Snap Identification
snap.label
The label (name) of the Snap.
Syntax:
snap.label
Example:
snap.label
// Returns: "Mapper+%28Data%29" for Mapper (Data)
// Note: Special characters are URL-encoded
snap.instanceId
The UUID (Universally Unique Identifier) of the Snap. Note that this is different from the runtime UUID of the Pipeline.
Syntax:
snap.instanceId
Example:
snap.instanceId
// Returns: "a1b2c3d4-e5f6-7890-abcd-ef1234567890"
Input View Statistics
snap.inputViews
The input view names and number of documents that have been read from these views.
Syntax:
snap.inputViews
Returns:
- If no view is defined, returns
{} - For each view defined, returns an object with view statistics
Example:
snap.inputViews
// Returns:
{
"Target": {
"input0": {
"count": 42,
"name": "input0"
}
}
}
// Where:
// - "Target" is the name of the target path this expression is mapping to
// - "input0" is the name of the input view
// - 42 is the number of documents that have been read
snap.in.totalCount
The total number of documents that have passed through all of the Snap's input views.
Syntax:
snap.in.totalCount
Example:
snap.in.totalCount
// Returns: 150 (total documents from all input views)
Output View Statistics
snap.outputViews
The output view names and number of documents that have been written to these views.
Syntax:
snap.outputViews
Returns:
- If no view is defined, returns
{} - For each view defined, returns an object with view statistics
Example:
snap.outputViews
// Returns:
{
"Target": {
"output0": {
"count": 38,
"name": "output0"
}
}
}
// Where:
// - "Target" is the name of the target path this expression is mapping to
// - "output0" is the name of the output view
// - 38 is the number of documents that have been written
snap.out.totalCount
The total number of documents that have passed through all of the Snap's output views.
Syntax:
snap.out.totalCount
Example:
snap.out.totalCount
// Returns: 145 (total documents from all output views)
Error View Statistics
snap.errorViews
The error view and number of documents that have been written to this view.
Syntax:
snap.errorViews
Example:
snap.errorViews
// Returns:
{
"Target": {
"error0": {
"count": 5,
"name": "error0"
}
}
}
// Where:
// - "Target" is the name of the target path this expression is mapping to
// - "error0" is the name of the error view
// - 5 is the number of documents that have been written to error
snap.error.totalCount
The total number of documents that have passed through all of the Snap's error views.
Syntax:
snap.error.totalCount
Example:
snap.error.totalCount
// Returns: 5 (total error documents)
Ultra Pipeline Properties
snap.original.load()
Loads the original message (document) coming to the FeedMaster when using an Ultra pipeline.
Syntax:
snap.original.load()
Returns: The original content of the document, along with the entire request sent to the feedmaster.
Example:
snap.original.load()
// Returns: Complete original request including headers, body, and metadata
snap.original.id
The unique ID associated with the message (document) coming into the Ultra pipeline.
Syntax:
snap.original.id
Returns: Unique ID of the message as a string.
Example:
snap.original.id
// Returns: "msg-12345-abcde-67890"
Common Use Cases
Conditional Processing Based on Document Count:
// Process only if there are documents
snap.in.totalCount > 0 ? $processData : null
Error Rate Monitoring:
// Calculate error rate
{
"totalInput": snap.in.totalCount,
"totalOutput": snap.out.totalCount,
"totalErrors": snap.error.totalCount,
"errorRate": snap.error.totalCount / snap.in.totalCount,
"successRate": snap.out.totalCount / snap.in.totalCount
}
Audit Logging:
// Create audit record with Snap metadata
{
"snapId": snap.instanceId,
"snapName": snap.label,
"documentsProcessed": snap.in.totalCount,
"documentsOutput": snap.out.totalCount,
"errors": snap.error.totalCount,
"timestamp": Date.now()
}
Progress Tracking:
// Track processing progress
{
"snap": snap.label,
"processed": snap.in.totalCount,
"successful": snap.out.totalCount,
"failed": snap.error.totalCount,
"status": snap.error.totalCount > 0 ? "Partial Success" : "Success"
}
Ultra Pipeline Request Tracking:
// Track original request in Ultra pipeline
{
"requestId": snap.original.id,
"originalRequest": snap.original.load(),
"processedBy": snap.label,
"timestamp": Date.now()
}
Data Quality Validation:
// Validate data quality based on error ratio
snap.error.totalCount / snap.in.totalCount > 0.1
? "Quality Check Failed: Error rate exceeds 10%"
: "Quality Check Passed"
Dynamic Routing Based on View Counts:
// Route based on document count
snap.in.totalCount > 1000
? "high_volume_processing"
: "standard_processing"
Best Practices
- Unique Identification: Use
snap.instanceIdfor unique Snap identification in logs and tracking. - Error Monitoring: Use
snap.error.totalCountto monitor error rates and data quality. - Performance Tracking: Compare
snap.in.totalCountandsnap.out.totalCountto track document processing efficiency. - Audit Trails: Include
snap.labelandsnap.instanceIdin audit logs for traceability. - Ultra Pipelines: Use
snap.original.idfor request correlation in Ultra pipelines. - Conditional Logic: Use document counts for conditional processing logic (e.g., only process if data exists).
- Quality Checks: Calculate error rates to implement data quality thresholds.
- View Statistics: Use
inputViews,outputViews, anderrorViewsfor detailed view-level analysis.
Property Reference
| Property | Description | Type | Example Value |
|---|---|---|---|
snap.label |
Snap label/name | String | "Mapper+%28Data%29" |
snap.instanceId |
Snap UUID | String | a1b2c3d4-e5f6-7890... |
snap.inputViews |
Input view statistics | Object | {input0: {count: 42}} |
snap.outputViews |
Output view statistics | Object | {output0: {count: 38}} |
snap.errorViews |
Error view statistics | Object | {error0: {count: 5}} |
snap.in.totalCount |
Total input documents | Number | 150 |
snap.out.totalCount |
Total output documents | Number | 145 |
snap.error.totalCount |
Total error documents | Number | 5 |
snap.original.load() |
Original Ultra request | Object | {headers: {...}, body: {...}} |
snap.original.id |
Ultra message ID | String | "msg-12345-abcde" |
Differences Between snap and pipe Objects
| Aspect | snap Object | pipe Object |
|---|---|---|
| Scope | Snap-level information | Pipeline-level information |
| ID Property | snap.instanceId (Snap UUID) | pipe.instanceId (Pipeline UUID) |
| Runtime ID | Not available | pipe.ruuid (Runtime UUID) |
| Label | snap.label (Snap name) | pipe.label (Pipeline name) |
| Statistics | Document counts per Snap | Pipeline execution metadata |
| Parameters | Not available | pipe.args (Pipeline parameters) |
| Use Case | Snap-specific tracking and logic | Pipeline-level configuration and tracking |
Calculating Document Processing Metrics
Success Rate:
// Calculate percentage of successful documents
(snap.out.totalCount / snap.in.totalCount) * 100
Error Rate:
// Calculate percentage of error documents
(snap.error.totalCount / snap.in.totalCount) * 100
Processing Efficiency:
// Documents lost in processing (neither output nor error)
snap.in.totalCount - (snap.out.totalCount + snap.error.totalCount)
Complete Processing Summary:
{
"snapId": snap.instanceId,
"snapName": snap.label,
"input": snap.in.totalCount,
"output": snap.out.totalCount,
"errors": snap.error.totalCount,
"successRate": ((snap.out.totalCount / snap.in.totalCount) * 100).toFixed(2) + "%",
"errorRate": ((snap.error.totalCount / snap.in.totalCount) * 100).toFixed(2) + "%",
"processed": snap.out.totalCount + snap.error.totalCount,
"status": snap.error.totalCount === 0 ? "Clean" : "Has Errors"
}