Units are encoded according to the case-sensitive abbreviations from the Unified Code for Units of Measure: http://unitsofmeasure.org/ucum.html
const ( UnitNone = "1" // Deprecated: Use UnitDimensionless. UnitDimensionless = "1" UnitBytes = "By" UnitMilliseconds = "ms" UnitSeconds = "s" )
func Record(ctx context.Context, ms ...Measurement)
Record records one or multiple measurements with the same context at once. If there are any tags in the context, measurements will be tagged with them.
▹ Example
func RecordWithOptions(ctx context.Context, ros ...Options) error
RecordWithOptions records measurements from the given options (if any) against context and tags and attachments in the options (if any). If there are any tags in the context, measurements will be tagged with them.
func RecordWithTags(ctx context.Context, mutators []tag.Mutator, ms ...Measurement) error
RecordWithTags records one or multiple measurements at once.
Measurements will be tagged with the tags in the context mutated by the mutators. RecordWithTags is useful if you want to record with tag mutations but don't want to propagate the mutations in the context.
Float64Measure is a measure for float64 values.
type Float64Measure struct {
// contains filtered or unexported fields
}
func Float64(name, description, unit string) *Float64Measure
Float64 creates a new measure for float64 values.
See the documentation for interface Measure for more guidance on the parameters of this function.
func (m *Float64Measure) Description() string
Description returns the description of the measure.
func (m *Float64Measure) M(v float64) Measurement
M creates a new float64 measurement. Use Record to record measurements.
func (m *Float64Measure) Name() string
Name returns the name of the measure.
func (m *Float64Measure) Unit() string
Unit returns the unit of the measure.
Int64Measure is a measure for int64 values.
type Int64Measure struct {
// contains filtered or unexported fields
}
func Int64(name, description, unit string) *Int64Measure
Int64 creates a new measure for int64 values.
See the documentation for interface Measure for more guidance on the parameters of this function.
func (m *Int64Measure) Description() string
Description returns the description of the measure.
func (m *Int64Measure) M(v int64) Measurement
M creates a new int64 measurement. Use Record to record measurements.
func (m *Int64Measure) Name() string
Name returns the name of the measure.
func (m *Int64Measure) Unit() string
Unit returns the unit of the measure.
Measure represents a single numeric value to be tracked and recorded. For example, latency, request bytes, and response bytes could be measures to collect from a server.
Measures by themselves have no outside effects. In order to be exported, the measure needs to be used in a View. If no Views are defined over a measure, there is very little cost in recording it.
type Measure interface { // Name returns the name of this measure. // // Measure names are globally unique (among all libraries linked into your program). // We recommend prefixing the measure name with a domain name relevant to your // project or application. // // Measure names are never sent over the wire or exported to backends. // They are only used to create Views. Name() string // Description returns the human-readable description of this measure. Description() string // Unit returns the units for the values this measure takes on. // // Units are encoded according to the case-sensitive abbreviations from the // Unified Code for Units of Measure: http://unitsofmeasure.org/ucum.html Unit() string }
Measurement is the numeric value measured when recording stats. Each measure provides methods to create measurements of their kind. For example, Int64Measure provides M to convert an int64 into a measurement.
type Measurement struct {
// contains filtered or unexported fields
}
func (m Measurement) Measure() Measure
Measure returns the Measure from which this Measurement was created.
func (m Measurement) Value() float64
Value returns the value of the Measurement as a float64.
Options apply changes to recordOptions.
type Options func(*recordOptions)
func WithAttachments(attachments metricdata.Attachments) Options
WithAttachments applies provided exemplar attachments.
func WithMeasurements(measurements ...Measurement) Options
WithMeasurements applies provided measurements.
func WithRecorder(meter Recorder) Options
WithRecorder records the measurements to the specified `Recorder`, rather than to the global metrics recorder.
func WithTags(mutators ...tag.Mutator) Options
WithTags applies provided tag mutators.
Recorder provides an interface for exporting measurement information from the static Record method by using the WithRecorder option.
type Recorder interface { // Record records a set of measurements associated with the given tags and attachments. // The second argument is a `[]Measurement`. Record(*tag.Map, interface{}, map[string]interface{}) }