Skip to main content

Installation

API reference for the helper packages of the iii SDK for Go.

helpers/http

Package http holds the HTTP helpers of the iii Go SDK: the Go counterpart of the Node @iii-dev/helpers/http module (plus the StreamRequest and StreamResponse types of the Node SDK) and of the Rust iii_helpers::http module. Import

Functions

NewStreamResponse

NewStreamResponse returns a StreamResponse writing to writer, the response channel of an http invocation opened with iii.Client.OpenWriter. ctx bounds the channel dial and every write. Wrap builds one for each invocation; call NewStreamResponse only when handling an InternalRequest by hand. With a nil writer every method returns ErrMissingChannel. Signature

Parameters

context.Context
required
*iii.ChannelWriter
required

Wrap

Wrap adapts an HTTP-style handler into an iii.Handler for a function behind an http trigger; it is the Go counterpart of the Node http() helper. Register the result with iii.Client.RegisterFunction. For each invocation Wrap decodes the InternalRequest, opens the request body channel for reading and the response channel for writing with iii.Client.OpenReader and iii.Client.OpenWriter (so the dials use the client’s engine address and send its iii.WithHeaders, plus III_TOKEN), and calls fn with the StreamRequest and StreamResponse. When fn returns, Wrap closes the request body reader and finishes the response like a net/http handler:
  • a streamed body, or a nil result without error, ends the response stream cleanly (no explicit Close needed);
  • a buffered result, or an error before any body, leaves the channel untouched so the http worker answers from the returned value or reports the error;
  • a failed Status, Headers or Write aborts the response, whatever fn returns;
  • an error after body bytes were written aborts the response too, so the truncated body is not taken for a complete one.
fn must not use req or res after it returns. Wrap returns nil when fn is nil; it panics when client is nil. Signature
*iii.Client
required
HandlerFunc
required

Variables

Types

HandlerFunc · InternalRequest · InvocationConfig · Method · MultiValue · Request · Response · StreamRequest · StreamResponse

HandlerFunc

HandlerFunc is an HTTP-style handler for a function behind an http trigger, the callback of the Node http() helper. Adapt it with Wrap. Write the response to res and return nil to stream it, or return a Response (any non-nil value with status_code, headers and body) to answer buffered without touching res. A returned error is reported as the invocation error, which the http worker answers with a 500; if body bytes were already streamed, Wrap aborts the response instead of ending it, so the truncated body is not taken for a complete one.

InternalRequest

InternalRequest is the payload the http worker sends to a function behind an http trigger, Node InternalHttpRequest: the parsed request plus the two channel refs. The Node SDK resolves the refs into a reader and a writer before it calls the handler; in Go they stay refs, opened by Wrap or by hand with iii.Client.OpenReader and iii.Client.OpenWriter.

InvocationConfig

InvocationConfig configures a function the engine invokes over HTTP (Lambda, Cloudflare Workers and similar), Node HttpInvocationConfig. It is the core iii.HTTPInvocationRef: URL, Method (POST when empty), TimeoutMs, Headers, and Auth, the JSON of a Node HttpAuthConfig: {“type”:“hmac”,“secret_key”:…}, {“type”:“bearer”,“token_key”:…} or {“type”:“api_key”,“header”:…,“value_key”:…}.

Method

Method is an HTTP method accepted by InvocationConfig (Node HttpMethod). It is an alias of string so the constants assign directly to iii.HTTPInvocationRef.Method. It is distinct from the http trigger’s http_method, which also accepts HEAD and OPTIONS.

MultiValue

MultiValue is a header or query parameter value, string | string[] in the Node types. It decodes from a JSON string (one element) or an array of strings; the http worker currently sends one string per key. A one-element MultiValue encodes back as a JSON string, nil as null and any other length as an array.

Request

Request is the buffered HTTP request a function behind an http trigger receives, Node HttpRequest<TBody> and Rust HttpRequest<T>. T is the type of the parsed body; use json.RawMessage to keep it raw. Decode the handler payload into it, or register the function with iii.RegisterFunctionTyped.

Response

Response is a buffered HTTP response returned from a function behind an http trigger, Node HttpResponse and Rust HttpResponse<T>. T is the type of the body: the http worker sends a string Body verbatim when Headers sets a content-type, and encodes anything else as JSON (a []byte encodes as a base64 string, so stream binary bodies through a StreamResponse). A Wrap handler returns a Response to answer without streaming.

StreamRequest

StreamRequest is the incoming request a HandlerFunc receives, Node StreamRequest: the parsed request plus the raw body as a stream. StreamRequest is an io.Reader over the raw request body.

StreamResponse

StreamResponse is the response a HandlerFunc writes, Node StreamResponse: Status and Headers send control messages, Write streams the body and Close ends it. StreamResponse is an io.Writer. Its methods are safe for concurrent use. A response whose writer failed is aborted, never reported complete. Once Status, Headers or Write returned an error, every later call returns that error, and Close (or Wrap, when the handler returns) ends the channel without a clean close: the http worker’s reader gets an error instead of a truncated body that looks whole.

helpers/queue

Package queue holds the queue helper types of the iii Go SDK, the Go counterpart of the Node @iii-dev/helpers/queue module and the Rust iii_helpers::queue module. Import

Types

EnqueueResult

EnqueueResult

EnqueueResult is the result returned when a function is invoked with iii.EnqueueAction (TriggerAction.Enqueue in the Node SDK). Decode the json.RawMessage returned by iii.Client.Trigger into it.

helpers/workerconnection

Package workerconnection holds the RBAC hook types of the iii worker-manager, the Go counterpart of the Node @iii-dev/helpers/worker-connection-manager module and the Rust iii_helpers::worker_connection_manager module. Import

Types

AuthInput · AuthResult · OnFunctionRegistrationInput · OnFunctionRegistrationResult · OnTriggerRegistrationInput · OnTriggerRegistrationResult · OnTriggerTypeRegistrationInput · OnTriggerTypeRegistrationResult

AuthInput

AuthInput is the input passed to the RBAC auth function during the WebSocket upgrade. It carries the HTTP headers, query parameters and client IP of the connecting worker’s upgrade request.

AuthResult

AuthResult is the value the RBAC auth function returns. It controls which functions the authenticated worker can invoke and what context is forwarded to the middleware. Every field is optional; the zero value of a field means “use the engine default”: no namespace-scoped grants, no extra allowed or forbidden functions, every trigger type allowed, trigger type registration denied, function registration allowed, an empty context and no function ID prefix.

OnFunctionRegistrationInput

OnFunctionRegistrationInput is the input passed to the on_function_registration_function_id hook when a worker attempts to register a function through the RBAC port. Return an OnFunctionRegistrationResult with the (possibly mapped) fields, or an error to deny the registration.

OnFunctionRegistrationResult

OnFunctionRegistrationResult is the result returned from the on_function_registration_function_id hook. Every field is optional; an omitted field keeps the original value from the registration request.

OnTriggerRegistrationInput

OnTriggerRegistrationInput is the input passed to the on_trigger_registration_function_id hook when a worker attempts to register a trigger through the RBAC port. Return an OnTriggerRegistrationResult with the (possibly mapped) fields, or an error to deny the registration.

OnTriggerRegistrationResult

OnTriggerRegistrationResult is the result returned from the on_trigger_registration_function_id hook. Every field is optional; an omitted field keeps the original value from the registration request.

OnTriggerTypeRegistrationInput

OnTriggerTypeRegistrationInput is the input passed to the on_trigger_type_registration_function_id hook when a worker attempts to register a new trigger type through the RBAC port. Return an OnTriggerTypeRegistrationResult with the (possibly mapped) fields, or an error to deny the registration.

OnTriggerTypeRegistrationResult

OnTriggerTypeRegistrationResult is the result returned from the on_trigger_type_registration_function_id hook. Every field is optional; an omitted field keeps the original value from the registration request.

observability

Package observability holds the OpenTelemetry helpers of the iii Go SDK, the counterpart of the Node SDK’s @iii-dev/helpers/observability: a structured Logger that correlates log records with traces, a traced HTTP client (NewTransport, NewHTTPClient), W3C trace context and baggage helpers, span helpers (WithSpan, RecordSpanEvent, …), payload redaction, and the worker resource metrics. Import

Functions

CurrentSpanID

CurrentSpanID returns the span id of the span in ctx as 16 lowercase hex digits, or "" when ctx has none (Node currentSpanId). Signature

Parameters

context.Context
required

CurrentSpanIsRecording

CurrentSpanIsRecording reports whether ctx holds a span that records; false when there is none or the sampler dropped it (Node currentSpanIsRecording). Signature

Parameters

context.Context
required

CurrentTraceID

CurrentTraceID returns the trace id of the span in ctx as 32 lowercase hex digits, or "" when ctx has none (Node currentTraceId). Signature

Parameters

context.Context
required

ExtractBaggage

ExtractBaggage returns ctx with the members of a W3C baggage header; an invalid header leaves ctx unchanged (Node extractBaggage). Signature

Parameters

context.Context
required
string
required

ExtractContext

ExtractContext returns ctx with both a traceparent and a baggage header applied; either may be empty (Node extractContext). Signature

Parameters

context.Context
required
string
required
string
required

ExtractTraceparent

ExtractTraceparent returns ctx with the remote span context of a W3C traceparent header as its parent; an invalid header leaves ctx unchanged (Node extractTraceparent). Signature

Parameters

context.Context
required
string
required

Flush

Flush exports the spans, metrics and log records buffered by the running client telemetry without stopping it (Node flushOtel); nil when none is running. Use it before a short-lived process exits without closing its client. Signature

Parameters

context.Context
required

GetAllBaggage

GetAllBaggage returns every baggage member in ctx as a key/value map (Node getAllBaggage). Signature

Parameters

context.Context
required

GetBaggageEntry

GetBaggageEntry returns the value of the baggage member key in ctx and whether it is present (Node getBaggageEntry). Signature

Parameters

context.Context
required
string
required

GetLogger

GetLogger returns the OpenTelemetry logger of the running client telemetry, or nil when there is none (Node getLogger). Most code should use Logger instead. Signature

InjectBaggage

InjectBaggage returns the W3C baggage header for the baggage in ctx, or "" when ctx has none (Node injectBaggage). Signature

Parameters

context.Context
required

InjectTraceparent

InjectTraceparent returns the W3C traceparent header for the span in ctx, or "" when ctx has none (Node injectTraceparent). Signature

Parameters

context.Context
required

NewHTTPClient

NewHTTPClient returns a copy of base (a zero http.Client when nil) whose transport is wrapped with NewTransport. base itself is not modified. Signature
*http.Client
required

NewTransport

NewTransport wraps base (http.DefaultTransport when nil) so every request runs inside an OpenTelemetry CLIENT span, the Go counterpart of the Node SDK’s executeTracedRequest and patchGlobalFetch. The span is named “METHOD /path” and carries the HTTP semantic convention attributes (http.request.method, url.full, server.address, server.port, url.scheme, url.path, url.query, http.response.status_code, the content-type and accept headers and the body sizes); the W3C traceparent and baggage of the span are injected into the request; a network error or a status >= 400 sets an ERROR status and error.type. url.full and url.query carry no credentials, as the OpenTelemetry HTTP semantic conventions require: userinfo becomes REDACTED:REDACTED and the values of the AWSAccessKeyId, Signature, sig and X-Goog-Signature query parameters become REDACTED. The request itself is sent unchanged. The parent span comes from the request’s context (http.NewRequestWithContext with a handler’s ctx). URLs containing one of the comma-separated substrings of OTEL_FETCH_IGNORE_URLS, or every request when the running client’s OtelConfig.FetchInstrumentationEnabled is false, pass through untraced. Signature

Parameters

http.RoundTripper
required

NewWorkerMetricsCollector

NewWorkerMetricsCollector starts a collector. The first Collect reports CPU usage and scheduling latency since this call; each later one since the previous Collect. Signature

RecordSpanEvent

RecordSpanEvent adds an event with optional attributes to the span in ctx; a no-op when it does not record (Node recordSpanEvent). Attribute values convert as in SetCurrentSpanAttribute. Signature

Parameters

context.Context
required
string
required
map[string]any
required

Redact

Redact returns v with the value of every sensitive key, at any depth, replaced by RedactedPlaceholder (Node redact). A key is sensitive when it contains api_key, apikey, api-key, password, secret, credential, authorization, auth_token, access_token, refresh_token, bearer, private_key or client_secret (any case), or is “token” or ends with “_token” or “-token”. A map[string]any or []any is copied recursively and nil and scalars are returned as they are; any other value (a struct, a typed map, json.RawMessage) is serialized and returned as a redacted json.RawMessage. Signature

Parameters

any
required

RedactAndTruncate

RedactAndTruncate redacts v, serializes it to JSON and caps the result at maxBytes bytes, ending a cut payload with a truncation marker and never splitting a UTF-8 sequence; maxBytes <= 0 means no cap (Node redactAndTruncate). It reports whether the payload was cut. A value that cannot be serialized becomes “null”. Signature

Parameters

any
required
int
required

RegisterWorkerGauges

RegisterWorkerGauges registers the worker resource gauges on meter (Node registerWorkerGauges): iii.worker.memory.heap_used, iii.worker.memory.heap_total, iii.worker.memory.rss, iii.worker.memory.external, iii.worker.cpu.percent, iii.worker.cpu.user_micros, iii.worker.cpu.system_micros, iii.worker.event_loop.lag_ms and iii.worker.uptime_seconds, each observed once per collection with the worker.id and worker.name attributes (values the platform cannot measure are skipped). A client does this itself when iii.WithMetricsReporting is on; call it for a meter of your own. Signature

Parameters

Meter
required
WorkerGaugesOptions
required

RemoveBaggageEntry

RemoveBaggageEntry returns ctx without the baggage member key (Node removeBaggageEntry). Signature

Parameters

context.Context
required
string
required

ResolveMaxBytesFromEnv

ResolveMaxBytesFromEnv returns the recorded-payload cap set by III_TRACE_PAYLOAD_MAX_BYTES, or 0 (no cap) when it is unset, blank, “unlimited”, not a plain positive integer (Node resolveMaxBytesFromEnv, whose null is 0 here). Signature

SafeStringify

SafeStringify serializes v to JSON, or returns “[unserializable]” when it cannot be serialized (Node safeStringify; a cyclic value is reported as unserializable). Signature

Parameters

any
required

SetBaggageEntry

SetBaggageEntry returns ctx with the baggage member key set to value (Node setBaggageEntry). The baggage travels with every Trigger made with the returned ctx and is copied onto the spans started under it. An invalid key is an error. Signature

Parameters

context.Context
required
string
required
string
required

SetCurrentSpanAttribute

SetCurrentSpanAttribute sets an attribute on the span in ctx; a no-op when it does not record (Node setCurrentSpanAttribute). Strings, booleans, integers, floats and slices of them keep their type; other values are recorded as text. Signature

Parameters

context.Context
required
string
required
any
required

SetCurrentSpanError

SetCurrentSpanError sets an ERROR status with message on the span in ctx; a no-op when there is none (Node setCurrentSpanError). Signature

Parameters

context.Context
required
string
required

WithSpan

WithSpan runs fn inside a new span named name and returns fn’s result (Node withSpan). The span is a child of opts.Traceparent when set, else of the span in ctx; fn receives the span and a ctx carrying it, to pass on to Trigger, the Logger or nested spans. The span ends with an OK status when fn returns a nil error, and with an ERROR status and an exception event when fn returns an error or panics (the panic is re-raised). Without running telemetry the global tracer provider is used. Signature
context.Context
required
string
required
SpanOptions
required
func(ctx context.Context, span Span) (T, error)
required

Constants

Types

BaggageSpanProcessor · Logger · Meter · OtelLogEvent · OtelLogger · Span · SpanOptions · WorkerGauges · WorkerGaugesOptions · WorkerMetrics · WorkerMetricsCollector

BaggageSpanProcessor

BaggageSpanProcessor is an OpenTelemetry span processor that copies every baggage member of a span’s parent context onto the span as a string attribute when it starts (Node BaggageSpanProcessor). The client’s tracer provider already runs it; add it to a tracer provider of your own with sdktrace.WithSpanProcessor, before the exporting processor.

Logger

Logger is a structured logger that emits OpenTelemetry log records (Node Logger). Every call captures the trace and span of ctx, so log lines correlate with the distributed trace without manual wiring; TraceID and SpanID override them when set. Pass structured data (a map or struct) instead of formatting it into the message, so it can be filtered and aggregated: it is attached as the log.data attribute. When no client’s telemetry is running, Logger falls back to the standard log package. The zero value is ready to use.

Meter

Meter is an OpenTelemetry meter, as taken by RegisterWorkerGauges.

OtelLogEvent

OtelLogEvent is a log record as the engine reports it (Node OtelLogEvent), for functions that consume the engine’s log stream.

OtelLogger

OtelLogger is an OpenTelemetry logger, as returned by GetLogger.

Span

Span is an OpenTelemetry span (Node exports the Span type the same way).

SpanOptions

SpanOptions are the options of WithSpan (Node withSpan options).

WorkerGauges

WorkerGauges is a registration of the worker resource gauges, returned by RegisterWorkerGauges.

WorkerGaugesOptions

WorkerGaugesOptions identifies the worker the gauges report for (Node WorkerGaugesOptions).

WorkerMetrics

WorkerMetrics is one snapshot of the worker’s resource usage (Node WorkerMetrics). A field the platform cannot measure is nil.

WorkerMetricsCollector

WorkerMetricsCollector collects WorkerMetrics (Node WorkerMetricsCollector).