Skip to content

Commit

Permalink
chore(tm2): OTEL / handle http metrics exporter (#2402)
Browse files Browse the repository at this point in the history
<details><summary>Contributors' checklist...</summary>

- [ ] Added new tests, or not needed, or not feasible
- [ ] Provided an example (e.g. screenshot) to aid review or the PR is
self-explanatory
- [ ] Updated the official documentation or not needed
- [ ] No breaking changes were made, or a `BREAKING CHANGE: xxx` message
was included in the description
- [ ] Added references to related issues and PRs
- [ ] Provided any useful hints for running manual tests
- [ ] Added new benchmarks to [generated
graphs](https://gnoland.github.io/benchmarks), if any. More info
[here](https://github.com/gnolang/gno/blob/master/.benchmarks/README.md).
</details>
  • Loading branch information
albttx authored Jun 20, 2024
1 parent 25dba01 commit ea1ff3f
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 58 deletions.
35 changes: 18 additions & 17 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -29,22 +29,23 @@ require (
github.com/stretchr/testify v1.9.0
github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7
go.etcd.io/bbolt v1.3.9
go.opentelemetry.io/otel v1.25.0
go.opentelemetry.io/otel v1.27.0
go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc v1.25.0
go.opentelemetry.io/otel/metric v1.25.0
go.opentelemetry.io/otel/sdk v1.25.0
go.opentelemetry.io/otel/sdk/metric v1.25.0
go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp v1.27.0
go.opentelemetry.io/otel/metric v1.27.0
go.opentelemetry.io/otel/sdk v1.27.0
go.opentelemetry.io/otel/sdk/metric v1.27.0
go.uber.org/multierr v1.11.0
go.uber.org/zap v1.27.0
go.uber.org/zap/exp v0.2.0
golang.org/x/crypto v0.21.0
golang.org/x/crypto v0.23.0
golang.org/x/exp v0.0.0-20240222234643-814bf88cf225
golang.org/x/mod v0.16.0
golang.org/x/net v0.23.0
golang.org/x/sync v0.6.0
golang.org/x/term v0.18.0
golang.org/x/net v0.25.0
golang.org/x/sync v0.7.0
golang.org/x/term v0.20.0
golang.org/x/tools v0.19.0
google.golang.org/protobuf v1.33.0
google.golang.org/protobuf v1.34.1
gopkg.in/yaml.v3 v3.0.1
)

Expand All @@ -56,18 +57,18 @@ require (
github.com/golang/snappy v0.0.4 // indirect
github.com/gorilla/securecookie v1.1.1 // indirect
github.com/gorilla/sessions v1.2.1 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.19.0 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.20.0 // indirect
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
github.com/nxadm/tail v1.4.11 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/rivo/uniseg v0.4.3 // indirect
github.com/zondax/hid v0.9.2 // indirect
github.com/zondax/ledger-go v0.14.3 // indirect
go.opentelemetry.io/otel/trace v1.25.0 // indirect
go.opentelemetry.io/proto/otlp v1.1.0 // indirect
golang.org/x/sys v0.18.0 // indirect
golang.org/x/text v0.14.0 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20240227224415-6ceb2ff114de // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240401170217-c3f982113cda // indirect
google.golang.org/grpc v1.63.0 // indirect
go.opentelemetry.io/otel/trace v1.27.0 // indirect
go.opentelemetry.io/proto/otlp v1.2.0 // indirect
golang.org/x/sys v0.20.0 // indirect
golang.org/x/text v0.15.0 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20240520151616-dc85e6b867a5 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240515191416-fc5f0ca64291 // indirect
google.golang.org/grpc v1.64.0 // indirect
)
71 changes: 36 additions & 35 deletions go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

35 changes: 29 additions & 6 deletions tm2/pkg/telemetry/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ package metrics
import (
"context"
"fmt"
"net/url"

"github.com/gnolang/gno/tm2/pkg/telemetry/config"
"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc"
"go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp"
"go.opentelemetry.io/otel/metric"
sdkMetric "go.opentelemetry.io/otel/sdk/metric"
"go.opentelemetry.io/otel/sdk/resource"
Expand Down Expand Up @@ -112,14 +114,35 @@ var (
)

func Init(config config.Config) error {
// Use oltp metric exporter
exp, err := otlpmetricgrpc.New(
context.Background(),
otlpmetricgrpc.WithEndpoint(config.ExporterEndpoint),
otlpmetricgrpc.WithInsecure(),
var (
ctx = context.Background()
exp sdkMetric.Exporter
)

u, err := url.Parse(config.ExporterEndpoint)
if err != nil {
return fmt.Errorf("unable to create metrics exporter, %w", err)
return fmt.Errorf("error parsing exporter endpoint: %s, %w", config.ExporterEndpoint, err)
}

// Use oltp metric exporter with http/https or grpc
switch u.Scheme {
case "http", "https":
exp, err = otlpmetrichttp.New(
ctx,
otlpmetrichttp.WithEndpointURL(config.ExporterEndpoint),
)
if err != nil {
return fmt.Errorf("unable to create http metrics exporter, %w", err)
}
default:
exp, err = otlpmetricgrpc.New(
ctx,
otlpmetricgrpc.WithEndpoint(config.ExporterEndpoint),
otlpmetricgrpc.WithInsecure(),
)
if err != nil {
return fmt.Errorf("unable to create grpc metrics exporter, %w", err)
}
}

provider := sdkMetric.NewMeterProvider(
Expand Down

0 comments on commit ea1ff3f

Please sign in to comment.