mirror of
https://github.com/open-telemetry/opentelemetry-go.git
synced 2024-12-16 10:19:23 +02:00
4047c0877a
* Update api for Must constructors, with SDK helpers * Update for Must constructors, leaving TODOs about global errors * Add tests * Move Must methods into metric.Must * Apply the feedback * Remove interfaces * Remove more interfaces * Again... * Remove a sentence about a dead inteface
45 lines
873 B
Go
45 lines
873 B
Go
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
|
|
// }
|
|
// ]
|
|
// }
|
|
}
|