glossymetric
import "github.com/foomo/opentelemetry-go/exporters/glossy/glossymetric"Styled terminal exporter for OpenTelemetry metrics. Renders Sum, Gauge, and Histogram data in a readable format.
Types
Exporter
type Exporter struct {
// contains filtered or unexported fields
}Implements go.opentelemetry.io/otel/sdk/metric.Exporter.
Constructors
New
func New(opts ...Option) (*Exporter, error)Creates a new glossy metric exporter. Output defaults to os.Stdout.
NewTest
func NewTest(tb testing.TB, opts ...Option) metric.ExporterCreates an exporter for use in tests. Automatically applies WithWriter(tb.Output()). Calls tb.Fatal() on initialization error.
NewTestMain
func NewTestMain(m testingx.M, opts ...Option) metric.ExporterCreates an exporter for use in TestMain. Automatically applies WithWriter(os.Stdout). Panics on initialization error.
TIP
testingx.M is from github.com/foomo/go/testing, not *testing.M.
Methods
Export
func (e *Exporter) Export(ctx context.Context, rm *metricdata.ResourceMetrics) errorExports metrics in human-readable format. Returns an error if the context is canceled.
ForceFlush
func (e *Exporter) ForceFlush(ctx context.Context) errorNo-op. Required by the metric.Exporter interface.
Shutdown
func (e *Exporter) Shutdown(ctx context.Context) errorShuts down the exporter. Currently a no-op.
Temporality
func (e *Exporter) Temporality(kind sdkmetric.InstrumentKind) metricdata.TemporalityReturns the temporality for the given instrument kind using the configured selector.
Aggregation
func (e *Exporter) Aggregation(kind sdkmetric.InstrumentKind) sdkmetric.AggregationReturns the aggregation for the given instrument kind using the configured selector.
Options
| Option | Signature | Description | Default |
|---|---|---|---|
WithWriter | WithWriter(w io.Writer) Option | Output destination | os.Stdout |
WithoutHistograms | WithoutHistograms() Option | Disable histogram detail printing | histograms enabled |
WithTemporalitySelector | WithTemporalitySelector(fn sdkmetric.TemporalitySelector) Option | Set temporality selector | Cumulative |
WithAggregationSelector | WithAggregationSelector(fn sdkmetric.AggregationSelector) Option | Set aggregation selector | DefaultAggregationSelector |
Example Output
METRICS
Scope: example
──────────────────────────────────────────────────
Metric: requests
Description: Number of requests received
Unit: 1
attrs: server=central
Value: 5
──────────────────────────────────────────────────
Metric: requests.size
Description: Size of received requests
Unit: kb
attrs: server=central
Histogram: min=3 max=30 avg=12.800 count=10
──────────────────────────────────────────────────