std/otlp
On this page
Index
- type
Resource - type
ExportErr- method
ExportErr.display
- method
- type
Exporter- method
Exporter.with_headers - method
Exporter.with_backoff - method
Exporter.send_traces - method
Exporter.send_metrics
- method
- fn
encode_traces - fn
encode_metrics - fn
exporter
Types
Resource
struct Resource {
service: Str
attributes: List[(Str, Str)] = []
scope: Str = "std/trace"
version: Str = ""
}What an export says about the program that made the spans: the service.name resource attribute, more
resource attributes, and the instrumentation scope name (and version) the spans are filed under.
ExportErr
enum ExportErr {
Transport(msg: Str)
Rejected(status: Int, body: Str)
GaveUp(status: Int, tries: Int)
}Why an export failed: the transport (no response), a status the collector will not take (400 and the like: a retry would send the same bytes), or retries that ran out with the last answer.
ExportErr.display
fn (e: ExportErr) display() -> Strexport: MSG, export rejected: STATUS BODY, export gave up after N tries: STATUS.
Exporter
struct Exporter {
client: http.Client
endpoint: Str
resource: Resource
headers: Map[Str, Str]
backoff: backoff.Backoff
clock: Clock
rand: Rand
}Sends OTLP/HTTP requests (POST {endpoint}/v1/traces and /v1/metrics, Content-Type: application/x-protobuf)
to a collector. 429, 502, 503 and 504 are retried with the schedule of backoff, waiting at least the
Retry-After the collector asks for (in seconds); any other non 2xx status is not retried, as the OTLP
specification says.
Exporter.with_headers
fn (e: Exporter) with_headers(h: Map[Str, Str]) -> ExporterThe exporter sending these headers on every request (an API key, Authorization).
Exporter.with_backoff
fn (e: Exporter) with_backoff(b: backoff.Backoff) -> ExporterThe exporter retrying on schedule b (5 tries by default).
Exporter.send_traces
fn (e: Exporter) send_traces(spans: List[trace.Span]) -> () ! ExportErr uses net.dial, clock, randExports spans (one request; an empty list sends nothing).
Exporter.send_metrics
fn (e: Exporter) send_metrics(reg: metrics.Registry, start_ms: Int) -> () ! ExportErr uses net.dial, clock, randExports the registry’s metrics (one request), every point cumulative since start_ms, stamped now.
Functions
encode_traces
fn encode_traces(res: Resource, spans: List[trace.Span]) -> BytesThe body of an ExportTraceServiceRequest for spans (one ResourceSpans, one ScopeSpans). A span’s
trace id is its request id when that is 32 hex digits, else the first 16 bytes of the SHA-256 of the id;
the request span of an id is a server span with the id as its trace, its other spans are internal
spans whose parent is that request span; span ids are the first 8 bytes of a SHA-256 of the span’s
request id, name and start, so an export repeated after a retry names the same spans. A request span’s
HTTP status becomes the span status (500 and above is an error) and the attribute http.response.status_code.
encode_metrics
fn encode_metrics(res: Resource, reg: metrics.Registry, start_ms: Int, now_ms: Int) -> BytesThe body of an ExportMetricsServiceRequest for the families of reg (one ResourceMetrics, one ScopeMetrics),
every point cumulative since start_ms and stamped now_ms (Unix milliseconds): a counter is a monotonic Sum,
a gauge a Gauge, a histogram a Histogram (bucket counts per bucket, not cumulative, as OTLP has them), a summary
a Summary with its count and sum (no quantile values); a label becomes a string attribute of the point.
exporter
fn exporter(client: http.Client, endpoint: Str, res: Resource, clock: Clock, rand: Rand) -> ExporterAn exporter to the collector at endpoint (http://host:4318, no path), for the spans and metrics of res.