Skip to content

Commit 2e95dea

Browse files
committed
feat: add OpenTelemetry instrumentation with OTLP trace and metric exporters
- Create pkg/telemetry package with OTLP gRPC trace and metric exporters - Add configurable trace sampling and periodic metric read interval - Add otelgrpc.UnaryServerInterceptor to gRPC middleware chain - Add Telemetry config section to CLI config - Initialize OTel on server start with graceful shutdown cleanup
1 parent 885852a commit 2e95dea

7 files changed

Lines changed: 199 additions & 16 deletions

File tree

cli/config.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
esStore "github.com/raystack/compass/internal/store/elasticsearch"
1212
"github.com/raystack/compass/internal/store/postgres"
1313
"github.com/raystack/compass/pkg/metrics"
14+
"github.com/raystack/compass/pkg/telemetry"
1415
"github.com/raystack/salt/cmdx"
1516
"github.com/raystack/salt/config"
1617
"github.com/spf13/cobra"
@@ -81,6 +82,9 @@ type Config struct {
8182
// NewRelic
8283
NewRelic metrics.NewRelicConfig `mapstructure:"newrelic"`
8384

85+
// Telemetry
86+
Telemetry telemetry.Config `mapstructure:"telemetry"`
87+
8488
// Elasticsearch
8589
Elasticsearch esStore.Config `mapstructure:"elasticsearch"`
8690

cli/server.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
compassserver "github.com/raystack/compass/internal/server"
1919
esStore "github.com/raystack/compass/internal/store/elasticsearch"
2020
"github.com/raystack/compass/internal/store/postgres"
21+
"github.com/raystack/compass/pkg/telemetry"
2122
"github.com/raystack/salt/log"
2223
"github.com/spf13/cobra"
2324
)
@@ -100,6 +101,12 @@ func runServer(config *Config) error {
100101
return err
101102
}
102103

104+
otelCleanup, err := telemetry.Init(ctx, config.Telemetry, logger)
105+
if err != nil {
106+
return fmt.Errorf("failed to initialize telemetry: %w", err)
107+
}
108+
defer otelCleanup()
109+
103110
esClient, err := initElasticsearch(logger, config.Elasticsearch)
104111
if err != nil {
105112
return err

go.mod

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ require (
99
github.com/Masterminds/squirrel v1.5.2
1010
github.com/elastic/go-elasticsearch v0.0.0
1111
github.com/elastic/go-elasticsearch/v7 v7.16.0
12-
github.com/envoyproxy/protoc-gen-validate v0.6.7
12+
github.com/envoyproxy/protoc-gen-validate v0.10.0
1313
github.com/go-playground/locales v0.14.0
1414
github.com/go-playground/universal-translator v0.18.0
1515
github.com/go-playground/validator/v10 v10.10.0
1616
github.com/golang-migrate/migrate/v4 v4.15.2
1717
github.com/golang-module/carbon/v2 v2.1.8
18-
github.com/google/go-cmp v0.5.8
18+
github.com/google/go-cmp v0.5.9
1919
github.com/google/uuid v1.3.0
2020
github.com/gorilla/handlers v1.4.2
2121
github.com/grpc-ecosystem/go-grpc-middleware v1.3.0
@@ -36,9 +36,15 @@ require (
3636
github.com/raystack/salt v0.3.1
3737
github.com/spf13/cobra v1.4.0
3838
github.com/stretchr/testify v1.8.4
39-
google.golang.org/genproto v0.0.0-20220822174746-9e6da59bd2fc
40-
google.golang.org/grpc v1.49.0
41-
google.golang.org/protobuf v1.28.1
39+
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.42.0
40+
go.opentelemetry.io/otel v1.16.0
41+
go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc v0.39.0
42+
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.16.0
43+
go.opentelemetry.io/otel/sdk v1.16.0
44+
go.opentelemetry.io/otel/sdk/metric v0.39.0
45+
google.golang.org/genproto v0.0.0-20230306155012-7f2fa6fef1f4
46+
google.golang.org/grpc v1.55.0
47+
google.golang.org/protobuf v1.30.0
4248
gopkg.in/yaml.v2 v2.4.0
4349
gotest.tools v2.2.0+incompatible
4450
)
@@ -50,7 +56,7 @@ require (
5056
github.com/alecthomas/chroma v0.8.2 // indirect
5157
github.com/aymerick/douceur v0.2.0 // indirect
5258
github.com/briandowns/spinner v1.18.0 // indirect
53-
github.com/cenkalti/backoff/v4 v4.1.3 // indirect
59+
github.com/cenkalti/backoff/v4 v4.2.1 // indirect
5460
github.com/charmbracelet/glamour v0.3.0 // indirect
5561
github.com/cli/safeexec v1.0.0 // indirect
5662
github.com/containerd/continuity v0.3.0 // indirect
@@ -66,7 +72,7 @@ require (
6672
github.com/fatih/color v1.13.0 // indirect
6773
github.com/goccy/go-json v0.10.2 // indirect
6874
github.com/gogo/protobuf v1.3.2 // indirect
69-
github.com/golang/protobuf v1.5.2 // indirect
75+
github.com/golang/protobuf v1.5.3 // indirect
7076
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 // indirect
7177
github.com/gorilla/css v1.0.0 // indirect
7278
github.com/hashicorp/errwrap v1.1.0 // indirect
@@ -136,6 +142,8 @@ require (
136142
require (
137143
github.com/benbjohnson/clock v1.3.0 // indirect
138144
github.com/fsnotify/fsnotify v1.5.4 // indirect
145+
github.com/go-logr/logr v1.2.4 // indirect
146+
github.com/go-logr/stdr v1.2.2 // indirect
139147
github.com/gofrs/uuid v4.2.0+incompatible // indirect
140148
github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a // indirect
141149
github.com/mitchellh/mapstructure v1.5.0 // indirect
@@ -144,6 +152,12 @@ require (
144152
github.com/spf13/cast v1.5.0 // indirect
145153
github.com/spf13/viper v1.11.0 // indirect
146154
github.com/subosito/gotenv v1.4.0 // indirect
155+
go.opentelemetry.io/otel/exporters/otlp/internal/retry v1.16.0 // indirect
156+
go.opentelemetry.io/otel/exporters/otlp/otlpmetric v0.39.0 // indirect
157+
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.16.0 // indirect
158+
go.opentelemetry.io/otel/metric v1.16.0 // indirect
159+
go.opentelemetry.io/otel/trace v1.16.0 // indirect
160+
go.opentelemetry.io/proto/otlp v0.19.0 // indirect
147161
go.uber.org/atomic v1.9.0 // indirect
148162
go.uber.org/multierr v1.8.0 // indirect
149163
go.uber.org/zap v1.21.0 // indirect

0 commit comments

Comments
 (0)