Docs menu
Build a scenario
Scenario file Generators vars and const Time and pace Defaults Relationships Schedules Instances Lifecycle Collections Connections Delivery behaviorExpressions
Strings and env
Readable codes and joined labels should stay consistent with the values they describe. Use format and concat after you have the source values.
The result
The formatted order id and concatenated label use the same number:
{"orderNumber":1,"orderId":"ORD-001","label":"order-1"}
{"orderNumber":2,"orderId":"ORD-002","label":"order-2"}
Build readable order codes
generators:
- name: orders
config:
maxEvents: 2
vars:
number: =seq(start=1)
value:
orderNumber: $number
orderId: =format(ORD-%03d, $number)
label: =concat(order-, $number)
format(template, value, ...)
Uses Go fmt.Sprintf formatting.
orderId: =format(ORD-%06d, seq())
customerCode: =format(CUST-%03d, $customerNumber)
With customerNumber: 1:
{"orderId":"ORD-000000","customerCode":"CUST-001"}
At least one value after the template is required. Quote templates that contain commas, parentheses, or spaces. Use %d for integers; %s prints Go’s %!s(int64=...) form.
concat(value, ...)
Converts each argument to text and concatenates the results.
label: =concat(customer-, $customerNumber)
fullName: =concat($firstName, " ", $lastName)
With customerNumber: 1, firstName: Asha, and lastName: Rao:
{"label":"customer-1","fullName":"Asha Rao"}
concat needs at least one argument. Use quoted strings for spaces and punctuation.
env(name, fallback?)
Reads an environment variable. If it is unset, Synthtraffic returns the fallback when provided, otherwise an empty string.
region: =env(REGION, local)
dbPassword: =env(POSTGRES_PASSWORD)
When REGION and POSTGRES_PASSWORD are unset:
{"region":"local","dbPassword":""}
Use env for deployment-specific connector settings such as database passwords — see PostgreSQL. Do not place secret values in scenario files, diagnostics, or documentation examples.
The IDs and sequences page covers seq() counters used by many format templates.
Next: ramp numeric values.