Tracking Payload Builder

TrackingPayloadBuilder helps you create payloads for delegate and custom transport integrations. Use it when LoadStrike is not building the envelope for you.

What this page helps you do

What this page helps you do

TrackingPayloadBuilder helps you create payloads for delegate and custom transport integrations. Use it when LoadStrike is not building the envelope for you.

Who this is for

Engineers writing or reviewing scenario code in one of the supported SDKs.

Prerequisites

  • A scenario or runtime surface you want to wire correctly in code

By the end

The exact SDK surface you need for this part of the runtime.

Use this page when

Use this reference when you already know the workflow and need the exact Tracking Payload Builder API surface in code.

Visual guide

Sequence diagram showing how a LoadStrike workflow moves from setup to report output.
This page fits into the same setup, run, correlate, and report flow as the rest of the public LoadStrike runtime.

Guide

What It Builds

TrackingPayloadBuilder creates a TrackingPayload with headers, body, content type, MessagePayloadType, JsonSettings, and JsonConvertSettings. It is the helper to reach for when a custom or delegate transport still needs to follow the normal tracking rules. Go now exposes the same builder-style SetBody(...) and Build() surface, Java exposes setBody(...) and build(), and Python now publishes the final TrackingPayload body reader directly through get_body_as_utf8() plus the Pascal-case alias GetBodyAsUtf8().

Body Input Modes

Use SetBody(string) for text payloads and SetBody(ReadOnlyMemory<byte>) for binary payloads such as protobuf or compressed formats. After Build(), the resulting payload helper surfaces also expose GetBodyAsUtf8(), getBodyAsUtf8(), or get_body_as_utf8() where that public method exists so selector and delegate code can read the normalized UTF-8 body back out consistently.

Where To Use

This builder is most useful inside delegate-based endpoints such as ProduceAsync or ConsumeAsync, where you need to construct the payload envelope yourself and still keep tracking ID extraction consistent.

SDK reference samples

Use these SDK samples to compare how Tracking Payload Builder is exposed across the supported languages before you wire it into a full scenario.

If you run these examples locally, add a valid runner key before execution starts. Set it with WithRunnerKey("...") or the config key LoadStrike:RunnerKey.

TrackingPayloadBuilder

using LoadStrike;

var httpClient = new HttpClient
{
    BaseAddress = new Uri("https://api.example.com")
};

var scenario = LoadStrikeScenario.Create("submit-orders", async context =>
{
    var builder = new TrackingPayloadBuilder
    {
        ContentType = "application/json",
        MessagePayloadType = typeof(object)
    };

    builder.Headers["X-Correlation-Id"] = $"ord-{context.InvocationNumber}";
    builder.SetBody($$"""{"orderId":"ord-{{context.InvocationNumber}}","amount":49.95}""");

    var payload = builder.Build();
    using var request = new HttpRequestMessage(HttpMethod.Post, "/orders")
    {
        Content = new StringContent(payload.GetBodyAsUtf8(), Encoding.UTF8)
    };
    request.Content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue(payload.ContentType);

    foreach (var header in payload.Headers)
    {
        request.Headers.TryAddWithoutValidation(header.Key, header.Value?.ToString());
    }

    using var response = await httpClient.SendAsync(request);
    return response.IsSuccessStatusCode
        ? LoadStrikeResponse.Ok(statusCode: ((int)response.StatusCode).ToString())
        : LoadStrikeResponse.Fail(statusCode: ((int)response.StatusCode).ToString());
})
.WithLoadSimulations(LoadStrikeSimulation.Inject(10, TimeSpan.FromSeconds(1), TimeSpan.FromSeconds(20)));

LoadStrikeRunner.RegisterScenarios(scenario)
    .WithRunnerKey("rkl_your_local_runner_key")
    .Run();

TrackingPayloadBuilder fields and methods

Headers

Header collection used when building the final TrackingPayload. Header names are preserved exactly as added so exact-case header selectors can match them later.

ContentType

Optional content type carried into the built payload.

MessagePayloadType

Optional type hint for typed JSON parsing by tracking selectors.

JsonSettings / JsonConvertSettings

Optional serializer settings used when payload parsing needs a custom JSON configuration.

Body

Read-only byte view of the currently configured body content.

SetBody(string)

Stores UTF-8 text as the payload body.

SetBody(ReadOnlyMemory<byte>)

Stores raw binary content as the payload body.

Shared HTTP transport

If the tracking payload feeds an HTTP step under load, execute the request through one shared client, session, or dispatcher and dispose or close it after the run.

Build()

Creates the immutable TrackingPayload instance passed into parsers and delegate-based adapters.