1
0
mirror of https://github.com/open-telemetry/opentelemetry-go.git synced 2024-12-16 10:19:23 +02:00
opentelemetry-go/exporters/metric/stdout/example_test.go

45 lines
873 B
Go
Raw Normal View History

package stdout_test
import (
"context"
"log"
"time"
"go.opentelemetry.io/otel/api/key"
"go.opentelemetry.io/otel/api/metric"
"go.opentelemetry.io/otel/exporters/metric/stdout"
)
func ExampleNewExportPipeline() {
// Create a meter
pusher, err := stdout.NewExportPipeline(stdout.Config{
PrettyPrint: true,
DoNotPrintTime: true,
}, time.Minute)
if err != nil {
log.Fatal("Could not initialize stdout exporter:", err)
}
defer pusher.Stop()
ctx := context.Background()
key := key.New("key")
meter := pusher.Meter("example")
// Create and update a single counter:
counter := metric.Must(meter).NewInt64Counter("a.counter", metric.WithKeys(key))
labels := meter.Labels(key.String("value"))
counter.Add(ctx, 100, labels)
// Output:
// {
// "updates": [
// {
// "name": "a.counter{key=value}",
// "sum": 100
// }
// ]
// }
}