Skip to content

Commit

Permalink
feat: datadog wiring (main) (backport #8543) (#8561)
Browse files Browse the repository at this point in the history
Co-authored-by: Roman <roman@osmosis.team>
  • Loading branch information
mergify[bot] and p0mvn authored Jul 28, 2024
1 parent 790a23a commit 301997d
Show file tree
Hide file tree
Showing 7 changed files with 151 additions and 42 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### State Compatible

* [#8543](https://github.com/osmosis-labs/osmosis/pull/8543) Add OTEL wiring and new configs in app.toml

## v25.2.1
* [#8546](https://github.com/osmosis-labs/osmosis/pull/8546) feat: reduce commit timeout to 500ms to enable faster blocks, and timeout propose to 1.8s

Expand Down
46 changes: 46 additions & 0 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@ import (
"reflect"
"time"

"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc"
"go.opentelemetry.io/otel/propagation"

"go.opentelemetry.io/otel/sdk/resource"
sdktrace "go.opentelemetry.io/otel/sdk/trace"
semconv "go.opentelemetry.io/otel/semconv/v1.4.0"

wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types"
"github.com/skip-mev/block-sdk/block"
"github.com/skip-mev/block-sdk/block/base"
Expand Down Expand Up @@ -239,6 +247,25 @@ func NewOsmosisApp(
wasmOpts []wasmkeeper.Option,
baseAppOptions ...func(*baseapp.BaseApp),
) *OsmosisApp {
// Handler OTEL configuration.
OTELConfig := NewOTELConfigFromOptions(appOpts)
if OTELConfig.Enabled {
ctx := context.Background()

res, err := resource.New(ctx, resource.WithContainer(),
resource.WithAttributes(semconv.ServiceNameKey.String(OTELConfig.ServiceName)),
resource.WithFromEnv(),
)
if err != nil {
panic(err)
}

_, err = initOTELTracer(ctx, res)
if err != nil {
panic(err)
}
}

initReusablePackageInjections() // This should run before anything else to make sure the variables are properly initialized
overrideWasmVariables()
encodingConfig := GetEncodingConfig()
Expand Down Expand Up @@ -1090,3 +1117,22 @@ func GetMaccPerms() map[string][]string {

return dupMaccPerms
}

// initOTELTracer initializes the OTEL tracer
// and wires it up with the Sentry exporter.
func initOTELTracer(ctx context.Context, res *resource.Resource) (*sdktrace.TracerProvider, error) {
exporter, err := otlptracegrpc.New(ctx, otlptracegrpc.WithInsecure())
if err != nil {
return nil, err
}

tp := sdktrace.NewTracerProvider(
sdktrace.WithBatcher(exporter),
sdktrace.WithResource(res),
)

otel.SetTracerProvider(tp)
otel.SetTextMapPropagator(propagation.NewCompositeTextMapPropagator(propagation.TraceContext{}, propagation.Baggage{}))

return tp, nil
}
25 changes: 25 additions & 0 deletions app/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,15 @@ import (
pruningtypes "github.com/cosmos/cosmos-sdk/store/pruning/types"
sdk "github.com/cosmos/cosmos-sdk/types"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"

"github.com/osmosis-labs/osmosis/osmoutils"
)

type OTELConfig struct {
Enabled bool `mapstructure:"enabled"`
ServiceName string `mapstructure:"service-name"`
}

// DefaultConfig returns a default configuration suitable for nearly all
// testing requirements.
func DefaultConfig() network.Config {
Expand Down Expand Up @@ -61,3 +68,21 @@ func NewAppConstructor(chainId string) network.AppConstructor {
)
}
}

// NewOTELConfigFromOptions returns a new DataDog config from the given options.
func NewOTELConfigFromOptions(opts servertypes.AppOptions) OTELConfig {
isEnabled := osmoutils.ParseBool(opts, "otel", "enabled", false)

if !isEnabled {
return OTELConfig{
Enabled: false,
}
}

serviceName := osmoutils.ParseString(opts, "otel", "service-name")

return OTELConfig{
Enabled: isEnabled,
ServiceName: serviceName,
}
}
13 changes: 13 additions & 0 deletions cmd/osmosisd/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -617,6 +617,8 @@ func initAppConfig() (string, interface{}) {

IndexerConfig indexer.Config `mapstructure:"osmosis-indexer"`

OTELConfig osmosis.OTELConfig `mapstructure:"otel"`

WasmConfig wasmtypes.WasmConfig `mapstructure:"wasm"`
}

Expand Down Expand Up @@ -709,6 +711,17 @@ token-supply-offset-topic-id = "{{ .IndexerConfig.TokenSupplyOffsetTopicId }}"
# The topic id to use for publishing pair metadata
pair-topic-id = "{{ .IndexerConfig.PairTopicId }}"
###############################################################################
### OpenTelemetry (OTEL) Configuration ###
###############################################################################
[otel]
# Flag that enables OTEL
enabled = "{{ .OTELConfig.Enabled }}"
# The service name to use for OTEL
service-name = "{{ .OTELConfig.ServiceName }}"
###############################################################################
### Wasm Configuration ###
###############################################################################
Expand Down
31 changes: 19 additions & 12 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/osmosis-labs/osmosis/v25
go 1.21.8

require (
cloud.google.com/go/pubsub v1.36.1
cloud.google.com/go/pubsub v1.38.0
cosmossdk.io/api v0.3.1
cosmossdk.io/errors v1.0.1
cosmossdk.io/math v1.3.0
Expand Down Expand Up @@ -44,9 +44,13 @@ require (
github.com/stretchr/testify v1.9.0
github.com/tidwall/btree v1.6.0
github.com/tidwall/gjson v1.17.1
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.53.0
go.opentelemetry.io/otel v1.28.0
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.28.0
go.opentelemetry.io/otel/sdk v1.28.0
go.uber.org/multierr v1.11.0
golang.org/x/exp v0.0.0-20240506185415-9bf2ced13842
google.golang.org/genproto/googleapis/api v0.0.0-20240528184218-531527333157
google.golang.org/genproto/googleapis/api v0.0.0-20240701130421-f6361c86f094
google.golang.org/grpc v1.65.0
google.golang.org/protobuf v1.34.2
gopkg.in/yaml.v2 v2.4.0
Expand All @@ -57,10 +61,12 @@ require (

require (
4d63.com/gocheckcompilerdirectives v1.2.1 // indirect
cloud.google.com/go v0.112.1 // indirect
cloud.google.com/go v0.114.0 // indirect
cloud.google.com/go/auth v0.5.1 // indirect
cloud.google.com/go/auth/oauth2adapt v0.2.2 // indirect
cloud.google.com/go/compute/metadata v0.3.0 // indirect
cloud.google.com/go/iam v1.1.6 // indirect
cloud.google.com/go/storage v1.38.0 // indirect
cloud.google.com/go/iam v1.1.8 // indirect
cloud.google.com/go/storage v1.40.0 // indirect
cosmossdk.io/core v0.5.1 // indirect
cosmossdk.io/depinject v1.0.0-alpha.4 // indirect
cosmossdk.io/log v1.3.0 // indirect
Expand Down Expand Up @@ -116,7 +122,8 @@ require (
github.com/google/s2a-go v0.1.7 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/googleapis/enterprise-certificate-proxy v0.3.2 // indirect
github.com/googleapis/gax-go/v2 v2.12.2 // indirect
github.com/googleapis/gax-go/v2 v2.12.5 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.20.0 // indirect
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
github.com/hashicorp/go-getter v1.7.4 // indirect
github.com/hashicorp/go-safetemp v1.0.0 // indirect
Expand Down Expand Up @@ -154,16 +161,16 @@ require (
github.com/zondax/ledger-go v0.14.3 // indirect
go-simpler.org/musttag v0.8.0 // indirect
go-simpler.org/sloglint v0.4.0 // indirect
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.53.0 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.49.0 // indirect
go.opentelemetry.io/otel v1.28.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.28.0 // indirect
go.opentelemetry.io/otel/metric v1.28.0 // indirect
go.opentelemetry.io/otel/trace v1.28.0 // indirect
go.opentelemetry.io/proto/otlp v1.3.1 // indirect
go.uber.org/zap v1.26.0 // indirect
golang.org/x/oauth2 v0.20.0 // indirect
golang.org/x/oauth2 v0.21.0 // indirect
golang.org/x/time v0.5.0 // indirect
google.golang.org/api v0.169.0 // indirect
google.golang.org/genproto v0.0.0-20240227224415-6ceb2ff114de // indirect
google.golang.org/api v0.184.0 // indirect
google.golang.org/genproto v0.0.0-20240604185151-ef581f913117 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240701130421-f6361c86f094 // indirect
pgregory.net/rapid v0.5.5 // indirect
sigs.k8s.io/yaml v1.4.0 // indirect
Expand Down Expand Up @@ -192,7 +199,7 @@ require (
github.com/breml/bidichk v0.2.7 // indirect
github.com/breml/errchkjson v0.3.6 // indirect
github.com/butuzov/ireturn v0.3.0 // indirect
github.com/cenkalti/backoff/v4 v4.2.1 // indirect
github.com/cenkalti/backoff/v4 v4.3.0 // indirect
github.com/cespare/xxhash v1.1.0 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/charithe/durationcheck v0.0.10 // indirect
Expand Down
Loading

0 comments on commit 301997d

Please sign in to comment.