otlp export + obs.init for observability#450
Merged
Merged
Conversation
std.otlp encodes std.trace spans and std.metrics samples as OTLP protobuf (ExportTraceServiceRequest / ExportMetricsServiceRequest, hand-built on std.protobuf) and POSTs them to an OTLP/HTTP collector at /v1/traces and /v1/metrics. std.obs.init reads the standard OTEL_* environment variables, turns tracing and metric collection on, and spawns a background exporter that periodically flushes spans and the current metric snapshot. one call wires up observability; with no endpoint configured it stays off. scope for this pass: spans with string attributes and status, counter and gauge metrics in full, histograms as a count+sum data point (per-bucket detail omitted), OTLP/HTTP transport only (grpc fails with a clear message). tested: - pith test std/otlp.pith (6 tests): endpoint parsing, and round-trips of a trace request, a monotonic-sum counter with an int data point and its label attribute, and a histogram count+sum, all decoded back with protobuf.reader. - pith test std/obs.pith (3 tests): init stays off with no endpoint, the loop tick picks the smaller interval, an empty endpoint is a no-op. - doc --check clean on both modules. - end-to-end: ran obs.init against a local stub collector that decodes the posted protobuf; the stub received /v1/traces (service.name + span name) and /v1/metrics (service.name + metric name) as expected. - make run-examples: 86 passed, 0 failed (no regression).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
summary
phase 3 of the observability sprint: OTLP export and a one-call
obs.init.protobuf (
ExportTraceServiceRequest/ExportMetricsServiceRequest),hand-built on std.protobuf the way the db drivers hand-write their wire
protocols, and POSTs them to an OTLP/HTTP collector at
/v1/tracesand/v1/metricswithcontent-type: application/x-protobuf.init()reads the standardOTEL_*environment variables,turns tracing and metric collection on, and spawns a background exporter
that periodically flushes finished spans and the current metric snapshot.
with no
OTEL_EXPORTER_OTLP_ENDPOINTset it does nothing, so the call isfree to leave in.
public api:
otlp.target(service_name, endpoint, protocol) -> Targetotlp.encode_traces(service_name, spans) -> Bytesotlp.encode_metrics(service_name, samples) -> Bytesotlp.export_traces(target, spans) -> Bool/otlp.export_metrics(target, samples) -> Boolobs.init(),obs.start(service_name, endpoint, protocol, metric_interval_ms, span_delay_ms),obs.active(),obs.shutdown()scope
spans with string attributes and status, counter and gauge metrics in full,
histograms as a count+sum data point (per-bucket boundaries omitted — noted in
the code), OTLP/HTTP only (grpc fails with a clear message).
tested
pith test std/otlp.pith(6 tests): endpoint parsing plus reader round-tripsof a trace request, a monotonic-sum counter with an int data point and its
label attribute, and a histogram count+sum.
pith test std/obs.pith(3 tests): stays off with no endpoint, loop tickpicks the smaller interval, empty endpoint is a no-op.
doc --checkclean on both modules.obs.initagainst a local stub collector that decodes theposted protobuf; it received
/v1/traces(service.name + span name) and/v1/metrics(service.name + metric name) as expected.make run-examples: 86 passed, 0 failed.design notes
otlp.Targetis namedTargetrather thanConfigto avoid a cross-modulestruct-name clash with
tls.Config(E219). histograms map to acount+sum data point for v1; a fuller mapping with bucket boundaries can follow.