I'm unable to get the Cloud Monitoring exporter working:
https://github.com/GoogleCloudPlatform/opentelemetry-operations-go/blob/master/exporter/metric/README.md
There are appear to be a couple of issues in addition to my likely incompetence; I'm reasonable familiar with Cloud Monitoring and OpenCensus and this is my first dip into OpenTelemetry. Code at end based upon the README example. The code works with the stdout
exporter.
I've exported:
GOOGLE_APPLICATION_CREDENTIALS
to a known working Service Account with roles/monitoring.admin
PROJECT
to a project with Stackdriver enabled
The module appears to have a bug using InstallNewPipeline(opts, nil)
:
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x18 pc=0x972274]
goroutine 1 [running]:
go.opentelemetry.io/otel/sdk/metric/controller/push.New(0xbfa380, 0xc0001f08c0, 0xbebb60, 0xc000010740, 0xc00000fba0, 0x2, 0x2, 0x1)
/home/dazwilkin/go/pkg/mod/go.opentelemetry.io/otel/[email protected]/metric/controller/push/push.go:56 +0x84
github.com/GoogleCloudPlatform/opentelemetry-operations-go/exporter/metric.NewExportPipeline(0xc0002dfc50, 0x1, 0x1, 0xc0002dfc88, 0x1, 0x1, 0x4d1c01, 0xc00000f800, 0xc0002dfb98)
/home/dazwilkin/go/pkg/mod/github.com/!google!cloud!platform/opentelemetry-operations-go/exporter/[email protected]/metric.go:166 +0x1cf
github.com/GoogleCloudPlatform/opentelemetry-operations-go/exporter/metric.InstallNewPipeline(0xc0002dfc50, 0x1, 0x1, 0xc0002dfc88, 0x1, 0x1, 0x7, 0x6, 0xc00a20)
/home/dazwilkin/go/pkg/mod/github.com/!google!cloud!platform/opentelemetry-operations-go/exporter/[email protected]/metric.go:147 +0x6d
main.main()
/home/dazwilkin/Projects/go-open-telemetry/main.go:25 +0xe1
exit status 2
This occurs in metric.go
line 166 because the append results in len(opts)==2 with the second value being void:
pusher := push.New(
checkpointer,
exporter,
append([]push.Option{
push.WithPeriod(period),
}, popts...)...,
)
Which then breaks push.go
line 56 on the second apply:
for _, opt := range opts {
opt.Apply(c)
}
I can fudge this by creating an non-nil popts:
opts := []cloudmonitoring.Option{
cloudmonitoring.WithProjectID(projectID),
}
popts := []push.Option{}
pusher, err := cloudmonitoring.InstallNewPipeline(opts, popts...)
But this then results in a second failure (which bemuses me);
2020/09/09 14:49:49 [main] ProjectID: [[REDACTED]]
2020/09/09 14:49:49 Error during exporting TimeSeries: currently the aggregator is not supported: &{{0 0} 1 [1]}
2020/09/09 14:49:49 rpc error: code = InvalidArgument desc = Request was missing field timeSeries.
Code
package main
import (
"context"
"log"
"math/rand"
"os"
"time"
"go.opentelemetry.io/otel/api/metric"
"go.opentelemetry.io/otel/label"
"go.opentelemetry.io/otel/sdk/metric/controller/push"
cloudmonitoring "github.com/GoogleCloudPlatform/opentelemetry-operations-go/exporter/metric"
)
func main() {
projectID := os.Getenv("PROJECT")
if projectID == "" {
log.Fatal("Environment variable `PROJECT` is required and was unset")
}
log.Printf("[main] ProjectID: %s", projectID)
opts := []cloudmonitoring.Option{
cloudmonitoring.WithProjectID(projectID),
}
popts := []push.Option{}
pusher, err := cloudmonitoring.InstallNewPipeline(opts, popts...)
if err != nil {
log.Fatal(err)
}
defer pusher.Stop()
meter := global.Meter("cloudmonitoring/example")
counter := metric.Must(meter).NewInt64Counter("counter.foo")
lemonsKey := label.Key("ex.com/lemons")
labels := []label.KeyValue{
lemonsKey.Int(10),
label.Key("key").String("value"),
label.String("dog", "Freddie"),
}
ctx := context.Background()
s := rand.NewSource(time.Now().UnixNano())
r := rand.New(s)
counter.Add(ctx, r.Int63n(100), labels...)
}