Host Tracking

Methods on TraxBuilder for configuring host identity. All are optional — host tracking works with zero configuration via auto-detection.

SetHostEnvironment

Overrides the auto-detected host environment type.

public TraxBuilder SetHostEnvironment(string environment)
ParameterTypeRequiredDescription
environmentstringYesEnvironment identifier (e.g., "lambda", "ecs", "my-custom-env")

SetHostInstanceId

Overrides the auto-detected host instance ID.

public TraxBuilder SetHostInstanceId(string instanceId)
ParameterTypeRequiredDescription
instanceIdstringYesInstance identifier

AddHostLabel

Adds a custom key-value label to the host identity. Labels are stored as JSONB on every metadata record.

public TraxBuilder AddHostLabel(string key, string value)
ParameterTypeRequiredDescription
keystringYesLabel key (e.g., "region", "service")
valuestringYesLabel value (e.g., "us-east-1")

AddHostLabels

Adds multiple custom labels at once.

public TraxBuilder AddHostLabels(Dictionary<string, string> labels)
ParameterTypeRequiredDescription
labelsDictionary<string, string>YesKey-value pairs to add

Example

services.AddTrax(trax => trax
    .SetHostEnvironment("ecs")
    .AddHostLabel("region", "us-east-1")
    .AddHostLabel("service", "content-shield")
    .AddEffects(effects => effects
        .UsePostgres(connectionString)
    )
    .AddMediator(assemblies)
);

Remarks

  • Host identity is detected once at startup and applied to all train executions in the process.
  • Auto-detection probes environment variables for Lambda, ECS, Kubernetes, and Azure App Service. See Host Tracking for the full detection table.
  • Duplicate label keys use last-write-wins semantics.
  • When a remote worker executes a train, host fields are overwritten in StartServiceTrain() so the metadata reflects the actual execution host, not the dispatcher.