2020-03-24 07:41:10 +02:00
|
|
|
// Copyright The OpenTelemetry Authors
|
2019-11-15 23:01:20 +02:00
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
|
|
package metric_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"fmt"
|
2020-02-29 03:08:30 +02:00
|
|
|
"time"
|
2019-11-15 23:01:20 +02:00
|
|
|
|
2020-05-14 01:06:03 +02:00
|
|
|
"go.opentelemetry.io/otel/api/kv"
|
|
|
|
|
2019-11-15 23:01:20 +02:00
|
|
|
"go.opentelemetry.io/otel/api/metric"
|
2020-03-02 23:54:57 +02:00
|
|
|
"go.opentelemetry.io/otel/exporters/metric/stdout"
|
2019-11-15 23:01:20 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
func ExampleNew() {
|
2020-01-03 19:48:45 +02:00
|
|
|
pusher, err := stdout.NewExportPipeline(stdout.Config{
|
2019-11-15 23:01:20 +02:00
|
|
|
PrettyPrint: true,
|
|
|
|
DoNotPrintTime: true, // This makes the output deterministic
|
2020-02-29 03:08:30 +02:00
|
|
|
}, time.Minute)
|
2019-11-15 23:01:20 +02:00
|
|
|
if err != nil {
|
|
|
|
panic(fmt.Sprintln("Could not initialize stdout exporter:", err))
|
|
|
|
}
|
|
|
|
defer pusher.Stop()
|
|
|
|
|
|
|
|
ctx := context.Background()
|
|
|
|
|
2020-05-14 01:21:23 +02:00
|
|
|
key := kv.Key("key")
|
2019-11-26 19:54:05 +02:00
|
|
|
meter := pusher.Meter("example")
|
2019-11-15 23:01:20 +02:00
|
|
|
|
2020-04-15 01:07:11 +02:00
|
|
|
counter := metric.Must(meter).NewInt64Counter("a.counter")
|
2019-11-15 23:01:20 +02:00
|
|
|
|
2020-03-27 23:06:48 +02:00
|
|
|
counter.Add(ctx, 100, key.String("value"))
|
2019-11-15 23:01:20 +02:00
|
|
|
|
|
|
|
// Output:
|
|
|
|
// {
|
|
|
|
// "updates": [
|
|
|
|
// {
|
|
|
|
// "name": "a.counter{key=value}",
|
|
|
|
// "sum": 100
|
|
|
|
// }
|
|
|
|
// ]
|
|
|
|
// }
|
|
|
|
}
|