2020-03-23 22:41:10 -07:00
|
|
|
// Copyright The OpenTelemetry Authors
|
|
|
|
//
|
|
|
|
// 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.
|
|
|
|
|
2020-01-02 19:41:21 +01:00
|
|
|
package stdout_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"log"
|
|
|
|
|
2020-05-14 07:06:03 +08:00
|
|
|
"go.opentelemetry.io/otel/api/kv"
|
2020-01-02 19:41:21 +01:00
|
|
|
"go.opentelemetry.io/otel/api/metric"
|
2020-03-02 13:54:57 -08:00
|
|
|
"go.opentelemetry.io/otel/exporters/metric/stdout"
|
2020-01-02 19:41:21 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
func ExampleNewExportPipeline() {
|
|
|
|
// Create a meter
|
2020-01-03 12:48:45 -05:00
|
|
|
pusher, err := stdout.NewExportPipeline(stdout.Config{
|
2020-01-02 19:41:21 +01:00
|
|
|
PrettyPrint: true,
|
|
|
|
DoNotPrintTime: true,
|
2020-05-18 18:37:41 -07:00
|
|
|
})
|
2020-01-02 19:41:21 +01:00
|
|
|
if err != nil {
|
|
|
|
log.Fatal("Could not initialize stdout exporter:", err)
|
|
|
|
}
|
|
|
|
defer pusher.Stop()
|
|
|
|
|
|
|
|
ctx := context.Background()
|
|
|
|
|
2020-05-13 16:21:23 -07:00
|
|
|
key := kv.Key("key")
|
2020-06-12 09:11:17 -07:00
|
|
|
meter := pusher.Provider().Meter(
|
|
|
|
"github.com/instrumentron",
|
|
|
|
metric.WithInstrumentationVersion("v0.1.0"),
|
|
|
|
)
|
2020-01-02 19:41:21 +01:00
|
|
|
|
|
|
|
// Create and update a single counter:
|
2020-04-14 16:07:11 -07:00
|
|
|
counter := metric.Must(meter).NewInt64Counter("a.counter")
|
2020-05-14 07:06:03 +08:00
|
|
|
labels := []kv.KeyValue{key.String("value")}
|
2020-01-02 19:41:21 +01:00
|
|
|
|
2020-03-27 14:06:48 -07:00
|
|
|
counter.Add(ctx, 100, labels...)
|
2020-01-02 19:41:21 +01:00
|
|
|
|
|
|
|
// Output:
|
|
|
|
// {
|
|
|
|
// "updates": [
|
|
|
|
// {
|
2020-06-12 09:11:17 -07:00
|
|
|
// "name": "a.counter{instrumentation.name=github.com/instrumentron,instrumentation.version=v0.1.0,key=value}",
|
2020-01-02 19:41:21 +01:00
|
|
|
// "sum": 100
|
|
|
|
// }
|
|
|
|
// ]
|
|
|
|
// }
|
|
|
|
}
|