2020-01-02 20:41:21 +02:00
|
|
|
package stdout_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"log"
|
2020-02-29 03:08:30 +02:00
|
|
|
"time"
|
2020-01-02 20:41:21 +02:00
|
|
|
|
|
|
|
"go.opentelemetry.io/otel/api/key"
|
|
|
|
"go.opentelemetry.io/otel/api/metric"
|
2020-03-02 23:54:57 +02:00
|
|
|
"go.opentelemetry.io/otel/exporters/metric/stdout"
|
2020-01-02 20:41:21 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
func ExampleNewExportPipeline() {
|
|
|
|
// Create a meter
|
2020-01-03 19:48:45 +02:00
|
|
|
pusher, err := stdout.NewExportPipeline(stdout.Config{
|
2020-01-02 20:41:21 +02:00
|
|
|
PrettyPrint: true,
|
|
|
|
DoNotPrintTime: true,
|
2020-02-29 03:08:30 +02:00
|
|
|
}, time.Minute)
|
2020-01-02 20:41:21 +02:00
|
|
|
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:
|
2020-03-11 20:57:57 +02:00
|
|
|
counter := metric.Must(meter).NewInt64Counter("a.counter", metric.WithKeys(key))
|
2020-01-02 20:41:21 +02:00
|
|
|
labels := meter.Labels(key.String("value"))
|
|
|
|
|
|
|
|
counter.Add(ctx, 100, labels)
|
|
|
|
|
|
|
|
// Output:
|
|
|
|
// {
|
|
|
|
// "updates": [
|
|
|
|
// {
|
|
|
|
// "name": "a.counter{key=value}",
|
|
|
|
// "sum": 100
|
|
|
|
// }
|
|
|
|
// ]
|
|
|
|
// }
|
|
|
|
}
|