Skip to content

Commit

Permalink
chore: use WithResource in the ExampleExporter to change `service…
Browse files Browse the repository at this point in the history
….name`
  • Loading branch information
laojianzi committed Sep 14, 2021
1 parent 5fbe2c8 commit 072939c
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions exporters/metric/datadog/example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
controller "go.opentelemetry.io/otel/sdk/metric/controller/basic"
"go.opentelemetry.io/otel/sdk/metric/processor/basic"
"go.opentelemetry.io/otel/sdk/metric/selector/simple"
"go.opentelemetry.io/otel/sdk/resource"
semconv "go.opentelemetry.io/otel/semconv/v1.4.0"
)

Expand Down Expand Up @@ -58,17 +59,20 @@ func ExampleExporter() {
go func() {
defer exp.Close()
processor := basic.New(selector, exp)
pusher := controller.New(processor, controller.WithExporter(exp), controller.WithCollectPeriod(time.Second*10))
pusher := controller.New(processor, controller.WithExporter(exp), controller.WithCollectPeriod(time.Second*10),
controller.WithResource(resource.Default()),
controller.WithResource(resource.NewSchemaless(semconv.ServiceNameKey.String("ExampleExporter"))))
ctx := context.Background()
err := pusher.Start(ctx)
if err != nil {
panic(err)
}

defer func() { handleErr(pusher.Stop(ctx)) }()
global.SetMeterProvider(pusher.MeterProvider())
meter := global.Meter("marwandist")
m := metric.Must(meter).NewInt64Histogram("myrecorder")
meter.RecordBatch(context.Background(), []attribute.KeyValue{attribute.Int("l", 1), semconv.ServiceNameKey.String("ExampleExporter")},
meter.RecordBatch(context.Background(), []attribute.KeyValue{attribute.Int("l", 1)},
m.Measurement(1), m.Measurement(50), m.Measurement(100))
}()

Expand Down

0 comments on commit 072939c

Please sign in to comment.