You've already forked opentelemetry-go
mirror of
https://github.com/open-telemetry/opentelemetry-go.git
synced 2025-11-25 22:41:46 +02:00
Make the stdout exporter a package (#963)
* Make the stdout exporter its own package Follow the pattern of the other exporters. * Update dependabot with stdout exporter * Add replace directives for stdout exporter * Remove outdated example test from metric SDK * go mod tidy * Update othttp example test Remove unused stdout exporter. * Remove tests in API that depend on stdout exporter The global package does not need to be validated with the SDK. A more properly constructed end-to-end integration test should be built if this is actually needed. * Add replace clause for otel in stdout go.mod
This commit is contained in:
@@ -1,55 +0,0 @@
|
||||
// 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.
|
||||
|
||||
package metric_test
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"go.opentelemetry.io/otel/api/kv"
|
||||
|
||||
"go.opentelemetry.io/otel/api/metric"
|
||||
"go.opentelemetry.io/otel/exporters/stdout"
|
||||
)
|
||||
|
||||
func ExampleNew() {
|
||||
buf := bytes.Buffer{}
|
||||
_, pusher, err := stdout.NewExportPipeline([]stdout.Option{
|
||||
// Defaults to STDOUT.
|
||||
stdout.WithWriter(&buf),
|
||||
stdout.WithPrettyPrint(),
|
||||
stdout.WithoutTimestamps(), // This makes the output deterministic
|
||||
}, nil)
|
||||
if err != nil {
|
||||
panic(fmt.Sprintln("Could not initialize stdout exporter:", err))
|
||||
}
|
||||
|
||||
meter := metric.Must(pusher.Provider().Meter("example"))
|
||||
counter := meter.NewInt64Counter("a.counter")
|
||||
counter.Add(context.Background(), 100, kv.String("key", "value"))
|
||||
|
||||
// Flush everything
|
||||
pusher.Stop()
|
||||
|
||||
fmt.Println(buf.String())
|
||||
// Output:
|
||||
// [
|
||||
// {
|
||||
// "Name": "a.counter{instrumentation.name=example,key=value}",
|
||||
// "Sum": 100
|
||||
// }
|
||||
// ]
|
||||
}
|
||||
Reference in New Issue
Block a user