Documentation ¶
Overview ¶
Package stdout contains an OpenTelemetry exporter for metric telemetry to be written to an output destination as JSON.
This package is currently in a pre-GA phase. Backwards incompatible changes may be introduced in subsequent minor version releases as we work to track the evolving OpenTelemetry specification and user feedback.
Example ¶
package main import ( "context" "log" "go.opentelemetry.io/otel/exporters/stdout/stdoutmetric" "go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/metric" "go.opentelemetry.io/otel/metric/global" controller "go.opentelemetry.io/otel/sdk/metric/controller/basic" processor "go.opentelemetry.io/otel/sdk/metric/processor/basic" "go.opentelemetry.io/otel/sdk/metric/selector/simple" ) const ( instrumentationName = "github.com/instrumentron" instrumentationVersion = "v0.1.0" ) var ( meter = global.GetMeterProvider().Meter( instrumentationName, metric.WithInstrumentationVersion(instrumentationVersion), ) loopCounter = metric.Must(meter).NewInt64Counter("function.loops") paramValue = metric.Must(meter).NewInt64ValueRecorder("function.param") nameKey = attribute.Key("function.name") ) func add(ctx context.Context, x, y int64) int64 { nameKV := nameKey.String("add") loopCounter.Add(ctx, 1, nameKV) paramValue.Record(ctx, x, nameKV) paramValue.Record(ctx, y, nameKV) return x + y } func multiply(ctx context.Context, x, y int64) int64 { nameKV := nameKey.String("multiply") loopCounter.Add(ctx, 1, nameKV) paramValue.Record(ctx, x, nameKV) paramValue.Record(ctx, y, nameKV) return x * y } func InstallExportPipeline(ctx context.Context) func() { exporter, err := stdoutmetric.New(stdoutmetric.WithPrettyPrint()) if err != nil { log.Fatalf("creating stdoutmetric exporter: %v", err) } pusher := controller.New( processor.New( simple.NewWithInexpensiveDistribution(), exporter, ), controller.WithExporter(exporter), ) if err = pusher.Start(ctx); err != nil { log.Fatalf("starting push controller: %v", err) } global.SetMeterProvider(pusher.MeterProvider()) return func() { if err := pusher.Stop(ctx); err != nil { log.Fatalf("stopping push controller: %v", err) } } } func main() { ctx := context.Background() // Registers a meter Provider globally. cleanup := InstallExportPipeline(ctx) defer cleanup() log.Println("the answer is", add(ctx, multiply(ctx, multiply(ctx, 2, 2), 10), 2)) }
Output:
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Exporter ¶
type Exporter struct {
// contains filtered or unexported fields
}
func (*Exporter) Export ¶
func (e *Exporter) Export(_ context.Context, checkpointSet exportmetric.CheckpointSet) error
func (*Exporter) ExportKindFor ¶
func (e *Exporter) ExportKindFor(desc *metric.Descriptor, kind aggregation.Kind) exportmetric.ExportKind
type Option ¶
type Option interface {
// contains filtered or unexported methods
}
Option sets the value of an option for a Config.
func WithLabelEncoder ¶
WithLabelEncoder sets the label encoder used in export.
func WithPrettyPrint ¶
func WithPrettyPrint() Option
WithPrettyPrint sets the export stream format to use JSON.
func WithWriter ¶
WithWriter sets the export stream destination.
func WithoutTimestamps ¶
func WithoutTimestamps() Option
WithoutTimestamps sets the export stream to not include timestamps.
Click to show internal directories.
Click to hide internal directories.