Documentation
¶
Overview ¶
Package otlpwire provides utilities for working with OTLP wire format data.
Example (ObservabilityStats) ¶
Example_observabilityStats demonstrates using Count() for observability metrics.
// Simulate receiving OTLP metrics data
metrics := createSampleMetrics(100)
marshaler := &pmetric.ProtoMarshaler{}
otlpBytes, _ := marshaler.MarshalMetrics(metrics)
// Count signals for observability
data := otlpwire.ExportMetricsServiceRequest(otlpBytes)
count, _ := data.DataPointCount()
// Emit metrics about incoming data (cardinality monitoring, billing, etc.)
fmt.Printf("Received %d data points for processing\n", count)
Output: Received 100 data points for processing
Example (ShardingByService) ¶
Example_shardingByService demonstrates splitting batches for distributed processing.
// Create metrics from multiple services
metrics := createMultiServiceMetrics()
marshaler := &pmetric.ProtoMarshaler{}
otlpBytes, _ := marshaler.MarshalMetrics(metrics)
// Split batch by resource for sharding
data := otlpwire.ExportMetricsServiceRequest(otlpBytes)
numWorkers := 3
resources, getErr := data.ResourceMetrics()
i := 0
for resource := range resources {
// Hash resource for consistent routing
resourceBytes, _ := resource.Resource()
hash := hashBytes(resourceBytes)
workerID := int(hash % uint64(numWorkers))
var buf bytes.Buffer
_, _ = resource.WriteTo(&buf)
count, _ := otlpwire.ExportMetricsServiceRequest(buf.Bytes()).DataPointCount()
fmt.Printf("Resource %d → Worker %d (%d data points)\n", i, workerID, count)
i++
}
if err := getErr(); err != nil {
fmt.Printf("Error: %v\n", err)
}
Output: Resource 0 → Worker 0 (10 data points) Resource 1 → Worker 1 (10 data points) Resource 2 → Worker 2 (10 data points)
Example (TypeComposition) ¶
Example_typeComposition demonstrates how types compose naturally.
metrics := createSampleMetrics(25)
marshaler := &pmetric.ProtoMarshaler{}
otlpBytes, _ := marshaler.MarshalMetrics(metrics)
// Count at batch level
batch := otlpwire.ExportMetricsServiceRequest(otlpBytes)
count, _ := batch.DataPointCount()
fmt.Printf("Total data points: %d\n", count)
// Iterate and count at resource level (zero allocation)
resourceCount := 0
resources, getErr := batch.ResourceMetrics()
for resource := range resources {
if resourceCount == 0 {
// Count signals in this resource (zero allocation)
dpCount, _ := resource.DataPointCount()
fmt.Printf("Resource 0 data points: %d\n", dpCount)
}
resourceCount++
}
if err := getErr(); err != nil {
fmt.Printf("Error: %v\n", err)
}
fmt.Printf("Number of resources: %d\n", resourceCount)
Output: Total data points: 25 Resource 0 data points: 25 Number of resources: 1
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ExportLogsServiceRequest ¶
type ExportLogsServiceRequest []byte
ExportLogsServiceRequest represents an OTLP ExportLogsServiceRequest message.
func (ExportLogsServiceRequest) LogRecordCount ¶
func (l ExportLogsServiceRequest) LogRecordCount() (int, error)
LogRecordCount returns the total number of log records in the batch.
func (ExportLogsServiceRequest) ResourceLogs ¶
func (l ExportLogsServiceRequest) ResourceLogs() (iter.Seq[ResourceLogs], func() error)
ResourceLogs returns an iterator over ResourceLogs in the batch. The returned function should be called after iteration to check for errors.
type ExportMetricsServiceRequest ¶
type ExportMetricsServiceRequest []byte
ExportMetricsServiceRequest represents an OTLP ExportMetricsServiceRequest message.
func (ExportMetricsServiceRequest) DataPointCount ¶
func (m ExportMetricsServiceRequest) DataPointCount() (int, error)
DataPointCount returns the total number of metric data points in the batch.
func (ExportMetricsServiceRequest) ResourceMetrics ¶
func (m ExportMetricsServiceRequest) ResourceMetrics() (iter.Seq[ResourceMetrics], func() error)
ResourceMetrics returns an iterator over ResourceMetrics in the batch. The returned function should be called after iteration to check for errors.
type ExportTracesServiceRequest ¶
type ExportTracesServiceRequest []byte
ExportTracesServiceRequest represents an OTLP ExportTracesServiceRequest message.
func (ExportTracesServiceRequest) ResourceSpans ¶
func (t ExportTracesServiceRequest) ResourceSpans() (iter.Seq[ResourceSpans], func() error)
ResourceSpans returns an iterator over ResourceSpans in the batch. The returned function should be called after iteration to check for errors.
func (ExportTracesServiceRequest) SpanCount ¶
func (t ExportTracesServiceRequest) SpanCount() (int, error)
SpanCount returns the total number of spans in the batch.
type ResourceLogs ¶
type ResourceLogs []byte
ResourceLogs represents a single ResourceLogs message.
func (ResourceLogs) LogRecordCount ¶
func (r ResourceLogs) LogRecordCount() (int, error)
LogRecordCount returns the number of log records in this resource.
func (ResourceLogs) Resource ¶
func (r ResourceLogs) Resource() ([]byte, error)
Resource returns the raw Resource message bytes.
type ResourceMetrics ¶
type ResourceMetrics []byte
ResourceMetrics represents a single ResourceMetrics message.
func (ResourceMetrics) DataPointCount ¶
func (r ResourceMetrics) DataPointCount() (int, error)
DataPointCount returns the number of metric data points in this resource.
func (ResourceMetrics) Resource ¶
func (r ResourceMetrics) Resource() ([]byte, error)
Resource returns the raw Resource message bytes.
type ResourceSpans ¶
type ResourceSpans []byte
ResourceSpans represents a single ResourceSpans message.
func (ResourceSpans) Resource ¶
func (r ResourceSpans) Resource() ([]byte, error)
Resource returns the raw Resource message bytes.
func (ResourceSpans) ScopeSpans ¶ added in v0.0.2
func (r ResourceSpans) ScopeSpans() (iter.Seq[ScopeSpans], func() error)
ScopeSpans returns an iterator over ScopeSpans in this ResourceSpans. Field 2 in the ResourceSpans protobuf message. The returned function should be called after iteration to check for errors.
func (ResourceSpans) SpanCount ¶
func (r ResourceSpans) SpanCount() (int, error)
SpanCount returns the number of spans in this resource.
type ScopeSpans ¶ added in v0.0.2
type ScopeSpans []byte
ScopeSpans represents a single ScopeSpans message (raw wire bytes).
func (ScopeSpans) SpanCount ¶ added in v0.0.2
func (s ScopeSpans) SpanCount() (int, error)
SpanCount returns the number of spans in this ScopeSpans.
type Span ¶ added in v0.0.2
type Span []byte
Span represents a single Span message (raw wire bytes).
func (Span) ParentSpanID ¶ added in v0.0.2
ParentSpanID extracts the parent span ID from the Span. Returns the raw 8 bytes from field 4. Returns zero value if the field is not present (root span).