From 6801e87900474e4152af7e0850704304e21635f8 Mon Sep 17 00:00:00 2001 From: Anna Vitova Date: Tue, 17 Oct 2023 14:34:58 +0200 Subject: [PATCH] chore: Include reservation template ID in Floorplan MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Lukáš Zapletal --- cmd/pbackend/api.go | 2 +- cmd/pbackend/stats.go | 2 +- cmd/pbackend/statuser.go | 2 +- cmd/pbackend/worker.go | 2 +- config/api.env.example | 14 +++++---- go.mod | 17 +++++++---- go.sum | 35 +++++++++++++++-------- internal/config/config.go | 10 ++++--- internal/telemetry/otel.go | 22 ++++++++++---- internal/telemetry/zerolog_err_handler.go | 13 +++++++++ 10 files changed, 83 insertions(+), 36 deletions(-) create mode 100644 internal/telemetry/zerolog_err_handler.go diff --git a/cmd/pbackend/api.go b/cmd/pbackend/api.go index 5c19fcbd..834d9e78 100644 --- a/cmd/pbackend/api.go +++ b/cmd/pbackend/api.go @@ -51,7 +51,7 @@ func api() { })) // initialize telemetry - tel := telemetry.Initialize(&log.Logger) + tel := telemetry.Initialize(ctx, &log.Logger) defer tel.Close(ctx) metrics.RegisterApiMetrics() diff --git a/cmd/pbackend/stats.go b/cmd/pbackend/stats.go index 0cf54d81..666d05ba 100644 --- a/cmd/pbackend/stats.go +++ b/cmd/pbackend/stats.go @@ -31,7 +31,7 @@ func stats() { logging.DumpConfigForDevelopment() // initialize telemetry - tel := telemetry.Initialize(&log.Logger) + tel := telemetry.Initialize(ctx, &log.Logger) defer tel.Close(ctx) // initialize the job queue but don't register any workers diff --git a/cmd/pbackend/statuser.go b/cmd/pbackend/statuser.go index 47019435..cc5e7530 100644 --- a/cmd/pbackend/statuser.go +++ b/cmd/pbackend/statuser.go @@ -331,7 +331,7 @@ func statuser() { logging.DumpConfigForDevelopment() // initialize telemetry - tel := telemetry.Initialize(&log.Logger) + tel := telemetry.Initialize(ctx, &log.Logger) defer tel.Close(ctx) // initialize platform kafka and notifications diff --git a/cmd/pbackend/worker.go b/cmd/pbackend/worker.go index b749affe..412bb900 100644 --- a/cmd/pbackend/worker.go +++ b/cmd/pbackend/worker.go @@ -39,7 +39,7 @@ func worker() { logger.Info().Msg("Worker starting") // initialize telemetry - tel := telemetry.Initialize(&log.Logger) + tel := telemetry.Initialize(ctx, &log.Logger) defer tel.Close(ctx) metrics.RegisterWorkerMetrics() diff --git a/config/api.env.example b/config/api.env.example index 876e6b9d..586cfbf3 100644 --- a/config/api.env.example +++ b/config/api.env.example @@ -173,13 +173,17 @@ # STATS_RESERVATIONS_INTERVAL int64 # how often to pull reservation statistics (default "10m") # TELEMETRY_ENABLED bool -# open telemetry collecting (default "false") -# TELEMETRY_JAEGER_ENABLED bool -# open telemetry jaeger exporter (default "false") -# TELEMETRY_JAEGER_ENDPOINT string -# jaeger endpoint (default "http://localhost:14268/api/traces") +# open telemetry collecting via OTLP protocol (default "false") # TELEMETRY_LOGGER_ENABLED bool # open telemetry logger output (dev only) (default "false") +# TELEMETRY_OLTP_ENABLED bool +# open telemetry jaeger exporter (default "false") +# TELEMETRY_OLTP_HOSTNAME string +# OTLP hostname (localhost) (default "localhost") +# TELEMETRY_OLTP_INSECURE bool +# use HTTP connection instead of HTTPS' (default "false") +# TELEMETRY_OLTP_PORT int +# OTLP port (4318) (default "4318") # UNLEASH_ENABLED bool # unleash service (feature flags) (default "false") # UNLEASH_ENVIRONMENT string diff --git a/go.mod b/go.mod index 4b865f97..18ef111c 100644 --- a/go.mod +++ b/go.mod @@ -47,10 +47,11 @@ require ( github.com/segmentio/kafka-go v0.4.42 github.com/stretchr/testify v1.8.4 go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.42.0 - go.opentelemetry.io/otel v1.16.0 + go.opentelemetry.io/otel v1.19.0 go.opentelemetry.io/otel/exporters/jaeger v1.16.0 - go.opentelemetry.io/otel/sdk v1.16.0 - go.opentelemetry.io/otel/trace v1.16.0 + go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.19.0 + go.opentelemetry.io/otel/sdk v1.19.0 + go.opentelemetry.io/otel/trace v1.19.0 go.uber.org/automaxprocs v1.5.3 golang.org/x/crypto v0.12.0 golang.org/x/exp v0.0.0-20230817173708-d852ddb80c63 @@ -79,6 +80,7 @@ require ( github.com/beorn7/perks v1.0.1 // indirect github.com/buger/jsonparser v1.1.1 // indirect github.com/bytedance/sonic v1.10.0 // indirect + github.com/cenkalti/backoff/v4 v4.2.1 // indirect github.com/cespare/xxhash/v2 v2.2.0 // indirect github.com/chenzhuoyu/base64x v0.0.0-20230717121745-296ad89f973d // indirect github.com/chenzhuoyu/iasm v0.9.0 // indirect @@ -109,6 +111,7 @@ require ( github.com/google/s2a-go v0.1.5 // indirect github.com/googleapis/enterprise-certificate-proxy v0.2.5 // indirect github.com/googleapis/gax-go/v2 v2.12.0 // indirect + github.com/grpc-ecosystem/grpc-gateway/v2 v2.16.0 // indirect github.com/huandu/xstrings v1.4.0 // indirect github.com/imdario/mergo v0.3.16 // indirect github.com/invopop/yaml v0.2.0 // indirect @@ -163,18 +166,20 @@ require ( go.mongodb.org/mongo-driver v1.12.1 // indirect go.opencensus.io v0.24.0 // indirect go.opentelemetry.io/contrib v1.17.0 // indirect - go.opentelemetry.io/otel/metric v1.16.0 // indirect + go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.19.0 // indirect + go.opentelemetry.io/otel/metric v1.19.0 // indirect + go.opentelemetry.io/proto/otlp v1.0.0 // indirect golang.org/x/arch v0.4.0 // indirect golang.org/x/net v0.14.0 // indirect golang.org/x/oauth2 v0.11.0 // indirect golang.org/x/sync v0.3.0 // indirect - golang.org/x/sys v0.11.0 // indirect + golang.org/x/sys v0.12.0 // indirect golang.org/x/text v0.12.0 // indirect google.golang.org/appengine v1.6.7 // indirect google.golang.org/genproto v0.0.0-20230821184602-ccc8af3d0e93 // indirect google.golang.org/genproto/googleapis/api v0.0.0-20230821184602-ccc8af3d0e93 // indirect google.golang.org/genproto/googleapis/rpc v0.0.0-20230821184602-ccc8af3d0e93 // indirect - google.golang.org/grpc v1.57.0 // indirect + google.golang.org/grpc v1.58.2 // indirect google.golang.org/protobuf v1.31.0 // indirect olympos.io/encoding/edn v0.0.0-20201019073823-d3554ca0b0a3 // indirect ) diff --git a/go.sum b/go.sum index 1287edca..80202e2e 100644 --- a/go.sum +++ b/go.sum @@ -94,6 +94,8 @@ github.com/bytedance/sonic v1.5.0/go.mod h1:ED5hyg4y6t3/9Ku1R6dU/4KyJ48DZ4jPhfY1 github.com/bytedance/sonic v1.10.0-rc/go.mod h1:ElCzW+ufi8qKqNW0FY314xriJhyJhuoJ3gFZdAHF7NM= github.com/bytedance/sonic v1.10.0 h1:qtNZduETEIWJVIyDl01BeNxur2rW9OwTQ/yBqFRkKEk= github.com/bytedance/sonic v1.10.0/go.mod h1:iZcSUejdk5aukTND/Eu/ivjQuEL0Cu9/rf50Hi0u/g4= +github.com/cenkalti/backoff/v4 v4.2.1 h1:y4OZtCnogmCPw98Zjyt5a6+QwPLGkiQsYW5oUqylYbM= +github.com/cenkalti/backoff/v4 v4.2.1/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE= github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44= @@ -249,6 +251,7 @@ github.com/gofrs/flock v0.8.1 h1:+gYjHKf32LDeiEEFhQaotPbLuUXjY5ZqxKgXy7n59aw= github.com/golang-jwt/jwt/v5 v5.0.0 h1:1n1XNM9hk7O9mnQoNBGolZvzebBQ7p93ULHRc28XJUE= github.com/golang-jwt/jwt/v5 v5.0.0/go.mod h1:pqrtFR0X4osieyHYxtmOUWsAWrfe1Q5UVIyoH402zdk= github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= +github.com/golang/glog v1.1.0 h1:/d3pCKDPWNnvIWe0vVUpNP32qc8U3PDVxySP/y360qE= github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da h1:oI5xCqsCo564l8iNU+DwB5epxmsaqB+rhGL0m5jtYqE= github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= @@ -294,6 +297,8 @@ github.com/googleapis/gax-go/v2 v2.12.0 h1:A+gCJKdRfqXkr+BIRGtZLibNXf0m1f9E4HG56 github.com/googleapis/gax-go/v2 v2.12.0/go.mod h1:y+aIqrI5eb1YGMVJfuV3185Ts/D7qKpsEkdD5+I6QGU= github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So= github.com/grpc-ecosystem/grpc-gateway v1.16.0/go.mod h1:BDjrQk3hbvj6Nolgz8mAMFbcEtjT1g+wF4CSlocrBnw= +github.com/grpc-ecosystem/grpc-gateway/v2 v2.16.0 h1:YBftPWNWd4WwGqtY2yeZL2ef8rHAxPBD8KFhJpmcqms= +github.com/grpc-ecosystem/grpc-gateway/v2 v2.16.0/go.mod h1:YN5jB8ie0yfIUg6VvR9Kz84aCaG7AsGZnLjhHbUqwPg= github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= github.com/huandu/xstrings v1.3.3/go.mod h1:y5/lhBue+AyNmUVz9RLU9xbLR0o4KIIExikq4ovT0aE= github.com/huandu/xstrings v1.4.0 h1:D17IlohoQq4UcpqD7fDk80P7l+lwAmlFaBHgOipl2FU= @@ -533,19 +538,25 @@ go.opentelemetry.io/contrib v1.17.0/go.mod h1:gIzjwWFoGazJmtCaDgViqOSJPde2mCWzv6 go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.42.0 h1:pginetY7+onl4qN1vl0xW/V/v6OBZ0vVdH+esuJgvmM= go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.42.0/go.mod h1:XiYsayHc36K3EByOO6nbAXnAWbrUxdjUROCEeeROOH8= go.opentelemetry.io/otel v1.3.0/go.mod h1:PWIKzi6JCp7sM0k9yZ43VX+T345uNbAkDKwHVjb2PTs= -go.opentelemetry.io/otel v1.16.0 h1:Z7GVAX/UkAXPKsy94IU+i6thsQS4nb7LviLpnaNeW8s= -go.opentelemetry.io/otel v1.16.0/go.mod h1:vl0h9NUa1D5s1nv3A5vZOYWn8av4K8Ml6JDeHrT/bx4= +go.opentelemetry.io/otel v1.19.0 h1:MuS/TNf4/j4IXsZuJegVzI1cwut7Qc00344rgH7p8bs= +go.opentelemetry.io/otel v1.19.0/go.mod h1:i0QyjOq3UPoTzff0PJB2N66fb4S0+rSbSB15/oyH9fY= go.opentelemetry.io/otel/exporters/jaeger v1.16.0 h1:YhxxmXZ011C0aDZKoNw+juVWAmEfv/0W2XBOv9aHTaA= go.opentelemetry.io/otel/exporters/jaeger v1.16.0/go.mod h1:grYbBo/5afWlPpdPZYhyn78Bk04hnvxn2+hvxQhKIQM= -go.opentelemetry.io/otel/metric v1.16.0 h1:RbrpwVG1Hfv85LgnZ7+txXioPDoh6EdbZHo26Q3hqOo= -go.opentelemetry.io/otel/metric v1.16.0/go.mod h1:QE47cpOmkwipPiefDwo2wDzwJrlfxxNYodqc4xnGCo4= +go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.19.0 h1:Mne5On7VWdx7omSrSSZvM4Kw7cS7NQkOOmLcgscI51U= +go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.19.0/go.mod h1:IPtUMKL4O3tH5y+iXVyAXqpAwMuzC1IrxVS81rummfE= +go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.19.0 h1:IeMeyr1aBvBiPVYihXIaeIZba6b8E1bYp7lbdxK8CQg= +go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.19.0/go.mod h1:oVdCUtjq9MK9BlS7TtucsQwUcXcymNiEDjgDD2jMtZU= +go.opentelemetry.io/otel/metric v1.19.0 h1:aTzpGtV0ar9wlV4Sna9sdJyII5jTVJEvKETPiOKwvpE= +go.opentelemetry.io/otel/metric v1.19.0/go.mod h1:L5rUsV9kM1IxCj1MmSdS+JQAcVm319EUrDVLrt7jqt8= go.opentelemetry.io/otel/sdk v1.3.0/go.mod h1:rIo4suHNhQwBIPg9axF8V9CA72Wz2mKF1teNrup8yzs= -go.opentelemetry.io/otel/sdk v1.16.0 h1:Z1Ok1YsijYL0CSJpHt4cS3wDDh7p572grzNrBMiMWgE= -go.opentelemetry.io/otel/sdk v1.16.0/go.mod h1:tMsIuKXuuIWPBAOrH+eHtvhTL+SntFtXF9QD68aP6p4= +go.opentelemetry.io/otel/sdk v1.19.0 h1:6USY6zH+L8uMH8L3t1enZPR3WFEmSTADlqldyHtJi3o= +go.opentelemetry.io/otel/sdk v1.19.0/go.mod h1:NedEbbS4w3C6zElbLdPJKOpJQOrGUJ+GfzpjUvI0v1A= go.opentelemetry.io/otel/trace v1.3.0/go.mod h1:c/VDhno8888bvQYmbYLqe41/Ldmr/KKunbvWM4/fEjk= -go.opentelemetry.io/otel/trace v1.16.0 h1:8JRpaObFoW0pxuVPapkgH8UhHQj+bJW8jJsCZEu5MQs= -go.opentelemetry.io/otel/trace v1.16.0/go.mod h1:Yt9vYq1SdNz3xdjZZK7wcXv1qv2pwLkqr2QVwea0ef0= +go.opentelemetry.io/otel/trace v1.19.0 h1:DFVQmlVbfVeOuBRrwdtaehRrWiL1JoVs9CPIQ1Dzxpg= +go.opentelemetry.io/otel/trace v1.19.0/go.mod h1:mfaSyvGyEJEI0nyV2I4qhNQnbBOUUmYZpYojqMnX2vo= go.opentelemetry.io/proto/otlp v0.7.0/go.mod h1:PqfVotwruBrMGOCsRd/89rSnXhoiJIqeYNgFYFoEGnI= +go.opentelemetry.io/proto/otlp v1.0.0 h1:T0TX0tmXU8a3CbNXzEKGeU5mIVOdf0oykP+u2lIVU/I= +go.opentelemetry.io/proto/otlp v1.0.0/go.mod h1:Sy6pihPLfYHkr3NkUbEhGHFhINUSI/v80hjKIs5JXpM= go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= go.uber.org/automaxprocs v1.5.3 h1:kWazyxZUrS3Gs4qUpbwo5kEIMGe/DAvi5Z4tl2NW4j8= go.uber.org/automaxprocs v1.5.3/go.mod h1:eRbA25aqJrxAbsLO0xy5jVwPt7FQnRgjW+efnwa1WM0= @@ -643,8 +654,8 @@ golang.org/x/sys v0.0.0-20220908164124-27713097b956/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.2.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.11.0 h1:eG7RXZHdqOJ1i+0lgLgCpSXAp6M3LYlAo6osgSi0xOM= -golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.12.0 h1:CM0HF96J0hcLAwsHPJZjfdNzs0gftsLfgKt57wWHJ0o= +golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/term v0.2.0/go.mod h1:TVmDHMZPmdnySmBfhjOoOdhjzdE1h4u1VwSiw2l1Nuc= @@ -701,8 +712,8 @@ google.golang.org/grpc v1.33.1/go.mod h1:fr5YgcSWrqhRRxogOsw7RzIpsmvOZ6IcH4kBYTp google.golang.org/grpc v1.33.2/go.mod h1:JMHMWHQWaTccqQQlmk3MJZS+GWXOdAesneDmEnv2fbc= google.golang.org/grpc v1.36.0/go.mod h1:qjiiYl8FncCW8feJPdyg3v6XW24KsRHe+dy9BAGRRjU= google.golang.org/grpc v1.45.0/go.mod h1:lN7owxKUQEqMfSyQikvvk5tf/6zMPsrK+ONuO11+0rQ= -google.golang.org/grpc v1.57.0 h1:kfzNeI/klCGD2YPMUlaGNT3pxvYfga7smW3Vth8Zsiw= -google.golang.org/grpc v1.57.0/go.mod h1:Sd+9RMTACXwmub0zcNY2c4arhtrbBYD1AUHI/dt16Mo= +google.golang.org/grpc v1.58.2 h1:SXUpjxeVF3FKrTYQI4f4KvbGD5u2xccdYdurwowix5I= +google.golang.org/grpc v1.58.2/go.mod h1:tgX3ZQDlNJGU96V6yHh1T/JeoBQ2TXdr43YbYSsCJk0= google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM= diff --git a/internal/config/config.go b/internal/config/config.go index fbd7b86d..5c6ad2c4 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -67,11 +67,13 @@ var config struct { MaxField int `env:"MAX_FIELD" env-default:"0" env-description:"logger maximum field length (dev only)"` } `env-prefix:"LOGGING_"` Telemetry struct { - Enabled bool `env:"ENABLED" env-default:"false" env-description:"open telemetry collecting"` - Jaeger struct { + Enabled bool `env:"ENABLED" env-default:"false" env-description:"open telemetry collecting via OTLP protocol"` + OTLP struct { Enabled bool `env:"ENABLED" env-default:"false" env-description:"open telemetry jaeger exporter"` - Endpoint string `env:"ENDPOINT" env-default:"http://localhost:14268/api/traces" env-description:"jaeger endpoint"` - } `env-prefix:"JAEGER_"` + Hostname string `env:"HOSTNAME" env-default:"localhost" env-description:"OTLP hostname (localhost)"` + Port int `env:"PORT" env-default:"4318" env-description:"OTLP port (4318)"` + Insecure bool `env:"INSECURE" env-default:"false" env-description:"use HTTP connection instead of HTTPS'"` + } `env-prefix:"OLTP_"` Logger struct { Enabled bool `env:"ENABLED" env-default:"false" env-description:"open telemetry logger output (dev only)"` } `env-prefix:"LOGGER_"` diff --git a/internal/telemetry/otel.go b/internal/telemetry/otel.go index c61d5782..aed055f0 100644 --- a/internal/telemetry/otel.go +++ b/internal/telemetry/otel.go @@ -2,6 +2,7 @@ package telemetry import ( "context" + "fmt" "net/http" "github.com/RHEnVision/provisioning-backend/internal/config" @@ -10,7 +11,7 @@ import ( "github.com/riandyrn/otelchi" "github.com/rs/zerolog" "go.opentelemetry.io/otel" - "go.opentelemetry.io/otel/exporters/jaeger" + "go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp" "go.opentelemetry.io/otel/propagation" "go.opentelemetry.io/otel/sdk/resource" "go.opentelemetry.io/otel/sdk/trace" @@ -29,21 +30,31 @@ func Middleware(routes chi.Routes) func(next http.Handler) http.Handler { return otelchi.Middleware(AppName, otelchi.WithChiRoutes(routes), otelchi.WithRequestMethodInSpanName(true)) } -func Initialize(rootLogger *zerolog.Logger) *Telemetry { +func Initialize(ctx context.Context, rootLogger *zerolog.Logger) *Telemetry { if !config.Telemetry.Enabled { return &Telemetry{} } logger := rootLogger.With().Bool("otel", true).Logger() var exporterOption trace.TracerProviderOption - if config.Telemetry.Jaeger.Enabled { - // production use case: full exporting, batching - exporter, err := jaeger.New(jaeger.WithCollectorEndpoint(jaeger.WithEndpoint(config.Telemetry.Jaeger.Endpoint))) + if config.Telemetry.OTLP.Enabled { + logger.Debug().Msg("Jaeger telemetry enabled") + endpoint := fmt.Sprintf("%s:%d", config.Telemetry.OTLP.Hostname, config.Telemetry.OTLP.Port) + // production use case: full exporting, batching, compression + opts := []otlptracehttp.Option{ + otlptracehttp.WithEndpoint(endpoint), + otlptracehttp.WithCompression(otlptracehttp.GzipCompression), + } + if config.Telemetry.OTLP.Insecure { + opts = append(opts, otlptracehttp.WithInsecure()) + } + exporter, err := otlptracehttp.New(ctx, opts...) if err != nil { panic(err) } exporterOption = trace.WithBatcher(exporter) } else if config.Telemetry.Logger.Enabled { + logger.Debug().Msg("Logger telemetry enabled") // development use case: logger exporting, synchronous exporter := NewZerologExporter(&logger) exporterOption = trace.WithSyncer(exporter) @@ -67,6 +78,7 @@ func Initialize(rootLogger *zerolog.Logger) *Telemetry { propagator := propagation.NewCompositeTextMapPropagator(propagation.TraceContext{}, propagation.Baggage{}) otel.SetTracerProvider(tp) otel.SetTextMapPropagator(propagator) + otel.SetErrorHandler(&ZerologOpenTelemetryErrorHandler{logger: &logger}) return &Telemetry{tracerProvider: tp, propagator: propagator} } diff --git a/internal/telemetry/zerolog_err_handler.go b/internal/telemetry/zerolog_err_handler.go new file mode 100644 index 00000000..bd2c1e6b --- /dev/null +++ b/internal/telemetry/zerolog_err_handler.go @@ -0,0 +1,13 @@ +package telemetry + +import ( + "github.com/rs/zerolog" +) + +type ZerologOpenTelemetryErrorHandler struct { + logger *zerolog.Logger +} + +func (eh ZerologOpenTelemetryErrorHandler) Handle(err error) { + eh.logger.Warn().Err(err).Msgf("OTLP error: %s", err.Error()) +}