Skip to content

Commit

Permalink
example/basic: make basic example work (#279)
Browse files Browse the repository at this point in the history
* example/basic: make basic example work

- use stdout as exportor (otherwise no output when you run it)

* meter does not work yet, rephrase TODO
  • Loading branch information
clsung authored and rghetia committed Nov 4, 2019
1 parent 881e51f commit 6b48fce
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
1 change: 1 addition & 0 deletions example/basic/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ github.com/gostaticanalysis/analysisutil v0.0.3/go.mod h1:eEOZF4jCKGi+aprrirO9e7
github.com/grpc-ecosystem/go-grpc-middleware v1.0.0/go.mod h1:FiyG127CGDf3tlThmgyCl78X/SZQqEOJBCDaAfeWzPs=
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0/go.mod h1:8NvIoxWQoOIhqOTXgfV/d3M/q6VIi02HzZEHgUlZvzk=
github.com/grpc-ecosystem/grpc-gateway v1.9.0/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY=
github.com/hashicorp/golang-lru v0.5.3 h1:YPkqC67at8FYaadspW/6uE0COsBxS2656RLEr8Bppgk=
github.com/hashicorp/golang-lru v0.5.3/go.mod h1:iADmTwqILo4mZ8BN3D2Q6+9jd8WM5uGBxy+E8yxSoD4=
github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ=
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
Expand Down
30 changes: 24 additions & 6 deletions example/basic/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,46 @@ package main

import (
"context"
"log"

"go.opentelemetry.io/otel/api/distributedcontext"
"go.opentelemetry.io/otel/api/key"
"go.opentelemetry.io/otel/api/metric"
"go.opentelemetry.io/otel/api/trace"
"go.opentelemetry.io/otel/exporter/trace/stdout"
"go.opentelemetry.io/otel/global"
sdktrace "go.opentelemetry.io/otel/sdk/trace"
)

var (
tracer = global.TraceProvider().GetTracer("ex.com/basic")
meter = global.MeterProvider().GetMeter("ex.com/basic") // TODO: should share resources ^^^?

fooKey = key.New("ex.com/foo")
barKey = key.New("ex.com/bar")
lemonsKey = key.New("ex.com/lemons")
anotherKey = key.New("ex.com/another")
)

// initTracer creates and registers trace provider instance.
func initTracer() {
var err error
exp, err := stdout.NewExporter(stdout.Options{PrettyPrint: false})
if err != nil {
log.Panicf("failed to initialize stdout exporter %v\n", err)
return
}
tp, err := sdktrace.NewProvider(sdktrace.WithSyncer(exp),
sdktrace.WithConfig(sdktrace.Config{DefaultSampler: sdktrace.AlwaysSample()}))
if err != nil {
log.Panicf("failed to initialize trace provider %v\n", err)
}
global.SetTraceProvider(tp)
}

func main() {
initTracer()
tracer := global.TraceProvider().GetTracer("ex.com/basic")
// TODO: Meter doesn't work yet, check if resources to be shared afterwards.
meter := global.MeterProvider().GetMeter("ex.com/basic")

oneMetric := meter.NewFloat64Gauge("ex.com.one",
metric.WithKeys(fooKey, barKey, lemonsKey),
metric.WithDescription("A gauge set to 1.0"),
Expand Down Expand Up @@ -91,7 +112,4 @@ func main() {
if err != nil {
panic(err)
}

// TODO: How to flush?
// loader.Flush()
}

0 comments on commit 6b48fce

Please sign in to comment.