1
0
mirror of https://github.com/open-telemetry/opentelemetry-go.git synced 2025-01-12 02:28:07 +02:00

Split stdout exporter into stdouttrace and stdoutmetric (#2005)

* Split stdout exporter into stdouttrace and stdoutmetric

Signed-off-by: Anthony J Mirabella <a9@aneurysm9.com>

* Remove unused options from stdouttrace and stdoutmetric exporters

Signed-off-by: Anthony J Mirabella <a9@aneurysm9.com>

* Update stdout exporter references in website docs

Signed-off-by: Anthony J Mirabella <a9@aneurysm9.com>

* Update docs to include correct import paths, properly describe exporter scope

Signed-off-by: Anthony J Mirabella <a9@aneurysm9.com>

* Remove pointless options to disable signals from what are now single-signal exporters

Signed-off-by: Anthony J Mirabella <a9@aneurysm9.com>
This commit is contained in:
Anthony Mirabella 2021-06-16 11:32:42 -04:00 committed by GitHub
parent 80ca2b1ea1
commit c30cd1d0fd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
55 changed files with 631 additions and 282 deletions

View File

@ -148,7 +148,17 @@ updates:
interval: weekly
-
package-ecosystem: gomod
directory: /exporters/stdout
directory: /exporters/stdout/stdouttrace
labels:
- dependencies
- go
- "Skip Changelog"
schedule:
day: sunday
interval: weekly
-
package-ecosystem: gomod
directory: /exporters/stdout/stdoutmetric
labels:
- dependencies
- go

View File

@ -41,7 +41,9 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
- Changes `go.opentelemetry.io/otel/sdk/resource.NewWithAttributes` to require a schema URL. The old function is still available as `resource.NewSchemaless`. This is a breaking change. (#1938)
- Several builtin resource detectors now correctly populate the schema URL. (#1938)
- Creates package `go.opentelemetry.io/otel/exporters/otlp/otlpmetric` that defines a metrics exporter that uses a `otlpmetric.Client` to send data.
Creates package `go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc` implementing a gRPC `otlpmetric.Client` and offers convenience functions, `New` and `NewUnstarted`, to create an `otlpmetric.Exporter`.(#1991)
- Creates package `go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc` implementing a gRPC `otlpmetric.Client` and offers convenience functions, `New` and `NewUnstarted`, to create an `otlpmetric.Exporter`.(#1991)
- Added `go.opentelemetry.io/otel/exporters/stdout/stdouttrace` exporter. (#2005)
- Added `go.opentelemetry.io/otel/exporters/stdout/stdoutmetric` exporter. (#2005)
### Changed
@ -109,10 +111,11 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
- The `http.url` attribute generated by `HTTPClientAttributesFromHTTPRequest` will no longer include username or password information. (#1919)
- The `IsEmpty` method of the `TraceState` type in the `go.opentelemetry.io/otel/trace` package is removed in favor of using the added `TraceState.Len` method. (#1931)
- The `Set`, `Value`, `ContextWithValue`, `ContextWithoutValue`, and `ContextWithEmpty` functions in the `go.opentelemetry.io/otel/baggage` package are removed.
Handling of baggage is now done using the added `Baggage` type and related context functions (`ContextWithBaggage`, `ContextWithoutBaggage`, and `FromContext`) in that package. (TBD)
Handling of baggage is now done using the added `Baggage` type and related context functions (`ContextWithBaggage`, `ContextWithoutBaggage`, and `FromContext`) in that package. (#1967)
- The `InstallNewPipeline` and `NewExportPipeline` creation functions in all the exporters (prometheus, otlp, stdout, jaeger, and zipkin) have been removed.
These functions were deemed premature attempts to provide convenience that did not achieve this aim. (#1985)
- The `go.opentelemetry.io/otel/exporters/otlp` exporter has been removed. Use `go.opentelemetry.io/otel/exporters/otlp/otlptrace` instead. (#1990)
- The `go.opentelemetry.io/otel/exporters/stdout` exporter has been removed. Use `go.opentelemetry.io/otel/exporters/stdout/stdouttrace` or `go.opentelemetry.io/otel/exporters/stdout/stdoutmetric` instead. (#2005)
### Fixed

View File

@ -161,7 +161,7 @@ license-check:
.PHONY: dependabot-check
dependabot-check:
@result=$$( \
for f in $$( find . -type f -name go.mod -exec dirname {} \; | sed 's/^.\/\?/\//' ); \
for f in $$( find . -type f -name go.mod -exec dirname {} \; | sed 's/^.//' ); \
do grep -q "directory: \+$$f" .github/dependabot.yml \
|| echo "$$f"; \
done; \

View File

@ -34,8 +34,6 @@ replace go.opentelemetry.io/otel/example/zipkin => ../../example/zipkin
replace go.opentelemetry.io/otel/exporters/prometheus => ../../exporters/prometheus
replace go.opentelemetry.io/otel/exporters/stdout => ../../exporters/stdout
replace go.opentelemetry.io/otel/exporters/jaeger => ../../exporters/jaeger
replace go.opentelemetry.io/otel/exporters/zipkin => ../../exporters/zipkin
@ -73,3 +71,7 @@ replace go.opentelemetry.io/otel/exporters/trace/zipkin => ../../exporters/trace
replace go.opentelemetry.io/otel/exporters/otlp/otlpmetric => ../../exporters/otlp/otlpmetric
replace go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc => ../../exporters/otlp/otlpmetric/otlpmetricgrpc
replace go.opentelemetry.io/otel/exporters/stdout/stdoutmetric => ../../exporters/stdout/stdoutmetric
replace go.opentelemetry.io/otel/exporters/stdout/stdouttrace => ../../exporters/stdout/stdouttrace

View File

@ -30,8 +30,6 @@ replace go.opentelemetry.io/otel/example/zipkin => ../../example/zipkin
replace go.opentelemetry.io/otel/exporters/prometheus => ../../exporters/prometheus
replace go.opentelemetry.io/otel/exporters/stdout => ../../exporters/stdout
replace go.opentelemetry.io/otel/exporters/jaeger => ../../exporters/jaeger
replace go.opentelemetry.io/otel/exporters/zipkin => ../../exporters/zipkin
@ -69,3 +67,7 @@ replace go.opentelemetry.io/otel/exporters/trace/zipkin => ../../exporters/trace
replace go.opentelemetry.io/otel/exporters/otlp/otlpmetric => ../../exporters/otlp/otlpmetric
replace go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc => ../../exporters/otlp/otlpmetric/otlpmetricgrpc
replace go.opentelemetry.io/otel/exporters/stdout/stdoutmetric => ../../exporters/stdout/stdoutmetric
replace go.opentelemetry.io/otel/exporters/stdout/stdouttrace => ../../exporters/stdout/stdouttrace

View File

@ -34,8 +34,6 @@ replace go.opentelemetry.io/otel/example/zipkin => ../zipkin
replace go.opentelemetry.io/otel/exporters/prometheus => ../../exporters/prometheus
replace go.opentelemetry.io/otel/exporters/stdout => ../../exporters/stdout
replace go.opentelemetry.io/otel/exporters/zipkin => ../../exporters/zipkin
replace go.opentelemetry.io/otel/internal/tools => ../../internal/tools
@ -69,3 +67,7 @@ replace go.opentelemetry.io/otel/exporters/trace/zipkin => ../../exporters/trace
replace go.opentelemetry.io/otel/exporters/otlp/otlpmetric => ../../exporters/otlp/otlpmetric
replace go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc => ../../exporters/otlp/otlpmetric/otlpmetricgrpc
replace go.opentelemetry.io/otel/exporters/stdout/stdoutmetric => ../../exporters/stdout/stdoutmetric
replace go.opentelemetry.io/otel/exporters/stdout/stdouttrace => ../../exporters/stdout/stdouttrace

View File

@ -4,13 +4,12 @@ go 1.15
replace (
go.opentelemetry.io/otel => ../..
go.opentelemetry.io/otel/exporters/stdout => ../../exporters/stdout
go.opentelemetry.io/otel/sdk => ../../sdk
)
require (
go.opentelemetry.io/otel v0.20.0
go.opentelemetry.io/otel/exporters/stdout v0.20.0
go.opentelemetry.io/otel/exporters/stdout/stdouttrace v0.20.0
go.opentelemetry.io/otel/sdk v0.20.0
go.opentelemetry.io/otel/trace v0.20.0
)
@ -70,3 +69,7 @@ replace go.opentelemetry.io/otel/exporters/trace/zipkin => ../../exporters/trace
replace go.opentelemetry.io/otel/exporters/otlp/otlpmetric => ../../exporters/otlp/otlpmetric
replace go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc => ../../exporters/otlp/otlpmetric/otlpmetricgrpc
replace go.opentelemetry.io/otel/exporters/stdout/stdoutmetric => ../../exporters/stdout/stdoutmetric
replace go.opentelemetry.io/otel/exporters/stdout/stdouttrace => ../../exporters/stdout/stdouttrace

View File

@ -1,5 +1,3 @@
github.com/benbjohnson/clock v1.1.0 h1:Q92kusRqC1XV2MjkWETPvjJVqKetz1OzxZB7mHJLju8=
github.com/benbjohnson/clock v1.1.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA=
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/google/go-cmp v0.5.6 h1:BKbKCqvP6I+rmFHt06ZmyQtvB8xAkWdhFyr0ZUNZcxQ=

View File

@ -22,7 +22,7 @@ import (
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/baggage"
"go.opentelemetry.io/otel/example/namedtracer/foo"
"go.opentelemetry.io/otel/exporters/stdout"
"go.opentelemetry.io/otel/exporters/stdout/stdouttrace"
sdktrace "go.opentelemetry.io/otel/sdk/trace"
"go.opentelemetry.io/otel/trace"
)
@ -38,9 +38,9 @@ var tp *sdktrace.TracerProvider
// initTracer creates and registers trace provider instance.
func initTracer() {
var err error
exp, err := stdout.New(stdout.WithPrettyPrint())
exp, err := stdouttrace.New(stdouttrace.WithPrettyPrint())
if err != nil {
log.Panicf("failed to initialize stdout exporter %v\n", err)
log.Panicf("failed to initialize stdouttrace exporter %v\n", err)
return
}
bsp := sdktrace.NewBatchSpanProcessor(exp)

View File

@ -5,7 +5,6 @@ go 1.15
replace (
go.opentelemetry.io/otel => ../..
go.opentelemetry.io/otel/bridge/opencensus => ../../bridge/opencensus
go.opentelemetry.io/otel/exporters/stdout => ../../exporters/stdout
go.opentelemetry.io/otel/sdk => ../../sdk
)
@ -13,7 +12,8 @@ require (
go.opencensus.io v0.22.6-0.20201102222123-380f4078db9f
go.opentelemetry.io/otel v0.20.0
go.opentelemetry.io/otel/bridge/opencensus v0.20.0
go.opentelemetry.io/otel/exporters/stdout v0.20.0
go.opentelemetry.io/otel/exporters/stdout/stdoutmetric v0.20.0
go.opentelemetry.io/otel/exporters/stdout/stdouttrace v0.20.0
go.opentelemetry.io/otel/sdk v0.20.0
go.opentelemetry.io/otel/sdk/export/metric v0.20.0
)
@ -71,3 +71,7 @@ replace go.opentelemetry.io/otel/exporters/trace/zipkin => ../../exporters/trace
replace go.opentelemetry.io/otel/exporters/otlp/otlpmetric => ../../exporters/otlp/otlpmetric
replace go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc => ../../exporters/otlp/otlpmetric/otlpmetricgrpc
replace go.opentelemetry.io/otel/exporters/stdout/stdoutmetric => ../../exporters/stdout/stdoutmetric
replace go.opentelemetry.io/otel/exporters/stdout/stdouttrace => ../../exporters/stdout/stdouttrace

View File

@ -16,6 +16,7 @@ package main
import (
"context"
"fmt"
"log"
"time"
@ -31,7 +32,8 @@ import (
"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/bridge/opencensus"
"go.opentelemetry.io/otel/exporters/stdout"
"go.opentelemetry.io/otel/exporters/stdout/stdoutmetric"
"go.opentelemetry.io/otel/exporters/stdout/stdouttrace"
otmetricexport "go.opentelemetry.io/otel/sdk/export/metric"
sdktrace "go.opentelemetry.io/otel/sdk/trace"
)
@ -51,13 +53,17 @@ var (
)
func main() {
log.Println("Using OpenTelemetry stdout exporter.")
otExporter, err := stdout.New(stdout.WithPrettyPrint())
log.Println("Using OpenTelemetry stdout exporters.")
traceExporter, err := stdouttrace.New(stdouttrace.WithPrettyPrint())
if err != nil {
log.Fatal(err)
log.Fatal(fmt.Errorf("error creating trace exporter: %w", err))
}
tracing(otExporter)
monitoring(otExporter)
metricsExporter, err := stdoutmetric.New(stdoutmetric.WithPrettyPrint())
if err != nil {
log.Fatal(fmt.Errorf("error creating metric exporter: %w", err))
}
tracing(traceExporter)
monitoring(metricsExporter)
}
// tracing demonstrates overriding the OpenCensus DefaultTracer to send spans
@ -75,7 +81,7 @@ func tracing(otExporter sdktrace.SpanExporter) {
tracer := tp.Tracer("simple")
octrace.DefaultTracer = opencensus.NewTracer(tracer)
log.Println("Creating OpenCensus span, which should be printed out using the OpenTelemetry stdout exporter.\n-- It should have no parent, since it is the first span.")
log.Println("Creating OpenCensus span, which should be printed out using the OpenTelemetry stdouttrace exporter.\n-- It should have no parent, since it is the first span.")
ctx, outerOCSpan := octrace.StartSpan(ctx, "OpenCensusOuterSpan")
outerOCSpan.End()
@ -83,7 +89,7 @@ func tracing(otExporter sdktrace.SpanExporter) {
ctx, otspan := tracer.Start(ctx, "OpenTelemetrySpan")
otspan.End()
log.Println("Creating OpenCensus span, which should be printed out using the OpenTelemetry stdout exporter.\n-- It should have the OpenTelemetry span as a parent, since it was written using OpenTelemetry APIs")
log.Println("Creating OpenCensus span, which should be printed out using the OpenTelemetry stdouttrace exporter.\n-- It should have the OpenTelemetry span as a parent, since it was written using OpenTelemetry APIs")
_, innerOCSpan := octrace.StartSpan(ctx, "OpenCensusInnerSpan")
innerOCSpan.End()
}
@ -92,14 +98,14 @@ func tracing(otExporter sdktrace.SpanExporter) {
// exporter to send metrics to the exporter by using either an OpenCensus
// registry or an OpenCensus view.
func monitoring(otExporter otmetricexport.Exporter) {
log.Println("Using the OpenTelemetry stdout exporter to export OpenCensus metrics. This allows routing telemetry from both OpenTelemetry and OpenCensus to a single exporter.")
log.Println("Using the OpenTelemetry stdoutmetric exporter to export OpenCensus metrics. This allows routing telemetry from both OpenTelemetry and OpenCensus to a single exporter.")
ocExporter := opencensus.NewMetricExporter(otExporter)
intervalReader, err := metricexport.NewIntervalReader(&metricexport.Reader{}, ocExporter)
if err != nil {
log.Fatalf("Failed to create interval reader: %v\n", err)
}
intervalReader.ReportingInterval = 10 * time.Second
log.Println("Emitting metrics using OpenCensus APIs. These should be printed out using the OpenTelemetry stdout exporter.")
log.Println("Emitting metrics using OpenCensus APIs. These should be printed out using the OpenTelemetry stdoutmetric exporter.")
err = intervalReader.Start()
if err != nil {
log.Fatalf("Failed to start interval reader: %v\n", err)

View File

@ -35,8 +35,6 @@ replace go.opentelemetry.io/otel/example/zipkin => ../zipkin
replace go.opentelemetry.io/otel/exporters/prometheus => ../../exporters/prometheus
replace go.opentelemetry.io/otel/exporters/stdout => ../../exporters/stdout
replace go.opentelemetry.io/otel/exporters/jaeger => ../../exporters/jaeger
replace go.opentelemetry.io/otel/exporters/zipkin => ../../exporters/zipkin
@ -72,3 +70,7 @@ replace go.opentelemetry.io/otel/exporters/trace/zipkin => ../../exporters/trace
replace go.opentelemetry.io/otel/exporters/otlp/otlpmetric => ../../exporters/otlp/otlpmetric
replace go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc => ../../exporters/otlp/otlpmetric/otlpmetricgrpc
replace go.opentelemetry.io/otel/exporters/stdout/stdoutmetric => ../../exporters/stdout/stdoutmetric
replace go.opentelemetry.io/otel/exporters/stdout/stdouttrace => ../../exporters/stdout/stdouttrace

View File

@ -4,14 +4,13 @@ go 1.15
require (
go.opentelemetry.io/otel v0.20.0
go.opentelemetry.io/otel/exporters/stdout v0.20.0
go.opentelemetry.io/otel/exporters/stdout/stdouttrace v0.20.0
go.opentelemetry.io/otel/sdk v0.20.0
go.opentelemetry.io/otel/trace v0.20.0
)
replace (
go.opentelemetry.io/otel => ../..
go.opentelemetry.io/otel/exporters/stdout => ../../exporters/stdout
go.opentelemetry.io/otel/sdk => ../../sdk
go.opentelemetry.io/otel/trace => ../../trace
)
@ -71,3 +70,7 @@ replace go.opentelemetry.io/otel/exporters/trace/zipkin => ../../exporters/trace
replace go.opentelemetry.io/otel/exporters/otlp/otlpmetric => ../../exporters/otlp/otlpmetric
replace go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc => ../../exporters/otlp/otlpmetric/otlpmetricgrpc
replace go.opentelemetry.io/otel/exporters/stdout/stdoutmetric => ../../exporters/stdout/stdoutmetric
replace go.opentelemetry.io/otel/exporters/stdout/stdouttrace => ../../exporters/stdout/stdouttrace

View File

@ -1,5 +1,3 @@
github.com/benbjohnson/clock v1.1.0 h1:Q92kusRqC1XV2MjkWETPvjJVqKetz1OzxZB7mHJLju8=
github.com/benbjohnson/clock v1.1.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA=
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/google/go-cmp v0.5.6 h1:BKbKCqvP6I+rmFHt06ZmyQtvB8xAkWdhFyr0ZUNZcxQ=

View File

@ -22,7 +22,7 @@ import (
"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/example/passthrough/handler"
"go.opentelemetry.io/otel/exporters/stdout"
"go.opentelemetry.io/otel/exporters/stdout/stdouttrace"
"go.opentelemetry.io/otel/propagation"
sdktrace "go.opentelemetry.io/otel/sdk/trace"
"go.opentelemetry.io/otel/trace"
@ -76,9 +76,9 @@ func initPassthroughGlobals() {
// set it as the global tracer provider
func nonGlobalTracer() *sdktrace.TracerProvider {
var err error
exp, err := stdout.New(stdout.WithPrettyPrint())
exp, err := stdouttrace.New(stdouttrace.WithPrettyPrint())
if err != nil {
log.Panicf("failed to initialize stdout exporter %v\n", err)
log.Panicf("failed to initialize stdouttrace exporter %v\n", err)
}
bsp := sdktrace.NewBatchSpanProcessor(exp)
tp := sdktrace.NewTracerProvider(

View File

@ -34,8 +34,6 @@ replace go.opentelemetry.io/otel/example/prometheus => ./
replace go.opentelemetry.io/otel/example/zipkin => ../zipkin
replace go.opentelemetry.io/otel/exporters/stdout => ../../exporters/stdout
replace go.opentelemetry.io/otel/exporters/jaeger => ../../exporters/jaeger
replace go.opentelemetry.io/otel/exporters/zipkin => ../../exporters/zipkin
@ -71,3 +69,7 @@ replace go.opentelemetry.io/otel/exporters/trace/zipkin => ../../exporters/trace
replace go.opentelemetry.io/otel/exporters/otlp/otlpmetric => ../../exporters/otlp/otlpmetric
replace go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc => ../../exporters/otlp/otlpmetric/otlpmetricgrpc
replace go.opentelemetry.io/otel/exporters/stdout/stdoutmetric => ../../exporters/stdout/stdoutmetric
replace go.opentelemetry.io/otel/exporters/stdout/stdouttrace => ../../exporters/stdout/stdouttrace

View File

@ -35,8 +35,6 @@ replace go.opentelemetry.io/otel/example/zipkin => ./
replace go.opentelemetry.io/otel/exporters/prometheus => ../../exporters/prometheus
replace go.opentelemetry.io/otel/exporters/stdout => ../../exporters/stdout
replace go.opentelemetry.io/otel/exporters/jaeger => ../../exporters/jaeger
replace go.opentelemetry.io/otel/internal/tools => ../../internal/tools
@ -70,3 +68,7 @@ replace go.opentelemetry.io/otel/exporters/trace/zipkin => ../../exporters/trace
replace go.opentelemetry.io/otel/exporters/otlp/otlpmetric => ../../exporters/otlp/otlpmetric
replace go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc => ../../exporters/otlp/otlpmetric/otlpmetricgrpc
replace go.opentelemetry.io/otel/exporters/stdout/stdoutmetric => ../../exporters/stdout/stdoutmetric
replace go.opentelemetry.io/otel/exporters/stdout/stdouttrace => ../../exporters/stdout/stdouttrace

View File

@ -32,8 +32,6 @@ replace go.opentelemetry.io/otel/exporters/prometheus => ../prometheus
replace go.opentelemetry.io/otel/exporters/otlp => ../otlp
replace go.opentelemetry.io/otel/exporters/stdout => ../stdout
replace go.opentelemetry.io/otel/exporters/jaeger => ./
replace go.opentelemetry.io/otel/internal/tools => ../../internal/tools
@ -73,3 +71,7 @@ replace go.opentelemetry.io/otel/exporters/trace/zipkin => ../trace/zipkin
replace go.opentelemetry.io/otel/exporters/otlp/otlpmetric => ../otlp/otlpmetric
replace go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc => ../otlp/otlpmetric/otlpmetricgrpc
replace go.opentelemetry.io/otel/exporters/stdout/stdoutmetric => ../stdout/stdoutmetric
replace go.opentelemetry.io/otel/exporters/stdout/stdouttrace => ../stdout/stdouttrace

View File

@ -37,8 +37,6 @@ replace go.opentelemetry.io/otel/example/zipkin => ../../../example/zipkin
replace go.opentelemetry.io/otel/exporters/metric/prometheus => ./
replace go.opentelemetry.io/otel/exporters/stdout => ../../stdout
replace go.opentelemetry.io/otel/exporters/trace/jaeger => ../../trace/jaeger
replace go.opentelemetry.io/otel/exporters/trace/zipkin => ../../trace/zipkin
@ -74,3 +72,7 @@ replace go.opentelemetry.io/otel/exporters/zipkin => ../../zipkin
replace go.opentelemetry.io/otel/exporters/otlp/otlpmetric => ../../otlp/otlpmetric
replace go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc => ../../otlp/otlpmetric/otlpmetricgrpc
replace go.opentelemetry.io/otel/exporters/stdout/stdoutmetric => ../../stdout/stdoutmetric
replace go.opentelemetry.io/otel/exporters/stdout/stdouttrace => ../../stdout/stdouttrace

View File

@ -64,8 +64,6 @@ replace go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc => ../ot
replace go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp => ../otlptrace/otlptracehttp
replace go.opentelemetry.io/otel/exporters/stdout => ../../stdout
replace go.opentelemetry.io/otel/exporters/trace/jaeger => ../../trace/jaeger
replace go.opentelemetry.io/otel/exporters/trace/zipkin => ../../trace/zipkin
@ -79,3 +77,7 @@ replace go.opentelemetry.io/otel/exporters/jaeger => ../../jaeger
replace go.opentelemetry.io/otel/exporters/prometheus => ../../prometheus
replace go.opentelemetry.io/otel/exporters/zipkin => ../../zipkin
replace go.opentelemetry.io/otel/exporters/stdout/stdoutmetric => ../../stdout/stdoutmetric
replace go.opentelemetry.io/otel/exporters/stdout/stdouttrace => ../../stdout/stdouttrace

View File

@ -60,8 +60,6 @@ replace go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc => ../..
replace go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp => ../../otlptrace/otlptracehttp
replace go.opentelemetry.io/otel/exporters/stdout => ../../../stdout
replace go.opentelemetry.io/otel/exporters/trace/jaeger => ../../../trace/jaeger
replace go.opentelemetry.io/otel/exporters/trace/zipkin => ../../../trace/zipkin
@ -77,3 +75,7 @@ replace go.opentelemetry.io/otel/exporters/jaeger => ../../../jaeger
replace go.opentelemetry.io/otel/exporters/prometheus => ../../../prometheus
replace go.opentelemetry.io/otel/exporters/zipkin => ../../../zipkin
replace go.opentelemetry.io/otel/exporters/stdout/stdoutmetric => ../../../stdout/stdoutmetric
replace go.opentelemetry.io/otel/exporters/stdout/stdouttrace => ../../../stdout/stdouttrace

View File

@ -50,8 +50,6 @@ replace go.opentelemetry.io/otel/exporters/otlp/otlptrace => ./
replace go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc => ./otlptracegrpc
replace go.opentelemetry.io/otel/exporters/stdout => ../../stdout
replace go.opentelemetry.io/otel/exporters/jaeger => ../../jaeger
replace go.opentelemetry.io/otel/exporters/zipkin => ../../zipkin
@ -77,3 +75,7 @@ replace go.opentelemetry.io/otel/exporters/trace/zipkin => ../../trace/zipkin
replace go.opentelemetry.io/otel/exporters/otlp/otlpmetric => ../otlpmetric
replace go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc => ../otlpmetric/otlpmetricgrpc
replace go.opentelemetry.io/otel/exporters/stdout/stdoutmetric => ../../stdout/stdoutmetric
replace go.opentelemetry.io/otel/exporters/stdout/stdouttrace => ../../stdout/stdouttrace

View File

@ -47,8 +47,6 @@ replace go.opentelemetry.io/otel/exporters/prometheus => ../../../prometheus
replace go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc => ./
replace go.opentelemetry.io/otel/exporters/stdout => ../../../stdout
replace go.opentelemetry.io/otel/exporters/jaeger => ../../../jaeger
replace go.opentelemetry.io/otel/exporters/zipkin => ../../../zipkin
@ -74,3 +72,7 @@ replace go.opentelemetry.io/otel/exporters/trace/zipkin => ../../../trace/zipkin
replace go.opentelemetry.io/otel/exporters/otlp/otlpmetric => ../../otlpmetric
replace go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc => ../../otlpmetric/otlpmetricgrpc
replace go.opentelemetry.io/otel/exporters/stdout/stdoutmetric => ../../../stdout/stdoutmetric
replace go.opentelemetry.io/otel/exporters/stdout/stdouttrace => ../../../stdout/stdouttrace

View File

@ -40,8 +40,6 @@ replace go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc => ../ot
replace go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp => ./
replace go.opentelemetry.io/otel/exporters/stdout => ../../../stdout
replace go.opentelemetry.io/otel/exporters/jaeger => ../../../jaeger
replace go.opentelemetry.io/otel/exporters/zipkin => ../../../zipkin
@ -71,3 +69,7 @@ replace go.opentelemetry.io/otel/exporters/trace/zipkin => ../../../trace/zipkin
replace go.opentelemetry.io/otel/exporters/otlp/otlpmetric => ../../otlpmetric
replace go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc => ../../otlpmetric/otlpmetricgrpc
replace go.opentelemetry.io/otel/exporters/stdout/stdoutmetric => ../../../stdout/stdoutmetric
replace go.opentelemetry.io/otel/exporters/stdout/stdouttrace => ../../../stdout/stdouttrace

View File

@ -44,8 +44,6 @@ replace go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp => ../ot
replace go.opentelemetry.io/otel/exporters/prometheus => ./
replace go.opentelemetry.io/otel/exporters/stdout => ../stdout
replace go.opentelemetry.io/otel/exporters/jaeger => ../jaeger
replace go.opentelemetry.io/otel/exporters/zipkin => ../zipkin
@ -75,3 +73,7 @@ replace go.opentelemetry.io/otel/exporters/trace/zipkin => ../trace/zipkin
replace go.opentelemetry.io/otel/exporters/otlp/otlpmetric => ../otlp/otlpmetric
replace go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc => ../otlp/otlpmetric/otlpmetricgrpc
replace go.opentelemetry.io/otel/exporters/stdout/stdoutmetric => ../stdout/stdoutmetric
replace go.opentelemetry.io/otel/exporters/stdout/stdouttrace => ../stdout/stdouttrace

View File

@ -1,77 +0,0 @@
module go.opentelemetry.io/otel/exporters/stdout
go 1.15
replace (
go.opentelemetry.io/otel => ../..
go.opentelemetry.io/otel/sdk => ../../sdk
)
require (
github.com/stretchr/testify v1.7.0
go.opentelemetry.io/otel v0.20.0
go.opentelemetry.io/otel/metric v0.20.0
go.opentelemetry.io/otel/oteltest v0.20.0
go.opentelemetry.io/otel/sdk v0.20.0
go.opentelemetry.io/otel/sdk/export/metric v0.20.0
go.opentelemetry.io/otel/sdk/metric v0.20.0
go.opentelemetry.io/otel/trace v0.20.0
)
replace go.opentelemetry.io/otel/bridge/opencensus => ../../bridge/opencensus
replace go.opentelemetry.io/otel/bridge/opentracing => ../../bridge/opentracing
replace go.opentelemetry.io/otel/example/jaeger => ../../example/jaeger
replace go.opentelemetry.io/otel/example/namedtracer => ../../example/namedtracer
replace go.opentelemetry.io/otel/example/opencensus => ../../example/opencensus
replace go.opentelemetry.io/otel/example/otel-collector => ../../example/otel-collector
replace go.opentelemetry.io/otel/example/prom-collector => ../../example/prom-collector
replace go.opentelemetry.io/otel/example/prometheus => ../../example/prometheus
replace go.opentelemetry.io/otel/example/zipkin => ../../example/zipkin
replace go.opentelemetry.io/otel/exporters/prometheus => ../prometheus
replace go.opentelemetry.io/otel/exporters/stdout => ./
replace go.opentelemetry.io/otel/exporters/jaeger => ../jaeger
replace go.opentelemetry.io/otel/exporters/zipkin => ../zipkin
replace go.opentelemetry.io/otel/internal/tools => ../../internal/tools
replace go.opentelemetry.io/otel/metric => ../../metric
replace go.opentelemetry.io/otel/oteltest => ../../oteltest
replace go.opentelemetry.io/otel/sdk/export/metric => ../../sdk/export/metric
replace go.opentelemetry.io/otel/sdk/metric => ../../sdk/metric
replace go.opentelemetry.io/otel/trace => ../../trace
replace go.opentelemetry.io/otel/example/passthrough => ../../example/passthrough
replace go.opentelemetry.io/otel/exporters/otlp/otlptrace => ../otlp/otlptrace
replace go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc => ../otlp/otlptrace/otlptracegrpc
replace go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp => ../otlp/otlptrace/otlptracehttp
replace go.opentelemetry.io/otel/internal/metric => ../../internal/metric
replace go.opentelemetry.io/otel/exporters/metric/prometheus => ../metric/prometheus
replace go.opentelemetry.io/otel/exporters/trace/jaeger => ../trace/jaeger
replace go.opentelemetry.io/otel/exporters/trace/zipkin => ../trace/zipkin
replace go.opentelemetry.io/otel/exporters/otlp/otlpmetric => ../otlp/otlpmetric
replace go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc => ../otlp/otlpmetric/otlpmetricgrpc

View File

@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
package stdout // import "go.opentelemetry.io/otel/exporters/stdout"
package stdoutmetric // import "go.opentelemetry.io/otel/exporters/stdout/stdoutmetric"
import (
"io"
@ -22,12 +22,10 @@ import (
)
var (
defaultWriter = os.Stdout
defaultPrettyPrint = false
defaultTimestamps = true
defaultLabelEncoder = attribute.DefaultEncoder()
defaultDisableTraceExport = false
defaultDisableMetricExport = false
defaultWriter = os.Stdout
defaultPrettyPrint = false
defaultTimestamps = true
defaultLabelEncoder = attribute.DefaultEncoder()
)
// config contains options for the STDOUT exporter.
@ -39,29 +37,21 @@ type config struct {
// false.
PrettyPrint bool
// Timestamps specifies if timestamps should be pritted. Default is
// Timestamps specifies if timestamps should be printed. Default is
// true.
Timestamps bool
// LabelEncoder encodes the labels.
LabelEncoder attribute.Encoder
// DisableTraceExport prevents any export of trace telemetry.
DisableTraceExport bool
// DisableMetricExport prevents any export of metric telemetry.
DisableMetricExport bool
}
// newConfig creates a validated Config configured with options.
func newConfig(options ...Option) (config, error) {
cfg := config{
Writer: defaultWriter,
PrettyPrint: defaultPrettyPrint,
Timestamps: defaultTimestamps,
LabelEncoder: defaultLabelEncoder,
DisableTraceExport: defaultDisableTraceExport,
DisableMetricExport: defaultDisableMetricExport,
Writer: defaultWriter,
PrettyPrint: defaultPrettyPrint,
Timestamps: defaultTimestamps,
LabelEncoder: defaultLabelEncoder,
}
for _, opt := range options {
opt.apply(&cfg)
@ -122,25 +112,3 @@ type labelEncoderOption struct {
func (o labelEncoderOption) apply(cfg *config) {
cfg.LabelEncoder = o.LabelEncoder
}
// WithoutTraceExport disables all trace exporting.
func WithoutTraceExport() Option {
return disableTraceExportOption(true)
}
type disableTraceExportOption bool
func (o disableTraceExportOption) apply(cfg *config) {
cfg.DisableTraceExport = bool(o)
}
// WithoutMetricExport disables all metric exporting.
func WithoutMetricExport() Option {
return disableMetricExportOption(true)
}
type disableMetricExportOption bool
func (o disableMetricExportOption) apply(cfg *config) {
cfg.DisableMetricExport = bool(o)
}

View File

@ -0,0 +1,21 @@
// 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 stdout contains an OpenTelemetry exporter for metric telemetry
// to be written to an output destination as JSON.
//
// This package is currently in a pre-GA phase. Backwards incompatible changes
// may be introduced in subsequent minor version releases as we work to track
// the evolving OpenTelemetry specification and user feedback.
package stdoutmetric // import "go.opentelemetry.io/otel/exporters/stdout/stdoutmetric"

View File

@ -12,24 +12,20 @@
// See the License for the specific language governing permissions and
// limitations under the License.
package stdout_test
package stdoutmetric_test
import (
"context"
"log"
"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/exporters/stdout/stdoutmetric"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/exporters/stdout"
"go.opentelemetry.io/otel/metric"
"go.opentelemetry.io/otel/metric/global"
controller "go.opentelemetry.io/otel/sdk/metric/controller/basic"
processor "go.opentelemetry.io/otel/sdk/metric/processor/basic"
"go.opentelemetry.io/otel/sdk/metric/selector/simple"
"go.opentelemetry.io/otel/sdk/resource"
sdktrace "go.opentelemetry.io/otel/sdk/trace"
semconv "go.opentelemetry.io/otel/semconv/v1.4.0"
"go.opentelemetry.io/otel/trace"
)
const (
@ -38,12 +34,6 @@ const (
)
var (
tracer = otel.GetTracerProvider().Tracer(
instrumentationName,
trace.WithInstrumentationVersion(instrumentationVersion),
trace.WithSchemaURL("https://opentelemetry.io/schemas/1.2.0"),
)
meter = global.GetMeterProvider().Meter(
instrumentationName,
metric.WithInstrumentationVersion(instrumentationVersion),
@ -58,10 +48,6 @@ var (
func add(ctx context.Context, x, y int64) int64 {
nameKV := nameKey.String("add")
var span trace.Span
ctx, span = tracer.Start(ctx, "Addition")
defer span.End()
loopCounter.Add(ctx, 1, nameKV)
paramValue.Record(ctx, x, nameKV)
paramValue.Record(ctx, y, nameKV)
@ -72,10 +58,6 @@ func add(ctx context.Context, x, y int64) int64 {
func multiply(ctx context.Context, x, y int64) int64 {
nameKV := nameKey.String("multiply")
var span trace.Span
ctx, span = tracer.Start(ctx, "Multiplication")
defer span.End()
loopCounter.Add(ctx, 1, nameKV)
paramValue.Record(ctx, x, nameKV)
paramValue.Record(ctx, y, nameKV)
@ -83,26 +65,12 @@ func multiply(ctx context.Context, x, y int64) int64 {
return x * y
}
func Resource() *resource.Resource {
return resource.NewWithAttributes(
semconv.SchemaURL,
semconv.ServiceNameKey.String("stdout-example"),
semconv.ServiceVersionKey.String("0.0.1"),
)
}
func InstallExportPipeline(ctx context.Context) func() {
exporter, err := stdout.New(stdout.WithPrettyPrint())
exporter, err := stdoutmetric.New(stdoutmetric.WithPrettyPrint())
if err != nil {
log.Fatalf("creating stdout exporter: %v", err)
log.Fatalf("creating stdoutmetric exporter: %v", err)
}
tracerProvider := sdktrace.NewTracerProvider(
sdktrace.WithBatcher(exporter),
sdktrace.WithResource(Resource()),
)
otel.SetTracerProvider(tracerProvider)
pusher := controller.New(
processor.New(
simple.NewWithInexpensiveDistribution(),
@ -119,16 +87,13 @@ func InstallExportPipeline(ctx context.Context) func() {
if err := pusher.Stop(ctx); err != nil {
log.Fatalf("stopping push controller: %v", err)
}
if err := tracerProvider.Shutdown(ctx); err != nil {
log.Fatalf("stopping tracer provider: %v", err)
}
}
}
func Example() {
ctx := context.Background()
// Registers both a tracer and meter Provider globally.
// Registers a meter Provider globally.
cleanup := InstallExportPipeline(ctx)
defer cleanup()

View File

@ -12,21 +12,18 @@
// See the License for the specific language governing permissions and
// limitations under the License.
package stdout // import "go.opentelemetry.io/otel/exporters/stdout"
package stdoutmetric // import "go.opentelemetry.io/otel/exporters/stdout/stdoutmetric"
import (
"go.opentelemetry.io/otel/sdk/export/metric"
sdktrace "go.opentelemetry.io/otel/sdk/trace"
)
type Exporter struct {
traceExporter
metricExporter
}
var (
_ metric.Exporter = &Exporter{}
_ sdktrace.SpanExporter = &Exporter{}
_ metric.Exporter = &Exporter{}
)
// New creates an Exporter with the passed options.
@ -36,7 +33,6 @@ func New(options ...Option) (*Exporter, error) {
return nil, err
}
return &Exporter{
traceExporter: traceExporter{config: cfg},
metricExporter: metricExporter{cfg},
}, nil
}

View File

@ -0,0 +1,77 @@
module go.opentelemetry.io/otel/exporters/stdout/stdoutmetric
go 1.15
replace (
go.opentelemetry.io/otel => ../../..
go.opentelemetry.io/otel/sdk => ../../../sdk
)
require (
github.com/stretchr/testify v1.7.0
go.opentelemetry.io/otel v0.20.0
go.opentelemetry.io/otel/metric v0.20.0
go.opentelemetry.io/otel/sdk v0.20.0
go.opentelemetry.io/otel/sdk/export/metric v0.20.0
go.opentelemetry.io/otel/sdk/metric v0.20.0
)
replace go.opentelemetry.io/otel/bridge/opencensus => ../../../bridge/opencensus
replace go.opentelemetry.io/otel/bridge/opentracing => ../../../bridge/opentracing
replace go.opentelemetry.io/otel/example/jaeger => ../../../example/jaeger
replace go.opentelemetry.io/otel/example/namedtracer => ../../../example/namedtracer
replace go.opentelemetry.io/otel/example/opencensus => ../../../example/opencensus
replace go.opentelemetry.io/otel/example/otel-collector => ../../../example/otel-collector
replace go.opentelemetry.io/otel/example/prom-collector => ../../example/prom-collector
replace go.opentelemetry.io/otel/example/prometheus => ../../../example/prometheus
replace go.opentelemetry.io/otel/example/zipkin => ../../../example/zipkin
replace go.opentelemetry.io/otel/exporters/prometheus => ../../prometheus
replace go.opentelemetry.io/otel/exporters/stdout/stdoutmetric => ./
replace go.opentelemetry.io/otel/exporters/jaeger => ../../jaeger
replace go.opentelemetry.io/otel/exporters/zipkin => ../../zipkin
replace go.opentelemetry.io/otel/internal/tools => ../../../internal/tools
replace go.opentelemetry.io/otel/metric => ../../../metric
replace go.opentelemetry.io/otel/oteltest => ../../../oteltest
replace go.opentelemetry.io/otel/sdk/export/metric => ../../../sdk/export/metric
replace go.opentelemetry.io/otel/sdk/metric => ../../../sdk/metric
replace go.opentelemetry.io/otel/trace => ../../../trace
replace go.opentelemetry.io/otel/example/passthrough => ../../../example/passthrough
replace go.opentelemetry.io/otel/exporters/otlp/otlptrace => ../../otlp/otlptrace
replace go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc => ../../otlp/otlptrace/otlptracegrpc
replace go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp => ../../otlp/otlptrace/otlptracehttp
replace go.opentelemetry.io/otel/internal/metric => ../../../internal/metric
replace go.opentelemetry.io/otel/exporters/metric/prometheus => ../../metric/prometheus
replace go.opentelemetry.io/otel/exporters/trace/jaeger => ../../trace/jaeger
replace go.opentelemetry.io/otel/exporters/trace/zipkin => ../../trace/zipkin
replace go.opentelemetry.io/otel/exporters/otlp/otlpmetric => ../../otlp/otlpmetric
replace go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc => ../../otlp/otlpmetric/otlpmetricgrpc
replace go.opentelemetry.io/otel/exporters/stdout/stdouttrace => ../stdouttrace

View File

@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
package stdout // import "go.opentelemetry.io/otel/exporters/stdout"
package stdoutmetric // import "go.opentelemetry.io/otel/exporters/stdout/stdoutmetric"
import (
"context"
@ -50,9 +50,6 @@ func (e *metricExporter) ExportKindFor(desc *metric.Descriptor, kind aggregation
}
func (e *metricExporter) Export(_ context.Context, checkpointSet exportmetric.CheckpointSet) error {
if e.config.DisableMetricExport {
return nil
}
var aggError error
var batch []line
aggError = checkpointSet.ForEach(e, func(record exportmetric.Record) error {
@ -153,7 +150,7 @@ func (e *metricExporter) Export(_ context.Context, checkpointSet exportmetric.Ch
return aggError
}
// marshal v with approriate indentation.
// marshal v with appropriate indentation.
func (e *metricExporter) marshal(v interface{}) ([]byte, error) {
if e.config.PrettyPrint {
return json.MarshalIndent(v, "", "\t")

View File

@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
package stdout_test
package stdoutmetric_test
import (
"bytes"
@ -23,11 +23,12 @@ import (
"testing"
"time"
"go.opentelemetry.io/otel/exporters/stdout/stdoutmetric"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/exporters/stdout"
"go.opentelemetry.io/otel/metric"
"go.opentelemetry.io/otel/metric/number"
export "go.opentelemetry.io/otel/sdk/export/metric"
@ -42,17 +43,17 @@ import (
type testFixture struct {
t *testing.T
ctx context.Context
exporter *stdout.Exporter
exporter *stdoutmetric.Exporter
output *bytes.Buffer
}
var testResource = resource.NewSchemaless(attribute.String("R", "V"))
func newFixture(t *testing.T, opts ...stdout.Option) testFixture {
func newFixture(t *testing.T, opts ...stdoutmetric.Option) testFixture {
buf := &bytes.Buffer{}
opts = append(opts, stdout.WithWriter(buf))
opts = append(opts, stdout.WithoutTimestamps())
exp, err := stdout.New(opts...)
opts = append(opts, stdoutmetric.WithWriter(buf))
opts = append(opts, stdoutmetric.WithoutTimestamps())
exp, err := stdoutmetric.New(opts...)
if err != nil {
t.Fatal("Error building fixture: ", err)
}
@ -77,8 +78,8 @@ func (fix testFixture) Export(checkpointSet export.CheckpointSet) {
func TestStdoutTimestamp(t *testing.T) {
var buf bytes.Buffer
exporter, err := stdout.New(
stdout.WithWriter(&buf),
exporter, err := stdoutmetric.New(
stdoutmetric.WithWriter(&buf),
)
if err != nil {
t.Fatal("Invalid config: ", err)
@ -185,7 +186,7 @@ func TestStdoutMinMaxSumCount(t *testing.T) {
}
func TestStdoutValueRecorderFormat(t *testing.T) {
fix := newFixture(t, stdout.WithPrettyPrint())
fix := newFixture(t, stdoutmetric.WithPrettyPrint())
checkpointSet := metrictest.NewCheckpointSet(testResource)

View File

@ -0,0 +1,94 @@
// 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 stdouttrace // import "go.opentelemetry.io/otel/exporters/stdout/stdouttrace"
import (
"io"
"os"
)
var (
defaultWriter = os.Stdout
defaultPrettyPrint = false
defaultTimestamps = true
)
// config contains options for the STDOUT exporter.
type config struct {
// Writer is the destination. If not set, os.Stdout is used.
Writer io.Writer
// PrettyPrint will encode the output into readable JSON. Default is
// false.
PrettyPrint bool
// Timestamps specifies if timestamps should be printed. Default is
// true.
Timestamps bool
}
// newConfig creates a validated Config configured with options.
func newConfig(options ...Option) (config, error) {
cfg := config{
Writer: defaultWriter,
PrettyPrint: defaultPrettyPrint,
Timestamps: defaultTimestamps,
}
for _, opt := range options {
opt.apply(&cfg)
}
return cfg, nil
}
// Option sets the value of an option for a Config.
type Option interface {
apply(*config)
}
// WithWriter sets the export stream destination.
func WithWriter(w io.Writer) Option {
return writerOption{w}
}
type writerOption struct {
W io.Writer
}
func (o writerOption) apply(cfg *config) {
cfg.Writer = o.W
}
// WithPrettyPrint sets the export stream format to use JSON.
func WithPrettyPrint() Option {
return prettyPrintOption(true)
}
type prettyPrintOption bool
func (o prettyPrintOption) apply(cfg *config) {
cfg.PrettyPrint = bool(o)
}
// WithoutTimestamps sets the export stream to not include timestamps.
func WithoutTimestamps() Option {
return timestampsOption(false)
}
type timestampsOption bool
func (o timestampsOption) apply(cfg *config) {
cfg.Timestamps = bool(o)
}

View File

@ -12,10 +12,10 @@
// See the License for the specific language governing permissions and
// limitations under the License.
// Package stdout contains an OpenTelemetry exporter for both tracing and
// metric telemetry to be written to an output destination as JSON.
// Package stdout contains an OpenTelemetry exporter for tracing
// telemetry to be written to an output destination as JSON.
//
// This package is currently in a pre-GA phase. Backwards incompatible changes
// may be introduced in subsequent minor version releases as we work to track
// the evolving OpenTelemetry specification and user feedback.
package stdout // import "go.opentelemetry.io/otel/exporters/stdout"
package stdouttrace // import "go.opentelemetry.io/otel/exporters/stdout/stdouttrace"

View File

@ -0,0 +1,93 @@
// 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 stdouttrace_test
import (
"context"
"log"
"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/exporters/stdout/stdouttrace"
"go.opentelemetry.io/otel/sdk/resource"
sdktrace "go.opentelemetry.io/otel/sdk/trace"
semconv "go.opentelemetry.io/otel/semconv/v1.4.0"
"go.opentelemetry.io/otel/trace"
)
const (
instrumentationName = "github.com/instrumentron"
instrumentationVersion = "v0.1.0"
)
var (
tracer = otel.GetTracerProvider().Tracer(
instrumentationName,
trace.WithInstrumentationVersion(instrumentationVersion),
trace.WithSchemaURL("https://opentelemetry.io/schemas/1.2.0"),
)
)
func add(ctx context.Context, x, y int64) int64 {
var span trace.Span
_, span = tracer.Start(ctx, "Addition")
defer span.End()
return x + y
}
func multiply(ctx context.Context, x, y int64) int64 {
var span trace.Span
_, span = tracer.Start(ctx, "Multiplication")
defer span.End()
return x * y
}
func Resource() *resource.Resource {
return resource.NewWithAttributes(
semconv.SchemaURL,
semconv.ServiceNameKey.String("stdout-example"),
semconv.ServiceVersionKey.String("0.0.1"),
)
}
func InstallExportPipeline(ctx context.Context) func() {
exporter, err := stdouttrace.New(stdouttrace.WithPrettyPrint())
if err != nil {
log.Fatalf("creating stdout exporter: %v", err)
}
tracerProvider := sdktrace.NewTracerProvider(
sdktrace.WithBatcher(exporter),
sdktrace.WithResource(Resource()),
)
otel.SetTracerProvider(tracerProvider)
return func() {
if err := tracerProvider.Shutdown(ctx); err != nil {
log.Fatalf("stopping tracer provider: %v", err)
}
}
}
func Example() {
ctx := context.Background()
// Registers a tracer Provider globally.
cleanup := InstallExportPipeline(ctx)
defer cleanup()
log.Println("the answer is", add(ctx, multiply(ctx, multiply(ctx, 2, 2), 10), 2))
}

View File

@ -0,0 +1,38 @@
// 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 stdouttrace // import "go.opentelemetry.io/otel/exporters/stdout/stdouttrace"
import (
sdktrace "go.opentelemetry.io/otel/sdk/trace"
)
type Exporter struct {
traceExporter
}
var (
_ sdktrace.SpanExporter = &Exporter{}
)
// New creates an Exporter with the passed options.
func New(options ...Option) (*Exporter, error) {
cfg, err := newConfig(options...)
if err != nil {
return nil, err
}
return &Exporter{
traceExporter: traceExporter{config: cfg},
}, nil
}

View File

@ -0,0 +1,76 @@
module go.opentelemetry.io/otel/exporters/stdout/stdouttrace
go 1.15
replace (
go.opentelemetry.io/otel => ../../..
go.opentelemetry.io/otel/sdk => ../../../sdk
)
require (
github.com/stretchr/testify v1.7.0
go.opentelemetry.io/otel v0.20.0
go.opentelemetry.io/otel/oteltest v0.20.0
go.opentelemetry.io/otel/sdk v0.20.0
go.opentelemetry.io/otel/trace v0.20.0
)
replace go.opentelemetry.io/otel/bridge/opencensus => ../../../bridge/opencensus
replace go.opentelemetry.io/otel/bridge/opentracing => ../../../bridge/opentracing
replace go.opentelemetry.io/otel/example/jaeger => ../../../example/jaeger
replace go.opentelemetry.io/otel/example/namedtracer => ../../../example/namedtracer
replace go.opentelemetry.io/otel/example/opencensus => ../../../example/opencensus
replace go.opentelemetry.io/otel/example/otel-collector => ../../../example/otel-collector
replace go.opentelemetry.io/otel/example/prom-collector => ../../example/prom-collector
replace go.opentelemetry.io/otel/example/prometheus => ../../../example/prometheus
replace go.opentelemetry.io/otel/example/zipkin => ../../../example/zipkin
replace go.opentelemetry.io/otel/exporters/prometheus => ../../prometheus
replace go.opentelemetry.io/otel/exporters/stdout/stdouttrace => ./
replace go.opentelemetry.io/otel/exporters/jaeger => ../../jaeger
replace go.opentelemetry.io/otel/exporters/zipkin => ../../zipkin
replace go.opentelemetry.io/otel/internal/tools => ../../../internal/tools
replace go.opentelemetry.io/otel/metric => ../../../metric
replace go.opentelemetry.io/otel/oteltest => ../../../oteltest
replace go.opentelemetry.io/otel/sdk/export/metric => ../../../sdk/export/metric
replace go.opentelemetry.io/otel/sdk/metric => ../../../sdk/metric
replace go.opentelemetry.io/otel/trace => ../../../trace
replace go.opentelemetry.io/otel/example/passthrough => ../../../example/passthrough
replace go.opentelemetry.io/otel/exporters/otlp/otlptrace => ../../otlp/otlptrace
replace go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc => ../../otlp/otlptrace/otlptracegrpc
replace go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp => ../../otlp/otlptrace/otlptracehttp
replace go.opentelemetry.io/otel/internal/metric => ../../../internal/metric
replace go.opentelemetry.io/otel/exporters/metric/prometheus => ../../metric/prometheus
replace go.opentelemetry.io/otel/exporters/trace/jaeger => ../../trace/jaeger
replace go.opentelemetry.io/otel/exporters/trace/zipkin => ../../trace/zipkin
replace go.opentelemetry.io/otel/exporters/otlp/otlpmetric => ../../otlp/otlpmetric
replace go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc => ../../otlp/otlpmetric/otlpmetricgrpc
replace go.opentelemetry.io/otel/exporters/stdout/stdoutmetric => ../stdoutmetric

View File

@ -0,0 +1,15 @@
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/google/go-cmp v0.5.6 h1:BKbKCqvP6I+rmFHt06ZmyQtvB8xAkWdhFyr0ZUNZcxQ=
github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

View File

@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
package stdout // import "go.opentelemetry.io/otel/exporters/stdout"
package stdouttrace // import "go.opentelemetry.io/otel/exporters/stdout/stdouttrace"
import (
"context"
@ -41,7 +41,7 @@ func (e *traceExporter) ExportSpans(ctx context.Context, spans []trace.ReadOnlyS
return nil
}
if e.config.DisableTraceExport || len(spans) == 0 {
if len(spans) == 0 {
return nil
}
out, err := e.marshal(tracetest.SpanStubsFromReadOnlySpans(spans))

View File

@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
package stdout_test
package stdouttrace_test
import (
"bytes"
@ -26,7 +26,7 @@ import (
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/codes"
"go.opentelemetry.io/otel/exporters/stdout"
"go.opentelemetry.io/otel/exporters/stdout/stdouttrace"
"go.opentelemetry.io/otel/oteltest"
"go.opentelemetry.io/otel/sdk/resource"
tracesdk "go.opentelemetry.io/otel/sdk/trace"
@ -37,7 +37,7 @@ import (
func TestExporter_ExportSpan(t *testing.T) {
// write to buffer for testing
var b bytes.Buffer
ex, err := stdout.New(stdout.WithWriter(&b), stdout.WithPrettyPrint())
ex, err := stdouttrace.New(stdouttrace.WithWriter(&b), stdouttrace.WithPrettyPrint())
if err != nil {
t.Errorf("Error constructing stdout exporter %s", err)
}
@ -183,7 +183,7 @@ func TestExporterShutdownHonorsTimeout(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), 1*time.Minute)
defer cancel()
e, err := stdout.New()
e, err := stdouttrace.New()
if err != nil {
t.Fatalf("failed to create exporter: %v", err)
}
@ -202,7 +202,7 @@ func TestExporterShutdownHonorsCancel(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), 1*time.Minute)
defer cancel()
e, err := stdout.New()
e, err := stdouttrace.New()
if err != nil {
t.Fatalf("failed to create exporter: %v", err)
}
@ -217,7 +217,7 @@ func TestExporterShutdownHonorsCancel(t *testing.T) {
}
func TestExporterShutdownNoError(t *testing.T) {
e, err := stdout.New()
e, err := stdouttrace.New()
if err != nil {
t.Fatalf("failed to create exporter: %v", err)
}

View File

@ -35,8 +35,6 @@ replace go.opentelemetry.io/otel/example/zipkin => ../../../example/zipkin
replace go.opentelemetry.io/otel/exporters/metric/prometheus => ../../metric/prometheus
replace go.opentelemetry.io/otel/exporters/stdout => ../../stdout
replace go.opentelemetry.io/otel/exporters/trace/jaeger => ./
replace go.opentelemetry.io/otel/exporters/trace/zipkin => ../zipkin
@ -72,3 +70,7 @@ replace go.opentelemetry.io/otel/exporters/zipkin => ../../zipkin
replace go.opentelemetry.io/otel/exporters/otlp/otlpmetric => ../../otlp/otlpmetric
replace go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc => ../../otlp/otlpmetric/otlpmetricgrpc
replace go.opentelemetry.io/otel/exporters/stdout/stdoutmetric => ../../stdout/stdoutmetric
replace go.opentelemetry.io/otel/exporters/stdout/stdouttrace => ../../stdout/stdouttrace

View File

@ -36,8 +36,6 @@ replace go.opentelemetry.io/otel/example/zipkin => ../../../example/zipkin
replace go.opentelemetry.io/otel/exporters/metric/prometheus => ../../metric/prometheus
replace go.opentelemetry.io/otel/exporters/stdout => ../../stdout
replace go.opentelemetry.io/otel/exporters/trace/jaeger => ../jaeger
replace go.opentelemetry.io/otel/exporters/trace/zipkin => ./
@ -73,3 +71,7 @@ replace go.opentelemetry.io/otel/exporters/zipkin => ../../zipkin
replace go.opentelemetry.io/otel/exporters/otlp/otlpmetric => ../../otlp/otlpmetric
replace go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc => ../../otlp/otlpmetric/otlpmetricgrpc
replace go.opentelemetry.io/otel/exporters/stdout/stdoutmetric => ../../stdout/stdoutmetric
replace go.opentelemetry.io/otel/exporters/stdout/stdouttrace => ../../stdout/stdouttrace

View File

@ -33,8 +33,6 @@ replace go.opentelemetry.io/otel/exporters/prometheus => ../prometheus
replace go.opentelemetry.io/otel/exporters/otlp => ../otlp
replace go.opentelemetry.io/otel/exporters/stdout => ../stdout
replace go.opentelemetry.io/otel/exporters/jaeger => ../jaeger
replace go.opentelemetry.io/otel/exporters/zipkin => ./
@ -74,3 +72,7 @@ replace go.opentelemetry.io/otel/exporters/trace/zipkin => ../trace/zipkin
replace go.opentelemetry.io/otel/exporters/otlp/otlpmetric => ../otlp/otlpmetric
replace go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc => ../otlp/otlpmetric/otlpmetricgrpc
replace go.opentelemetry.io/otel/exporters/stdout/stdoutmetric => ../stdout/stdoutmetric
replace go.opentelemetry.io/otel/exporters/stdout/stdouttrace => ../stdout/stdouttrace

6
go.mod
View File

@ -31,8 +31,6 @@ replace go.opentelemetry.io/otel/example/zipkin => ./example/zipkin
replace go.opentelemetry.io/otel/exporters/prometheus => ./exporters/prometheus
replace go.opentelemetry.io/otel/exporters/stdout => ./exporters/stdout
replace go.opentelemetry.io/otel/exporters/jaeger => ./exporters/jaeger
replace go.opentelemetry.io/otel/exporters/zipkin => ./exporters/zipkin
@ -70,3 +68,7 @@ replace go.opentelemetry.io/otel/exporters/trace/zipkin => ./exporters/trace/zip
replace go.opentelemetry.io/otel/exporters/otlp/otlpmetric => ./exporters/otlp/otlpmetric
replace go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc => ./exporters/otlp/otlpmetric/otlpmetricgrpc
replace go.opentelemetry.io/otel/exporters/stdout/stdoutmetric => ./exporters/stdout/stdoutmetric
replace go.opentelemetry.io/otel/exporters/stdout/stdouttrace => ./exporters/stdout/stdouttrace

View File

@ -42,8 +42,6 @@ replace go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc => ../..
replace go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp => ../../exporters/otlp/otlptrace/otlptracehttp
replace go.opentelemetry.io/otel/exporters/stdout => ../../exporters/stdout
replace go.opentelemetry.io/otel/exporters/jaeger => ../../exporters/jaeger
replace go.opentelemetry.io/otel/exporters/zipkin => ../../exporters/zipkin
@ -69,3 +67,7 @@ replace go.opentelemetry.io/otel/exporters/trace/zipkin => ../../exporters/trace
replace go.opentelemetry.io/otel/exporters/otlp/otlpmetric => ../../exporters/otlp/otlpmetric
replace go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc => ../../exporters/otlp/otlpmetric/otlpmetricgrpc
replace go.opentelemetry.io/otel/exporters/stdout/stdoutmetric => ../../exporters/stdout/stdoutmetric
replace go.opentelemetry.io/otel/exporters/stdout/stdouttrace => ../../exporters/stdout/stdouttrace

View File

@ -34,8 +34,6 @@ replace go.opentelemetry.io/otel/example/zipkin => ../../example/zipkin
replace go.opentelemetry.io/otel/exporters/prometheus => ../../exporters/prometheus
replace go.opentelemetry.io/otel/exporters/stdout => ../../exporters/stdout
replace go.opentelemetry.io/otel/exporters/jaeger => ../../exporters/jaeger
replace go.opentelemetry.io/otel/exporters/zipkin => ../../exporters/zipkin
@ -73,3 +71,7 @@ replace go.opentelemetry.io/otel/exporters/trace/zipkin => ../../exporters/trace
replace go.opentelemetry.io/otel/exporters/otlp/otlpmetric => ../../exporters/otlp/otlpmetric
replace go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc => ../../exporters/otlp/otlpmetric/otlpmetricgrpc
replace go.opentelemetry.io/otel/exporters/stdout/stdoutmetric => ../../exporters/stdout/stdoutmetric
replace go.opentelemetry.io/otel/exporters/stdout/stdouttrace => ../../exporters/stdout/stdouttrace

View File

@ -24,8 +24,6 @@ replace go.opentelemetry.io/otel/example/zipkin => ../example/zipkin
replace go.opentelemetry.io/otel/exporters/prometheus => ../exporters/prometheus
replace go.opentelemetry.io/otel/exporters/stdout => ../exporters/stdout
replace go.opentelemetry.io/otel/exporters/jaeger => ../exporters/jaeger
replace go.opentelemetry.io/otel/exporters/zipkin => ../exporters/zipkin
@ -70,3 +68,7 @@ replace go.opentelemetry.io/otel/exporters/trace/zipkin => ../exporters/trace/zi
replace go.opentelemetry.io/otel/exporters/otlp/otlpmetric => ../exporters/otlp/otlpmetric
replace go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc => ../exporters/otlp/otlpmetric/otlpmetricgrpc
replace go.opentelemetry.io/otel/exporters/stdout/stdoutmetric => ../exporters/stdout/stdoutmetric
replace go.opentelemetry.io/otel/exporters/stdout/stdouttrace => ../exporters/stdout/stdouttrace

View File

@ -24,8 +24,6 @@ replace go.opentelemetry.io/otel/example/zipkin => ../example/zipkin
replace go.opentelemetry.io/otel/exporters/prometheus => ../exporters/prometheus
replace go.opentelemetry.io/otel/exporters/stdout => ../exporters/stdout
replace go.opentelemetry.io/otel/exporters/jaeger => ../exporters/jaeger
replace go.opentelemetry.io/otel/exporters/zipkin => ../exporters/zipkin
@ -69,3 +67,7 @@ replace go.opentelemetry.io/otel/exporters/trace/zipkin => ../exporters/trace/zi
replace go.opentelemetry.io/otel/exporters/otlp/otlpmetric => ../exporters/otlp/otlpmetric
replace go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc => ../exporters/otlp/otlpmetric/otlpmetricgrpc
replace go.opentelemetry.io/otel/exporters/stdout/stdoutmetric => ../exporters/stdout/stdoutmetric
replace go.opentelemetry.io/otel/exporters/stdout/stdouttrace => ../exporters/stdout/stdouttrace

View File

@ -24,8 +24,6 @@ replace go.opentelemetry.io/otel/example/zipkin => ../../../example/zipkin
replace go.opentelemetry.io/otel/exporters/prometheus => ../../../exporters/prometheus
replace go.opentelemetry.io/otel/exporters/stdout => ../../../exporters/stdout
replace go.opentelemetry.io/otel/exporters/jaeger => ../../../exporters/jaeger
replace go.opentelemetry.io/otel/exporters/zipkin => ../../../exporters/zipkin
@ -70,3 +68,7 @@ replace go.opentelemetry.io/otel/exporters/trace/zipkin => ../../../exporters/tr
replace go.opentelemetry.io/otel/exporters/otlp/otlpmetric => ../../../exporters/otlp/otlpmetric
replace go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc => ../../../exporters/otlp/otlpmetric/otlpmetricgrpc
replace go.opentelemetry.io/otel/exporters/stdout/stdoutmetric => ../../../exporters/stdout/stdoutmetric
replace go.opentelemetry.io/otel/exporters/stdout/stdouttrace => ../../../exporters/stdout/stdouttrace

View File

@ -32,8 +32,6 @@ replace go.opentelemetry.io/otel/example/zipkin => ../example/zipkin
replace go.opentelemetry.io/otel/exporters/prometheus => ../exporters/prometheus
replace go.opentelemetry.io/otel/exporters/stdout => ../exporters/stdout
replace go.opentelemetry.io/otel/exporters/jaeger => ../exporters/jaeger
replace go.opentelemetry.io/otel/exporters/zipkin => ../exporters/zipkin
@ -71,3 +69,7 @@ replace go.opentelemetry.io/otel/exporters/trace/zipkin => ../exporters/trace/zi
replace go.opentelemetry.io/otel/exporters/otlp/otlpmetric => ../exporters/otlp/otlpmetric
replace go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc => ../exporters/otlp/otlpmetric/otlpmetricgrpc
replace go.opentelemetry.io/otel/exporters/stdout/stdoutmetric => ../exporters/stdout/stdoutmetric
replace go.opentelemetry.io/otel/exporters/stdout/stdouttrace => ../exporters/stdout/stdouttrace

View File

@ -24,8 +24,6 @@ replace go.opentelemetry.io/otel/example/zipkin => ../../example/zipkin
replace go.opentelemetry.io/otel/exporters/prometheus => ../../exporters/prometheus
replace go.opentelemetry.io/otel/exporters/stdout => ../../exporters/stdout
replace go.opentelemetry.io/otel/exporters/jaeger => ../../exporters/jaeger
replace go.opentelemetry.io/otel/exporters/zipkin => ../../exporters/zipkin
@ -73,3 +71,7 @@ replace go.opentelemetry.io/otel/exporters/trace/zipkin => ../../exporters/trace
replace go.opentelemetry.io/otel/exporters/otlp/otlpmetric => ../../exporters/otlp/otlpmetric
replace go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc => ../../exporters/otlp/otlpmetric/otlpmetricgrpc
replace go.opentelemetry.io/otel/exporters/stdout/stdoutmetric => ../../exporters/stdout/stdoutmetric
replace go.opentelemetry.io/otel/exporters/stdout/stdouttrace => ../../exporters/stdout/stdouttrace

View File

@ -24,8 +24,6 @@ replace go.opentelemetry.io/otel/example/zipkin => ../example/zipkin
replace go.opentelemetry.io/otel/exporters/prometheus => ../exporters/prometheus
replace go.opentelemetry.io/otel/exporters/stdout => ../exporters/stdout
replace go.opentelemetry.io/otel/exporters/jaeger => ../exporters/jaeger
replace go.opentelemetry.io/otel/exporters/zipkin => ../exporters/zipkin
@ -69,3 +67,7 @@ replace go.opentelemetry.io/otel/exporters/trace/zipkin => ../exporters/trace/zi
replace go.opentelemetry.io/otel/exporters/otlp/otlpmetric => ../exporters/otlp/otlpmetric
replace go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc => ../exporters/otlp/otlpmetric/otlpmetricgrpc
replace go.opentelemetry.io/otel/exporters/stdout/stdoutmetric => ../exporters/stdout/stdoutmetric
replace go.opentelemetry.io/otel/exporters/stdout/stdouttrace => ../exporters/stdout/stdouttrace

View File

@ -29,7 +29,8 @@ import (
"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/baggage"
"go.opentelemetry.io/otel/exporters/stdout"
"go.opentelemetry.io/otel/exporters/stdout/stdouttrace"
"go.opentelemetry.io/otel/exporters/stdout/stdoutmetric"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/metric"
"go.opentelemetry.io/otel/propagation"
@ -51,11 +52,11 @@ To initialize the console exporter, add the following code to the file your `mai
```go
func main() {
exporter, err := stdout.New(
stdout.WithPrettyPrint(),
traceExporter, err := stdouttrace.New(
stdouttrace.WithPrettyPrint(),
)
if err != nil {
log.Fatalf("failed to initialize stdout export pipeline: %v", err)
log.Fatalf("failed to initialize stdouttrace export pipeline: %v", err)
}
```
@ -71,7 +72,7 @@ To create a trace provider, add the following code to your `main.go` file -
```go
ctx := context.Background()
bsp := sdktrace.NewBatchSpanProcessor(exporter)
bsp := sdktrace.NewBatchSpanProcessor(traceExporter)
tp := sdktrace.NewTracerProvider(sdktrace.WithSpanProcessor(bsp))
// Handle this error in a sensible manner where possible
@ -89,12 +90,19 @@ OpenTelemetry requires a meter provider to be initialized in order to create ins
To create a meter provider, add the following code to your `main.go` file -
```go
metricExporter, err := stdoutmetric.New(
stdoutmetric.WithPrettyPrint(),
)
if err != nil {
log.Fatalf("failed to initialize stdoutmetric export pipeline: %v", err)
}
pusher := controller.New(
processor.New(
simple.NewWithExactDistribution(),
exporter,
metricExporter,
),
controller.WithExporter(exporter),
controller.WithExporter(metricExporter),
controller.WithCollectPeriod(5*time.Second),
)
@ -107,7 +115,7 @@ To create a meter provider, add the following code to your `main.go` file -
defer func() { _ = pusher.Stop(ctx) }()
```
This creates a controller that uses a basic processor to aggregate and process metrics that are then sent to the exporter. The basic processor here uses a simple aggregator selector that decides what kind of an aggregator to use to aggregate measurements from a specific instrument. The processor also uses the exporter to learn how to prepare the aggregated measurements for the exporter to consume. The controller will periodically push aggregated measurements to the exporter.
Again we create an exporter, this time using the `stdoutmetric` exporter package. Then we create a controller that uses a basic processor to aggregate and process metrics that are then sent to the exporter. The basic processor here uses a simple aggregator selector that decides what kind of an aggregator to use to aggregate measurements from a specific instrument. The processor also uses the exporter to learn how to prepare the aggregated measurements for the exporter to consume. The controller will periodically push aggregated measurements to the exporter.
## Setting Global Options