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

Eliminate Scope/ScopeID, separate API from SDK for metrics/stats (#48)

* Move scope.Active to trace.CurrentSpan

* Remove scope / does not build

* Global tracer

* Checkpoint

* Checkpoint

* Add key/key.go for key.New

* Comments

* Remove more EventID and ScopeID

* Use Handle to describe static objects

* TODOs

* Remove empty file

* Remove singletons

* Update TODOs

* TODO about map update

* Make stats package option aliases (like key has)

* Rename experimental/streaming

* streaming SDK builds w/ many TODOs

* Get the examples building

* Tidy up metric API / add interface check

* Remove logic from the registry; this is now a placeholder
This commit is contained in:
Joshua MacDonald
2019-07-11 15:28:38 -07:00
committed by rghetia
parent 50f16dd16b
commit 961121698b
49 changed files with 833 additions and 1079 deletions

View File

@@ -17,33 +17,35 @@ package main
import (
"context"
"github.com/open-telemetry/opentelemetry-go/api/key"
"github.com/open-telemetry/opentelemetry-go/api/metric"
"github.com/open-telemetry/opentelemetry-go/api/registry"
"github.com/open-telemetry/opentelemetry-go/api/stats"
"github.com/open-telemetry/opentelemetry-go/api/tag"
"github.com/open-telemetry/opentelemetry-go/api/trace"
"github.com/open-telemetry/opentelemetry-go/exporter/loader"
"github.com/open-telemetry/opentelemetry-go/sdk/event"
"github.com/open-telemetry/opentelemetry-go/experimental/streaming/sdk/event"
)
var (
tracer = trace.GlobalTracer().
WithComponent("example").
WithResources(
tag.New("whatevs").String("yesss"),
key.New("whatevs").String("yesss"),
)
fooKey = tag.New("ex.com/foo", tag.WithDescription("A Foo var"))
barKey = tag.New("ex.com/bar", tag.WithDescription("A Bar var"))
lemonsKey = tag.New("ex.com/lemons", tag.WithDescription("A Lemons var"))
anotherKey = tag.New("ex.com/another")
meter = metric.GlobalMeter() // TODO: should share resources ^^^?
fooKey = key.New("ex.com/foo", registry.WithDescription("A Foo var"))
barKey = key.New("ex.com/bar", registry.WithDescription("A Bar var"))
lemonsKey = key.New("ex.com/lemons", registry.WithDescription("A Lemons var"))
anotherKey = key.New("ex.com/another")
oneMetric = metric.NewFloat64Gauge("ex.com/one",
metric.WithKeys(fooKey, barKey, lemonsKey),
metric.WithDescription("A gauge set to 1.0"),
)
measureTwo = tag.NewMeasure("ex.com/two")
measureTwo = stats.NewMeasure("ex.com/two")
)
func main() {
@@ -54,17 +56,17 @@ func main() {
tag.Insert(barKey.String("bar1")),
)
gauge := oneMetric.Gauge(
fooKey.Value(ctx),
barKey.Value(ctx),
gauge := meter.GetFloat64Gauge(
ctx,
oneMetric,
lemonsKey.Int(10),
)
err := tracer.WithSpan(ctx, "operation", func(ctx context.Context) error {
trace.Active(ctx).AddEvent(ctx, event.WithAttr("Nice operation!", tag.New("bogons").Int(100)))
trace.CurrentSpan(ctx).AddEvent(ctx, event.WithAttr("Nice operation!", key.New("bogons").Int(100)))
trace.Active(ctx).SetAttributes(anotherKey.String("yes"))
trace.CurrentSpan(ctx).SetAttributes(anotherKey.String("yes"))
gauge.Set(ctx, 1)
@@ -72,9 +74,9 @@ func main() {
ctx,
"Sub operation...",
func(ctx context.Context) error {
trace.Active(ctx).SetAttribute(lemonsKey.String("five"))
trace.CurrentSpan(ctx).SetAttribute(lemonsKey.String("five"))
trace.Active(ctx).AddEvent(ctx, event.WithString("Format schmormat %d!", 100))
trace.CurrentSpan(ctx).AddEvent(ctx, event.WithString("Format schmormat %d!", 100))
stats.Record(ctx, measureTwo.M(1.3))
@@ -86,5 +88,6 @@ func main() {
panic(err)
}
loader.Flush()
// TODO: How to flush?
// loader.Flush()
}