Documentation
¶
Overview ¶
Package pdataconv is the optional OTel-Go bridge: it converts the collector pdata metrics type (pmetric.Metrics) into the storage library's internal, []byte-based metric.Metrics ingest batch. It exists so OTel users get zero-friction ingestion without the pdata dependency or its allocation profile reaching the storage hot path — pdata is referenced only here, never by the core packages or the storage facade.
The conversion necessarily allocates: pdata stores keys/values as Go strings, so projecting them to the internal []byte model copies each one. Embedders that decode OTLP protobuf themselves should build metric.Metrics directly (aliasing the decode buffer) to stay allocation-free; this bridge is the compatibility path, not the fast path.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AppendLogs ¶ added in v0.3.0
AppendLogs converts an OTLP logs batch into dst, reusing dst's retained capacity (call log.Logs.Reset or use log.GetLogs for a recycled batch). dropped counts the records carrying no usable time at all (see [appendRecord]). Non-string record bodies are rendered to their textual form, since the internal model stores a body as text bytes.
func AppendProfiles ¶ added in v0.3.0
AppendProfiles converts an OTLP profiles batch into dst, reusing dst's retained capacity (call profile.Profiles.Reset or use profile.GetProfiles for a recycled batch). The OTLP shared ProfilesDictionary maps one-to-one onto profile.Dictionary, so its tables are copied index-preserving (samples/stacks/locations keep referencing the same indices). Everything is representable, so dropped is always 0; it is returned for symmetry with AppendMetrics's point count (Dropped.Points).
func AppendTraces ¶ added in v0.3.0
AppendTraces converts an OTLP traces batch into dst, reusing dst's retained capacity (call trace.Traces.Reset or use trace.GetTraces for a recycled batch). Every span, event, and link is representable, so dropped is always 0; it is returned for symmetry with AppendMetrics's point count (Dropped.Points) and to leave room for future unrepresentable cases.
Types ¶
type Dropped ¶ added in v0.47.0
type Dropped struct {
// Points is the number of data points that could not be represented.
Points int
// Exemplars is the number of exemplars that could not be represented — those on histogram,
// exponential-histogram and summary points (see [AppendMetrics]), plus value-less ones.
Exemplars int
}
Dropped counts what a conversion could not represent. Points and Exemplars are reported separately because they mean different things to a caller: Points feeds the OTLP partial-success response (a rejected data point is data the producer should retry), whereas a dropped exemplar only degrades trace correlation and must not inflate that count.
func AppendMetrics ¶
AppendMetrics converts an OTLP metrics batch into dst, reusing dst's retained capacity (call metric.Metrics.Reset or use metric.GetMetrics for a recycled batch). Gauge and sum number points convert directly, with their exemplars; histogram, exponential-histogram, and summary points are stored by **classic decomposition** into `_count`/`_sum`/`_bucket{le}`/`{quantile}` float series (see histogram.go), so they need no engine support.
**Exemplars on decomposed points are dropped, not stored**, and counted in Dropped.Exemplars. One histogram point becomes several series, so an exemplar on it has no unambiguous home; the Prometheus convention would attach it to the `_bucket` whose `le` covers its value, but committing to that before native histograms exist would bake the choice into the stored shape. Value-less number points are skipped and counted in Dropped.Points.
type MetricsProjector ¶ added in v0.50.1
type MetricsProjector struct {
// contains filtered or unexported fields
}
MetricsProjector hashes pdata points before materializing their attributes on demand. Its zero value is usable; input and projector must not change until the storage write returns.
func (*MetricsProjector) Dropped ¶ added in v0.50.1
func (p *MetricsProjector) Dropped() Dropped
Dropped reports value-less points in the prepared request; projection rejects no additional points.
func (*MetricsProjector) Prepare ¶ added in v0.50.1
func (p *MetricsProjector) Prepare(md pmetric.Metrics) bool
Prepare borrows md, rejecting the entire request if any metric is not gauge/sum or has exemplars. Call Reset after the enclosing write; a false result requires the existing AppendMetrics path.
func (*MetricsProjector) Project ¶ added in v0.50.1
func (p *MetricsProjector) Project(emit func(*metric.Batch)) (emitted int)
Project emits each nonempty metric once, borrowing columns until emit returns and Sources until Reset. Prepare must succeed first; Project may run only once per Prepare.
func (*MetricsProjector) Reset ¶ added in v0.50.1
func (p *MetricsProjector) Reset()
Reset releases borrowed input and materializer contexts; oversized scratch is discarded. It invalidates every Source previously emitted by Project.