mirror of
				https://github.com/elyby/chrly.git
				synced 2025-05-31 14:11:51 +05:30 
			
		
		
		
	Add otel setup
This commit is contained in:
		
							
								
								
									
										31
									
								
								go.mod
									
									
									
									
									
								
							
							
						
						
									
										31
									
								
								go.mod
									
									
									
									
									
								
							| @@ -4,6 +4,9 @@ go 1.21 | ||||
|  | ||||
| // Main dependencies | ||||
| require ( | ||||
| 	github.com/SentimensRG/ctx v0.0.0-20180729130232-0bfd988c655d | ||||
| 	github.com/agoda-com/opentelemetry-go/otelslog v0.1.1 | ||||
| 	github.com/agoda-com/opentelemetry-logs-go v0.4.3 | ||||
| 	github.com/brunomvsouza/singleflight v0.4.0 | ||||
| 	github.com/defval/di v1.12.0 | ||||
| 	github.com/etherlabsio/healthcheck/v2 v2.0.0 | ||||
| @@ -14,10 +17,18 @@ require ( | ||||
| 	github.com/jellydator/ttlcache/v3 v3.1.1 | ||||
| 	github.com/mediocregopher/radix/v4 v4.1.4 | ||||
| 	github.com/mono83/slf v0.0.0-20170919161409-79153e9636db | ||||
| 	github.com/SentimensRG/ctx v0.0.0-20180729130232-0bfd988c655d | ||||
| 	github.com/spf13/cobra v1.8.0 | ||||
| 	github.com/spf13/viper v1.18.1 | ||||
| 	github.com/valyala/fastjson v1.6.4 | ||||
| 	go.opentelemetry.io/contrib/instrumentation/github.com/gorilla/mux/otelmux v0.48.0 | ||||
| 	go.opentelemetry.io/contrib/instrumentation/runtime v0.48.0 | ||||
| 	go.opentelemetry.io/otel v1.23.1 | ||||
| 	go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp v1.23.1 | ||||
| 	go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.23.1 | ||||
| 	go.opentelemetry.io/otel/metric v1.23.1 | ||||
| 	go.opentelemetry.io/otel/sdk v1.23.1 | ||||
| 	go.opentelemetry.io/otel/sdk/metric v1.23.1 | ||||
| 	go.opentelemetry.io/otel/trace v1.23.1 | ||||
| ) | ||||
|  | ||||
| // Dev dependencies | ||||
| @@ -28,12 +39,18 @@ require ( | ||||
|  | ||||
| // Indirect dependencies | ||||
| require ( | ||||
| 	github.com/cenkalti/backoff/v4 v4.2.1 // indirect | ||||
| 	github.com/certifi/gocertifi v0.0.0-20210507211836-431795d63e8d // indirect | ||||
| 	github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect | ||||
| 	github.com/felixge/httpsnoop v1.0.4 // indirect | ||||
| 	github.com/fsnotify/fsnotify v1.7.0 // indirect | ||||
| 	github.com/gabriel-vasile/mimetype v1.4.2 // indirect | ||||
| 	github.com/go-logr/logr v1.4.1 // indirect | ||||
| 	github.com/go-logr/stdr v1.2.2 // indirect | ||||
| 	github.com/go-playground/locales v0.14.1 // indirect | ||||
| 	github.com/go-playground/universal-translator v0.18.1 // indirect | ||||
| 	github.com/golang/protobuf v1.5.3 // indirect | ||||
| 	github.com/grpc-ecosystem/grpc-gateway/v2 v2.19.1 // indirect | ||||
| 	github.com/h2non/parth v0.0.0-20190131123155-b4df798d6542 // indirect | ||||
| 	github.com/hashicorp/hcl v1.0.0 // indirect | ||||
| 	github.com/inconshreveable/mousetrap v1.1.0 // indirect | ||||
| @@ -51,13 +68,19 @@ require ( | ||||
| 	github.com/stretchr/objx v0.5.0 // indirect | ||||
| 	github.com/subosito/gotenv v1.6.0 // indirect | ||||
| 	github.com/tilinna/clock v1.0.2 // indirect | ||||
| 	go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.23.1 // indirect | ||||
| 	go.opentelemetry.io/proto/otlp v1.1.0 // indirect | ||||
| 	go.uber.org/multierr v1.11.0 // indirect | ||||
| 	golang.org/x/crypto v0.16.0 // indirect | ||||
| 	golang.org/x/crypto v0.19.0 // indirect | ||||
| 	golang.org/x/exp v0.0.0-20231206192017-f3f8817b8deb // indirect | ||||
| 	golang.org/x/net v0.19.0 // indirect | ||||
| 	golang.org/x/net v0.21.0 // indirect | ||||
| 	golang.org/x/sync v0.5.0 // indirect | ||||
| 	golang.org/x/sys v0.15.0 // indirect | ||||
| 	golang.org/x/sys v0.17.0 // indirect | ||||
| 	golang.org/x/text v0.14.0 // indirect | ||||
| 	google.golang.org/genproto/googleapis/api v0.0.0-20240205150955-31a09d347014 // indirect | ||||
| 	google.golang.org/genproto/googleapis/rpc v0.0.0-20240205150955-31a09d347014 // indirect | ||||
| 	google.golang.org/grpc v1.61.0 // indirect | ||||
| 	google.golang.org/protobuf v1.32.0 // indirect | ||||
| 	gopkg.in/ini.v1 v1.67.0 // indirect | ||||
| 	gopkg.in/yaml.v3 v3.0.1 // indirect | ||||
| ) | ||||
|   | ||||
							
								
								
									
										111
									
								
								go.sum
									
									
									
									
									
								
							
							
						
						
									
										111
									
								
								go.sum
									
									
									
									
									
								
							| @@ -1,5 +1,13 @@ | ||||
| github.com/SentimensRG/ctx v0.0.0-20180729130232-0bfd988c655d h1:CbB/Ef3TyBvSSJx2HDSUiw49ONTpaX6BGiI0jJEX6b8= | ||||
| github.com/SentimensRG/ctx v0.0.0-20180729130232-0bfd988c655d/go.mod h1:cfn0Ycx1ASzCkl8+04zI4hrclf9YQ1QfncxzFiNtQLo= | ||||
| github.com/agoda-com/opentelemetry-go/otelslog v0.1.1 h1:6nV8PZCzySHuh9kP/HZ2OJqGucwQiM+yZRugKDvtzj4= | ||||
| github.com/agoda-com/opentelemetry-go/otelslog v0.1.1/go.mod h1:CSc0veIcY/HsIfH7l5PGtIpRvBttk09QUQlweVkD2PI= | ||||
| github.com/agoda-com/opentelemetry-logs-go v0.4.3 h1:dYAx/q9di+/Pv6HuGq59DFIOjqKT0LTy3PYTIz8ccq8= | ||||
| github.com/agoda-com/opentelemetry-logs-go v0.4.3/go.mod h1:gPQ0fHqroxNP2DlQFZt29/pfqGiP2m6Q5CCxEgLo6yQ= | ||||
| github.com/brunomvsouza/singleflight v0.4.0 h1:9dNcTeYoXSus3xbZEM0EEZ11EcCRjUZOvVW8rnDMG5Y= | ||||
| github.com/brunomvsouza/singleflight v0.4.0/go.mod h1:8RYo9j5WQRupmsnUz5DlUWZxDLNi+t9Zhj3EZFmns7I= | ||||
| 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/certifi/gocertifi v0.0.0-20210507211836-431795d63e8d h1:S2NE3iHSwP0XV47EEXL8mWmRdEfGscSJ+7EgePNgt0s= | ||||
| github.com/certifi/gocertifi v0.0.0-20210507211836-431795d63e8d/go.mod h1:sGbDF6GwGcLpkNXPUTkMRoywsNa/ol15pxFe6ERfguA= | ||||
| github.com/cpuguy83/go-md2man/v2 v2.0.3/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= | ||||
| @@ -11,6 +19,8 @@ github.com/defval/di v1.12.0 h1:xXm7BMX2+Nr0Yyu55DeJl/rmfCA7CQX89f4AGE0zA6U= | ||||
| github.com/defval/di v1.12.0/go.mod h1:PhVbOxQOvU7oawTOJXXTvqOJp1Dvsjs5PuzMw9gGl0I= | ||||
| github.com/etherlabsio/healthcheck/v2 v2.0.0 h1:oKq8cbpwM/yNGPXf2Sff6MIjVUjx/pGYFydWzeK2MpA= | ||||
| github.com/etherlabsio/healthcheck/v2 v2.0.0/go.mod h1:huNVOjKzu6FI1eaO1CGD3ZjhrmPWf5Obu/pzpI6/wog= | ||||
| github.com/felixge/httpsnoop v1.0.4 h1:NFTV2Zj1bL4mc9sqWACXbQFVBBg2W3GPvqp8/ESS2Wg= | ||||
| github.com/felixge/httpsnoop v1.0.4/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U= | ||||
| github.com/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHkI4W8= | ||||
| github.com/frankban/quicktest v1.14.6/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0= | ||||
| github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA= | ||||
| @@ -19,6 +29,14 @@ github.com/gabriel-vasile/mimetype v1.4.2 h1:w5qFW6JKBz9Y393Y4q372O9A7cUSequkh1Q | ||||
| github.com/gabriel-vasile/mimetype v1.4.2/go.mod h1:zApsH/mKG4w07erKIaJPFiX0Tsq9BFQgN3qGY5GnNgA= | ||||
| github.com/getsentry/raven-go v0.2.1-0.20190419175539-919484f041ea h1:t6e33/eet/VyiHHHKs0cBytUISUWQ/hmQwOlqtFoGEo= | ||||
| github.com/getsentry/raven-go v0.2.1-0.20190419175539-919484f041ea/go.mod h1:KungGk8q33+aIAZUIVWZDr2OfAEBsO49PX4NzFV5kcQ= | ||||
| github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= | ||||
| github.com/go-logr/logr v1.4.1 h1:pKouT5E8xu9zeFC39JXRDukb6JFQPXM5p5I91188VAQ= | ||||
| github.com/go-logr/logr v1.4.1/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= | ||||
| github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag= | ||||
| github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE= | ||||
| github.com/go-ole/go-ole v1.2.6/go.mod h1:pprOEPIfldk/42T2oK7lQ4v4JSDwmV0As9GaiUsvbm0= | ||||
| github.com/go-ole/go-ole v1.3.0 h1:Dt6ye7+vXGIKZ7Xtk4s6/xVdGDQynvom7xCFEdWr6uE= | ||||
| github.com/go-ole/go-ole v1.3.0/go.mod h1:5LS6F96DhAwUc7C+1HLexzMXY1xGRSryjyPPKW6zv78= | ||||
| github.com/go-playground/assert/v2 v2.2.0 h1:JvknZsQTYeFEAhQwI4qEt9cyV5ONwRHC+lYKSsYSR8s= | ||||
| github.com/go-playground/assert/v2 v2.2.0/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4= | ||||
| github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/oXslEjJA= | ||||
| @@ -29,10 +47,18 @@ github.com/go-playground/validator/v10 v10.17.0 h1:SmVVlfAOtlZncTxRuinDPomC2DkXJ | ||||
| github.com/go-playground/validator/v10 v10.17.0/go.mod h1:9iXMNT7sEkjXb0I+enO7QXmzG6QCsPWY4zveKFVRSyU= | ||||
| github.com/golang-jwt/jwt/v5 v5.2.0 h1:d/ix8ftRUorsN+5eMIlF4T6J8CAt9rch3My2winC1Jw= | ||||
| github.com/golang-jwt/jwt/v5 v5.2.0/go.mod h1:pqrtFR0X4osieyHYxtmOUWsAWrfe1Q5UVIyoH402zdk= | ||||
| github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= | ||||
| github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= | ||||
| github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg= | ||||
| github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= | ||||
| github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= | ||||
| github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= | ||||
| github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= | ||||
| github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= | ||||
| github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= | ||||
| github.com/gorilla/mux v1.8.1 h1:TuBL49tXwgrFYWhqrNgrUNEY92u81SPhu7sTdzQEiWY= | ||||
| github.com/gorilla/mux v1.8.1/go.mod h1:AKf9I4AEqPTmMytcMc0KkNouC66V3BtZ4qD5fmWSiMQ= | ||||
| github.com/grpc-ecosystem/grpc-gateway/v2 v2.19.1 h1:/c3QmbOGMGTOumP2iT/rCwB7b0QDGLKzqOmktBjT+Is= | ||||
| github.com/grpc-ecosystem/grpc-gateway/v2 v2.19.1/go.mod h1:5SN9VR2LTsRFsrEC6FHgRbTWrTHu6tqPeKxEQv15giM= | ||||
| github.com/h2non/gock v1.2.0 h1:K6ol8rfrRkUOefooBC8elXoaNGYkpp7y2qcxGG6BzUE= | ||||
| github.com/h2non/gock v1.2.0/go.mod h1:tNhoxHYW2W42cYkYb1WqzdbYIieALC99kpYr7rH/BQk= | ||||
| github.com/h2non/parth v0.0.0-20190131123155-b4df798d6542 h1:2VTzZjLZBgl62/EtslCrtky5vbi9dd7HrQPQIx6wqiw= | ||||
| @@ -49,6 +75,9 @@ github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= | ||||
| github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= | ||||
| github.com/leodido/go-urn v1.2.4 h1:XlAE/cm/ms7TE/VMVoduSpNBoyc2dOxHs5MZSwAN63Q= | ||||
| github.com/leodido/go-urn v1.2.4/go.mod h1:7ZrI8mTSeBSHl/UaRyKQW1qZeMgak41ANeCNaVckg+4= | ||||
| github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0/go.mod h1:zJYVVT2jmtg6P3p1VtQj7WsuWi/y4VnjVBn7F8KPB3I= | ||||
| github.com/lufia/plan9stats v0.0.0-20231016141302-07b5767bb0ed h1:036IscGBfJsFIgJQzlui7nK1Ncm0tp2ktmPj8xO4N/0= | ||||
| github.com/lufia/plan9stats v0.0.0-20231016141302-07b5767bb0ed/go.mod h1:ilwx/Dta8jXAgpFYFvSWEMwxmbWXyiUHkd5FwyKhb5k= | ||||
| github.com/magiconair/properties v1.8.7 h1:IeQXZAiQcpL9mgcAe1Nu6cX9LLw6ExEHKjN0VQdvPDY= | ||||
| github.com/magiconair/properties v1.8.7/go.mod h1:Dhd985XPs7jluiymwWYZ0G4Z61jb3vdS329zhj2hYo0= | ||||
| github.com/mediocregopher/radix/v4 v4.1.4 h1:Uze6DEbEAvL+VHXUEu/EDBTkUk5CLct5h3nVSGpc6Ts= | ||||
| @@ -64,13 +93,21 @@ github.com/pelletier/go-toml/v2 v2.1.1/go.mod h1:tJU2Z3ZkXwnxa4DPO899bsyIoywizdU | ||||
| github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= | ||||
| github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U= | ||||
| github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= | ||||
| github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8= | ||||
| github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs= | ||||
| github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c/go.mod h1:OmDBASR4679mdNQnz2pUhc2G8CO2JrUAVFDRBDP/hJE= | ||||
| github.com/power-devops/perfstat v0.0.0-20221212215047-62379fc7944b h1:0LFwY6Q3gMACTjAbMZBjXAqTOzOwFaj2Ld6cjeQ7Rig= | ||||
| github.com/power-devops/perfstat v0.0.0-20221212215047-62379fc7944b/go.mod h1:OmDBASR4679mdNQnz2pUhc2G8CO2JrUAVFDRBDP/hJE= | ||||
| github.com/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDNXVBh4M= | ||||
| github.com/rogpeppe/go-internal v1.11.0/go.mod h1:ddIwULY96R17DhadqLgMfk9H9tvdUzkipdSkR5nkCZA= | ||||
| github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= | ||||
| github.com/sagikazarmark/locafero v0.4.0 h1:HApY1R9zGo4DBgr7dqsTH/JJxLTTsOt7u6keLGt6kNQ= | ||||
| github.com/sagikazarmark/locafero v0.4.0/go.mod h1:Pe1W6UlPYUk/+wc/6KFhbORCfqzgYEpgQ3O5fPuL3H4= | ||||
| github.com/sagikazarmark/slog-shim v0.1.0 h1:diDBnUNK9N/354PgrxMywXnAwEr1QZcOr6gto+ugjYE= | ||||
| github.com/sagikazarmark/slog-shim v0.1.0/go.mod h1:SrcSrq8aKtyuqEI1uvTDTK1arOWRIczQRv+GVI1AkeQ= | ||||
| github.com/shirou/gopsutil/v3 v3.24.1 h1:R3t6ondCEvmARp3wxODhXMTLC/klMa87h2PHUw5m7QI= | ||||
| github.com/shirou/gopsutil/v3 v3.24.1/go.mod h1:UU7a2MSBQa+kW1uuDq8DeEBS8kmrnQwsv2b5O513rwU= | ||||
| github.com/shoenig/go-m1cpu v0.1.6 h1:nxdKQNcEB6vzgA2E2bvzKIYRuNj7XNJ4S/aRSwKzFtM= | ||||
| github.com/shoenig/go-m1cpu v0.1.6/go.mod h1:1JJMcUBvfNwpq05QDQVAnx3gUHr9IYF7GNg9SUEw2VQ= | ||||
| github.com/shoenig/test v0.6.4/go.mod h1:byHiCGXqrVaflBLAMq/srcZIHynQPQgeyvkvXnjqq0k= | ||||
| github.com/sourcegraph/conc v0.3.0 h1:OQTbbt6P72L20UqAkXXuLOj79LfEanQ+YQFNpLA9ySo= | ||||
| github.com/sourcegraph/conc v0.3.0/go.mod h1:Sdozi7LEKbFPqYX2/J+iBAM6HpqSLTASQIKqDmF7Mt0= | ||||
| github.com/spf13/afero v1.11.0 h1:WJQKhtpdm3v2IzqG8VMqrr6Rf3UYpEF239Jy9wNepM8= | ||||
| @@ -97,27 +134,79 @@ github.com/subosito/gotenv v1.6.0 h1:9NlTDc1FTs4qu0DDq7AEtTPNw6SVm7uBMsUCUjABIf8 | ||||
| github.com/subosito/gotenv v1.6.0/go.mod h1:Dk4QP5c2W3ibzajGcXpNraDfq2IrhjMIvMSWPKKo0FU= | ||||
| github.com/tilinna/clock v1.0.2 h1:6BO2tyAC9JbPExKH/z9zl44FLu1lImh3nDNKA0kgrkI= | ||||
| github.com/tilinna/clock v1.0.2/go.mod h1:ZsP7BcY7sEEz7ktc0IVy8Us6boDrK8VradlKRUGfOao= | ||||
| github.com/tklauser/go-sysconf v0.3.12/go.mod h1:Ho14jnntGE1fpdOqQEEaiKRpvIavV0hSfmBq8nJbHYI= | ||||
| github.com/tklauser/go-sysconf v0.3.13 h1:GBUpcahXSpR2xN01jhkNAbTLRk2Yzgggk8IM08lq3r4= | ||||
| github.com/tklauser/go-sysconf v0.3.13/go.mod h1:zwleP4Q4OehZHGn4CYZDipCgg9usW5IJePewFCGVEa0= | ||||
| github.com/tklauser/numcpus v0.6.1/go.mod h1:1XfjsgE2zo8GVw7POkMbHENHzVg3GzmoZ9fESEdAacY= | ||||
| github.com/tklauser/numcpus v0.7.0 h1:yjuerZP127QG9m5Zh/mSO4wqurYil27tHrqwRoRjpr4= | ||||
| github.com/tklauser/numcpus v0.7.0/go.mod h1:bb6dMVcj8A42tSE7i32fsIUCbQNllK5iDguyOZRUzAY= | ||||
| github.com/valyala/fastjson v1.6.4 h1:uAUNq9Z6ymTgGhcm0UynUAB6tlbakBrz6CQFax3BXVQ= | ||||
| github.com/valyala/fastjson v1.6.4/go.mod h1:CLCAqky6SMuOcxStkYQvblddUtoRxhYMGLrsQns1aXY= | ||||
| github.com/yusufpapurcu/wmi v1.2.3/go.mod h1:SBZ9tNy3G9/m5Oi98Zks0QjeHVDvuK0qfxQmPyzfmi0= | ||||
| github.com/yusufpapurcu/wmi v1.2.4 h1:zFUKzehAFReQwLys1b/iSMl+JQGSCSjtVqQn9bBrPo0= | ||||
| github.com/yusufpapurcu/wmi v1.2.4/go.mod h1:SBZ9tNy3G9/m5Oi98Zks0QjeHVDvuK0qfxQmPyzfmi0= | ||||
| go.opentelemetry.io/contrib/instrumentation/github.com/gorilla/mux/otelmux v0.48.0 h1:7rkdNoXgScpSUIqBch/VOB24fk9g0wl3Tr5WPtshi9o= | ||||
| go.opentelemetry.io/contrib/instrumentation/github.com/gorilla/mux/otelmux v0.48.0/go.mod h1:U3t9uswWhDzieXHMNWP6zk87J4HNondiibKMdNLpnMk= | ||||
| go.opentelemetry.io/contrib/instrumentation/host v0.48.0 h1:eVDLR/hletJcctz4rSWwb3QVzRnEQKuTVi6qAm7fsWs= | ||||
| go.opentelemetry.io/contrib/instrumentation/host v0.48.0/go.mod h1:dWSGvPpaGKwBh/dpLJs6pczyOc82hBnxa1YTQZCic0I= | ||||
| go.opentelemetry.io/contrib/instrumentation/runtime v0.48.0 h1:dJlCKeq+zmO5Og4kgxqPvvJrzuD/mygs1g/NYM9dAsU= | ||||
| go.opentelemetry.io/contrib/instrumentation/runtime v0.48.0/go.mod h1:p+hpBCpLHpuUrR0lHgnHbUnbCBll1IhrcMIlycC+xYs= | ||||
| go.opentelemetry.io/otel v1.23.1 h1:Za4UzOqJYS+MUczKI320AtqZHZb7EqxO00jAHE0jmQY= | ||||
| go.opentelemetry.io/otel v1.23.1/go.mod h1:Td0134eafDLcTS4y+zQ26GE8u3dEuRBiBCTUIRHaikA= | ||||
| go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp v1.23.1 h1:q/Nj5/2TZRIt6PderQ9oU0M00fzoe8UZuINGw6ETGTw= | ||||
| go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp v1.23.1/go.mod h1:DTE9yAu6r08jU3xa68GiSeI7oRcSEQ2RpKbbQGO+dWM= | ||||
| go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.23.1 h1:o8iWeVFa1BcLtVEV0LzrCxV2/55tB3xLxADr6Kyoey4= | ||||
| go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.23.1/go.mod h1:SEVfdK4IoBnbT2FXNM/k8yC08MrfbhWk3U4ljM8B3HE= | ||||
| go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.23.1 h1:cfuy3bXmLJS7M1RZmAL6SuhGtKUp2KEsrm00OlAXkq4= | ||||
| go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.23.1/go.mod h1:22jr92C6KwlwItJmQzfixzQM3oyyuYLCfHiMY+rpsPU= | ||||
| go.opentelemetry.io/otel/metric v1.23.1 h1:PQJmqJ9u2QaJLBOELl1cxIdPcpbwzbkjfEyelTl2rlo= | ||||
| go.opentelemetry.io/otel/metric v1.23.1/go.mod h1:mpG2QPlAfnK8yNhNJAxDZruU9Y1/HubbC+KyH8FaCWI= | ||||
| go.opentelemetry.io/otel/sdk v1.23.1 h1:O7JmZw0h76if63LQdsBMKQDWNb5oEcOThG9IrxscV+E= | ||||
| go.opentelemetry.io/otel/sdk v1.23.1/go.mod h1:LzdEVR5am1uKOOwfBWFef2DCi1nu3SA8XQxx2IerWFk= | ||||
| go.opentelemetry.io/otel/sdk/metric v1.23.1 h1:T9/8WsYg+ZqIpMWwdISVVrlGb/N0Jr1OHjR/alpKwzg= | ||||
| go.opentelemetry.io/otel/sdk/metric v1.23.1/go.mod h1:8WX6WnNtHCgUruJ4TJ+UssQjMtpxkpX0zveQC8JG/E0= | ||||
| go.opentelemetry.io/otel/trace v1.23.1 h1:4LrmmEd8AU2rFvU1zegmvqW7+kWarxtNOPyeL6HmYY8= | ||||
| go.opentelemetry.io/otel/trace v1.23.1/go.mod h1:4IpnpJFwr1mo/6HL8XIPJaE9y0+u1KcVmuW7dwFSVrI= | ||||
| go.opentelemetry.io/proto/otlp v1.1.0 h1:2Di21piLrCqJ3U3eXGCTPHE9R8Nh+0uglSnOyxikMeI= | ||||
| go.opentelemetry.io/proto/otlp v1.1.0/go.mod h1:GpBHCBWiqvVLDqmHZsoMM3C5ySeKTC7ej/RNTae6MdY= | ||||
| go.uber.org/goleak v1.2.1 h1:NBol2c7O1ZokfZ0LEU9K6Whx/KnwvepVetCUhtKja4A= | ||||
| go.uber.org/goleak v1.2.1/go.mod h1:qlT2yGI9QafXHhZZLxlSuNsMw3FFLxBr+tBRlmO1xH4= | ||||
| go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0= | ||||
| go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y= | ||||
| golang.org/x/crypto v0.16.0 h1:mMMrFzRSCF0GvB7Ne27XVtVAaXLrPmgPC7/v0tkwHaY= | ||||
| golang.org/x/crypto v0.16.0/go.mod h1:gCAAfMLgwOJRpTjQ2zCCt2OcSfYMTeZVSRtQlPC7Nq4= | ||||
| golang.org/x/crypto v0.19.0 h1:ENy+Az/9Y1vSrlrvBSyna3PITt4tiZLf7sgCjZBX7Wo= | ||||
| golang.org/x/crypto v0.19.0/go.mod h1:Iy9bg/ha4yyC70EfRS8jz+B6ybOBKMaSxLj6P6oBDfU= | ||||
| golang.org/x/exp v0.0.0-20231206192017-f3f8817b8deb h1:c0vyKkb6yr3KR7jEfJaOSv4lG7xPkbN6r52aJz1d8a8= | ||||
| golang.org/x/exp v0.0.0-20231206192017-f3f8817b8deb/go.mod h1:iRJReGqOEeBhDZGkGbynYwcHlctCvnjTYIamk7uXpHI= | ||||
| golang.org/x/net v0.19.0 h1:zTwKpTd2XuCqf8huc7Fo2iSy+4RHPd10s4KzeTnVr1c= | ||||
| golang.org/x/net v0.19.0/go.mod h1:CfAk/cbD4CthTvqiEl8NpboMuiuOYsAr/7NOjZJtv1U= | ||||
| golang.org/x/net v0.21.0 h1:AQyQV4dYCvJ7vGmJyKki9+PBdyvhkSd8EIx/qb0AYv4= | ||||
| golang.org/x/net v0.21.0/go.mod h1:bIjVDfnllIU7BJ2DNgfnXvpSvtn8VRwhlsaeUTyUS44= | ||||
| golang.org/x/sync v0.5.0 h1:60k92dhOjHxJkrqnwsfl8KuaHbn/5dl0lUPUklKo3qE= | ||||
| golang.org/x/sync v0.5.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= | ||||
| golang.org/x/sys v0.15.0 h1:h48lPFYpsTvQJZF4EKyI4aLHaev3CxivZmv7yZig9pc= | ||||
| golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= | ||||
| golang.org/x/sys v0.0.0-20190916202348-b4ddaad3f8a3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= | ||||
| golang.org/x/sys v0.0.0-20201204225414-ed752295db88/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= | ||||
| golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= | ||||
| golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= | ||||
| golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= | ||||
| golang.org/x/sys v0.16.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= | ||||
| golang.org/x/sys v0.17.0 h1:25cE3gD+tdBA7lp7QfhuV+rJiE9YXTcS3VG1SqssI/Y= | ||||
| golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= | ||||
| golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= | ||||
| golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= | ||||
| golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= | ||||
| google.golang.org/genproto v0.0.0-20240125205218-1f4bbc51befe h1:USL2DhxfgRchafRvt/wYyyQNzwgL7ZiURcozOE/Pkvo= | ||||
| google.golang.org/genproto v0.0.0-20240125205218-1f4bbc51befe/go.mod h1:cc8bqMqtv9gMOr0zHg2Vzff5ULhhL2IXP4sbcn32Dro= | ||||
| google.golang.org/genproto/googleapis/api v0.0.0-20240205150955-31a09d347014 h1:x9PwdEgd11LgK+orcck69WVRo7DezSO4VUMPI4xpc8A= | ||||
| google.golang.org/genproto/googleapis/api v0.0.0-20240205150955-31a09d347014/go.mod h1:rbHMSEDyoYX62nRVLOCc4Qt1HbsdytAYoVwgjiOhF3I= | ||||
| google.golang.org/genproto/googleapis/rpc v0.0.0-20240205150955-31a09d347014 h1:FSL3lRCkhaPFxqi0s9o+V4UI2WTzAVOvkgbd4kVV4Wg= | ||||
| google.golang.org/genproto/googleapis/rpc v0.0.0-20240205150955-31a09d347014/go.mod h1:SaPjaZGWb0lPqs6Ittu0spdfrOArqji4ZdeP5IC/9N4= | ||||
| google.golang.org/grpc v1.61.0 h1:TOvOcuXn30kRao+gfcvsebNEa5iZIiLkisYEkf7R7o0= | ||||
| google.golang.org/grpc v1.61.0/go.mod h1:VUbo7IFqmF1QtCAstipjG0GIoq49KvMe9+h1jFLBNJs= | ||||
| google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= | ||||
| google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= | ||||
| google.golang.org/protobuf v1.32.0 h1:pPC6BG5ex8PDFnkbrGU3EixyhKcQ2aDuBS36lqK/C7I= | ||||
| google.golang.org/protobuf v1.32.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos= | ||||
| gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= | ||||
| gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo= | ||||
| gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= | ||||
| gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= | ||||
| gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= | ||||
| gopkg.in/ini.v1 v1.67.0 h1:Dgnx+6+nfE+IfzjUEISNeydPJh9AXNNsWbGP9KzCsOA= | ||||
| gopkg.in/ini.v1 v1.67.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= | ||||
| gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= | ||||
|   | ||||
| @@ -8,7 +8,6 @@ import ( | ||||
| 	"github.com/spf13/viper" | ||||
|  | ||||
| 	"ely.by/chrly/internal/di" | ||||
| 	"ely.by/chrly/internal/http" | ||||
| 	"ely.by/chrly/internal/version" | ||||
| ) | ||||
|  | ||||
| @@ -27,25 +26,6 @@ func shouldGetContainer() *Container { | ||||
| 	return container | ||||
| } | ||||
|  | ||||
| func startServer(modules ...string) error { | ||||
| 	container := shouldGetContainer() | ||||
|  | ||||
| 	var config *viper.Viper | ||||
| 	err := container.Resolve(&config) | ||||
| 	if err != nil { | ||||
| 		return err | ||||
| 	} | ||||
|  | ||||
| 	config.Set("modules", modules) | ||||
|  | ||||
| 	err = container.Invoke(http.StartServer) | ||||
| 	if err != nil { | ||||
| 		return err | ||||
| 	} | ||||
|  | ||||
| 	return nil | ||||
| } | ||||
|  | ||||
| func init() { | ||||
| 	cobra.OnInitialize(initConfig) | ||||
| } | ||||
|   | ||||
| @@ -1,7 +1,14 @@ | ||||
| package cmd | ||||
|  | ||||
| import ( | ||||
| 	"context" | ||||
| 	"log/slog" | ||||
|  | ||||
| 	"github.com/spf13/cobra" | ||||
| 	"github.com/spf13/viper" | ||||
|  | ||||
| 	"ely.by/chrly/internal/http" | ||||
| 	"ely.by/chrly/internal/otel" | ||||
| ) | ||||
|  | ||||
| var serveCmd = &cobra.Command{ | ||||
| @@ -15,3 +22,39 @@ var serveCmd = &cobra.Command{ | ||||
| func init() { | ||||
| 	RootCmd.AddCommand(serveCmd) | ||||
| } | ||||
|  | ||||
| func startServer(modules ...string) error { | ||||
| 	container := shouldGetContainer() | ||||
|  | ||||
| 	var globalCtx context.Context | ||||
| 	err := container.Resolve(&globalCtx) | ||||
| 	if err != nil { | ||||
| 		return err | ||||
| 	} | ||||
|  | ||||
| 	shutdownOtel, err := otel.SetupOTelSDK(globalCtx) | ||||
| 	defer func() { | ||||
| 		err := shutdownOtel(context.Background()) | ||||
| 		if err != nil { | ||||
| 			slog.Error("Unable to shutdown OpenTelemetry", slog.Any("error", err)) | ||||
| 		} | ||||
| 	}() | ||||
| 	if err != nil { | ||||
| 		return err | ||||
| 	} | ||||
|  | ||||
| 	var config *viper.Viper | ||||
| 	err = container.Resolve(&config) | ||||
| 	if err != nil { | ||||
| 		return err | ||||
| 	} | ||||
|  | ||||
| 	config.Set("modules", modules) | ||||
|  | ||||
| 	err = container.Invoke(http.StartServer) | ||||
| 	if err != nil { | ||||
| 		return err | ||||
| 	} | ||||
|  | ||||
| 	return nil | ||||
| } | ||||
|   | ||||
							
								
								
									
										21
									
								
								internal/di/context.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										21
									
								
								internal/di/context.go
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,21 @@ | ||||
| package di | ||||
|  | ||||
| import ( | ||||
| 	"context" | ||||
| 	"os" | ||||
| 	"os/signal" | ||||
| 	"syscall" | ||||
|  | ||||
| 	"github.com/defval/di" | ||||
| ) | ||||
|  | ||||
| var contextDiOptions = di.Options( | ||||
| 	di.Provide(newBaseContext), | ||||
| ) | ||||
|  | ||||
| func newBaseContext() context.Context { | ||||
| 	ctx := context.Background() | ||||
| 	ctx, _ = signal.NotifyContext(ctx, os.Interrupt, syscall.SIGTERM, os.Kill) | ||||
|  | ||||
| 	return ctx | ||||
| } | ||||
| @@ -16,7 +16,7 @@ import ( | ||||
|  | ||||
| // Since there are no options for selecting target backends, | ||||
| // all constants in this case point to static specific implementations. | ||||
| var dbDeOptions = di.Options( | ||||
| var dbDiOptions = di.Options( | ||||
| 	di.Provide(newRedis, | ||||
| 		di.As(new(profiles.ProfilesRepository)), | ||||
| 		di.As(new(profiles.ProfilesFinder)), | ||||
| @@ -24,13 +24,13 @@ var dbDeOptions = di.Options( | ||||
| 	), | ||||
| ) | ||||
|  | ||||
| func newRedis(container *di.Container, config *viper.Viper) (*redis.Redis, error) { | ||||
| func newRedis(container *di.Container, ctx context.Context, config *viper.Viper) (*redis.Redis, error) { | ||||
| 	config.SetDefault("storage.redis.host", "localhost") | ||||
| 	config.SetDefault("storage.redis.port", 6379) | ||||
| 	config.SetDefault("storage.redis.poolSize", 10) | ||||
|  | ||||
| 	conn, err := redis.New( | ||||
| 		context.Background(), | ||||
| 		ctx, | ||||
| 		db.NewZlibEncoder(&db.JsonSerializer{}), | ||||
| 		fmt.Sprintf("%s:%d", config.GetString("storage.redis.host"), config.GetInt("storage.redis.port")), | ||||
| 		config.GetInt("storage.redis.poolSize"), | ||||
|   | ||||
| @@ -5,12 +5,13 @@ import "github.com/defval/di" | ||||
| func New() (*di.Container, error) { | ||||
| 	return di.New( | ||||
| 		configDiOptions, | ||||
| 		loggerDiOptions, | ||||
| 		dbDeOptions, | ||||
| 		mojangDiOptions, | ||||
| 		contextDiOptions, | ||||
| 		dbDiOptions, | ||||
| 		handlersDiOptions, | ||||
| 		loggerDiOptions, | ||||
| 		mojangDiOptions, | ||||
| 		profilesDiOptions, | ||||
| 		serverDiOptions, | ||||
| 		securityDiOptions, | ||||
| 		serverDiOptions, | ||||
| 	) | ||||
| } | ||||
|   | ||||
| @@ -9,6 +9,7 @@ import ( | ||||
| 	"github.com/etherlabsio/healthcheck/v2" | ||||
| 	"github.com/gorilla/mux" | ||||
| 	"github.com/spf13/viper" | ||||
| 	"go.opentelemetry.io/contrib/instrumentation/github.com/gorilla/mux/otelmux" | ||||
|  | ||||
| 	. "ely.by/chrly/internal/http" | ||||
| ) | ||||
| @@ -39,6 +40,7 @@ func newHandlerFactory( | ||||
| 	} | ||||
|  | ||||
| 	router.StrictSlash(true) | ||||
| 	router.Use(otelmux.Middleware("chrly")) | ||||
| 	router.NotFoundHandler = http.HandlerFunc(NotFoundHandler) | ||||
|  | ||||
| 	if slices.Contains(enabledModules, "api") { | ||||
|   | ||||
| @@ -8,7 +8,6 @@ import ( | ||||
| 	"time" | ||||
|  | ||||
| 	"github.com/defval/di" | ||||
| 	"github.com/getsentry/raven-go" | ||||
| 	"github.com/spf13/viper" | ||||
|  | ||||
| 	. "ely.by/chrly/internal/http" | ||||
| @@ -29,41 +28,22 @@ func newAuthenticator(config *viper.Viper) (*security.Jwt, error) { | ||||
| 	return security.NewJwt([]byte(key)), nil | ||||
| } | ||||
|  | ||||
| type serverParams struct { | ||||
| 	di.Inject | ||||
| func newServer(Config *viper.Viper, Handler http.Handler) *http.Server { | ||||
| 	Config.SetDefault("server.host", "") | ||||
| 	Config.SetDefault("server.port", 80) | ||||
|  | ||||
| 	Config  *viper.Viper  `di:""` | ||||
| 	Handler http.Handler  `di:""` | ||||
| 	Sentry  *raven.Client `di:"" optional:"true"` | ||||
| } | ||||
| 	var handler http.Handler = http.HandlerFunc(func(request http.ResponseWriter, response *http.Request) { | ||||
| 		defer func() { | ||||
| 			if recovered := recover(); recovered != nil { | ||||
| 				debug.PrintStack() | ||||
| 				request.WriteHeader(http.StatusInternalServerError) | ||||
| 			} | ||||
| 		}() | ||||
|  | ||||
| func newServer(params serverParams) *http.Server { | ||||
| 	params.Config.SetDefault("server.host", "") | ||||
| 	params.Config.SetDefault("server.port", 80) | ||||
| 		Handler.ServeHTTP(request, response) | ||||
| 	}) | ||||
|  | ||||
| 	var handler http.Handler | ||||
| 	if params.Sentry != nil { | ||||
| 		// raven.Recoverer uses DefaultClient and nothing can be done about it | ||||
| 		// To avoid code duplication, if the Sentry service is successfully initiated, | ||||
| 		// it will also replace DefaultClient, so raven.Recoverer will work with the instance | ||||
| 		// created in the application constructor | ||||
| 		handler = raven.Recoverer(params.Handler) | ||||
| 	} else { | ||||
| 		// Raven's Recoverer is prints the stacktrace and sets the corresponding status itself. | ||||
| 		// But there is no magic and if you don't define a panic handler, Mux will just reset the connection | ||||
| 		handler = http.HandlerFunc(func(request http.ResponseWriter, response *http.Request) { | ||||
| 			defer func() { | ||||
| 				if recovered := recover(); recovered != nil { | ||||
| 					debug.PrintStack() // TODO: colorize output | ||||
| 					request.WriteHeader(http.StatusInternalServerError) | ||||
| 				} | ||||
| 			}() | ||||
|  | ||||
| 			params.Handler.ServeHTTP(request, response) | ||||
| 		}) | ||||
| 	} | ||||
|  | ||||
| 	address := fmt.Sprintf("%s:%d", params.Config.GetString("server.host"), params.Config.GetInt("server.port")) | ||||
| 	address := fmt.Sprintf("%s:%d", Config.GetString("server.host"), Config.GetInt("server.port")) | ||||
| 	server := &http.Server{ | ||||
| 		Addr:           address, | ||||
| 		ReadTimeout:    5 * time.Second, | ||||
|   | ||||
| @@ -3,10 +3,8 @@ package http | ||||
| import ( | ||||
| 	"context" | ||||
| 	"encoding/json" | ||||
| 	"log/slog" | ||||
| 	"net/http" | ||||
| 	"os" | ||||
| 	"os/signal" | ||||
| 	"syscall" | ||||
| 	"time" | ||||
|  | ||||
| 	"github.com/gorilla/mux" | ||||
| @@ -16,11 +14,8 @@ import ( | ||||
| 	"ely.by/chrly/internal/version" | ||||
| ) | ||||
|  | ||||
| func StartServer(server *http.Server, logger slf.Logger) { | ||||
| 	logger.Debug("Chrly :v (:c)", wd.StringParam("v", version.Version()), wd.StringParam("c", version.Commit())) | ||||
|  | ||||
| 	ctx, cancel := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM, os.Kill) | ||||
| 	defer cancel() | ||||
| func StartServer(ctx context.Context, server *http.Server, logger slf.Logger) { | ||||
| 	slog.Debug("Chrly :v (:c)", slog.String("v", version.Version()), slog.String("c", version.Commit())) | ||||
|  | ||||
| 	srvErr := make(chan error, 1) | ||||
| 	go func() { | ||||
|   | ||||
							
								
								
									
										164
									
								
								internal/otel/setup.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										164
									
								
								internal/otel/setup.go
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,164 @@ | ||||
| package otel | ||||
|  | ||||
| import ( | ||||
| 	"context" | ||||
| 	"errors" | ||||
| 	"log/slog" | ||||
| 	"time" | ||||
|  | ||||
| 	"github.com/agoda-com/opentelemetry-go/otelslog" | ||||
| 	logsOtel "github.com/agoda-com/opentelemetry-logs-go" | ||||
| 	"github.com/agoda-com/opentelemetry-logs-go/exporters/otlp/otlplogs" | ||||
| 	"github.com/agoda-com/opentelemetry-logs-go/sdk/logs" | ||||
| 	logsSdk "github.com/agoda-com/opentelemetry-logs-go/sdk/logs" | ||||
| 	runtimeMetrics "go.opentelemetry.io/contrib/instrumentation/runtime" | ||||
| 	"go.opentelemetry.io/otel" | ||||
| 	"go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp" | ||||
| 	"go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp" | ||||
| 	"go.opentelemetry.io/otel/propagation" | ||||
| 	"go.opentelemetry.io/otel/sdk/metric" | ||||
| 	"go.opentelemetry.io/otel/sdk/resource" | ||||
| 	"go.opentelemetry.io/otel/sdk/trace" | ||||
| 	"go.opentelemetry.io/otel/semconv/v1.4.0" | ||||
|  | ||||
| 	"ely.by/chrly/internal/version" | ||||
| ) | ||||
|  | ||||
| func SetupOTelSDK(ctx context.Context) (shutdown func(context.Context) error, err error) { | ||||
| 	var shutdownFuncs []func(context.Context) error | ||||
|  | ||||
| 	// shutdown calls cleanup functions registered via shutdownFuncs. | ||||
| 	// The errors from the calls are joined. | ||||
| 	// Each registered cleanup will be invoked once | ||||
| 	shutdown = func(ctx context.Context) error { | ||||
| 		var err error | ||||
| 		for _, fn := range shutdownFuncs { | ||||
| 			err = errors.Join(err, fn(ctx)) | ||||
| 		} | ||||
|  | ||||
| 		shutdownFuncs = nil | ||||
|  | ||||
| 		return err | ||||
| 	} | ||||
|  | ||||
| 	// handleErr calls shutdown for cleanup and makes sure that all errors are returned | ||||
| 	handleErr := func(inErr error) { | ||||
| 		err = errors.Join(inErr, shutdown(ctx)) | ||||
| 	} | ||||
|  | ||||
| 	// Set up propagator | ||||
| 	prop := newPropagator() | ||||
| 	otel.SetTextMapPropagator(prop) | ||||
|  | ||||
| 	// Set up resource | ||||
| 	res, err := newResource(ctx) | ||||
| 	if err != nil { | ||||
| 		handleErr(err) | ||||
| 		return | ||||
| 	} | ||||
|  | ||||
| 	// Set up logs provider | ||||
| 	logsProvider, err := newLoggerProvider(ctx, res) | ||||
| 	if err != nil { | ||||
| 		handleErr(err) | ||||
| 		return | ||||
| 	} | ||||
|  | ||||
| 	shutdownFuncs = append(shutdownFuncs, logsProvider.Shutdown) | ||||
| 	logsOtel.SetLoggerProvider(logsProvider) | ||||
|  | ||||
| 	otelSlog := slog.New(otelslog.NewOtelHandler(logsProvider, &otelslog.HandlerOptions{Level: slog.LevelDebug})) | ||||
| 	slog.SetDefault(otelSlog) | ||||
|  | ||||
| 	// Set up trace provider | ||||
| 	tracerProvider, err := newTraceProvider(ctx, res) | ||||
| 	if err != nil { | ||||
| 		handleErr(err) | ||||
| 		return | ||||
| 	} | ||||
|  | ||||
| 	shutdownFuncs = append(shutdownFuncs, tracerProvider.Shutdown) | ||||
| 	otel.SetTracerProvider(tracerProvider) | ||||
|  | ||||
| 	// Set up meter provider | ||||
| 	meterProvider, err := newMeterProvider(ctx, res) | ||||
| 	if err != nil { | ||||
| 		handleErr(err) | ||||
| 		return | ||||
| 	} | ||||
|  | ||||
| 	shutdownFuncs = append(shutdownFuncs, meterProvider.Shutdown) | ||||
| 	otel.SetMeterProvider(meterProvider) | ||||
|  | ||||
| 	err = runtimeMetrics.Start(runtimeMetrics.WithMinimumReadMemStatsInterval(time.Second)) | ||||
| 	if err != nil { | ||||
| 		handleErr(err) | ||||
| 		return | ||||
| 	} | ||||
|  | ||||
| 	return | ||||
| } | ||||
|  | ||||
| func newPropagator() propagation.TextMapPropagator { | ||||
| 	return propagation.NewCompositeTextMapPropagator( | ||||
| 		propagation.TraceContext{}, | ||||
| 		propagation.Baggage{}, | ||||
| 	) | ||||
| } | ||||
|  | ||||
| func newResource(ctx context.Context) (*resource.Resource, error) { | ||||
| 	return resource.New( | ||||
| 		ctx, | ||||
| 		resource.WithFromEnv(), | ||||
| 		resource.WithTelemetrySDK(), | ||||
| 		resource.WithOS(), | ||||
| 		resource.WithContainer(), | ||||
| 		resource.WithHost(), | ||||
| 		resource.WithAttributes( | ||||
| 			semconv.ServiceNameKey.String("chrly"), | ||||
| 			semconv.ServiceVersionKey.String(version.Version()), | ||||
| 		), | ||||
| 	) | ||||
| } | ||||
|  | ||||
| func newLoggerProvider(ctx context.Context, res *resource.Resource) (*logs.LoggerProvider, error) { | ||||
| 	exporter, err := otlplogs.NewExporter(ctx) | ||||
| 	if err != nil { | ||||
| 		return nil, err | ||||
| 	} | ||||
|  | ||||
| 	loggerProvider := logsSdk.NewLoggerProvider( | ||||
| 		logsSdk.WithBatcher(exporter), | ||||
| 		logsSdk.WithResource(res), | ||||
| 	) | ||||
|  | ||||
| 	return loggerProvider, nil | ||||
| } | ||||
|  | ||||
| func newTraceProvider(ctx context.Context, res *resource.Resource) (*trace.TracerProvider, error) { | ||||
| 	traceExporter, err := otlptracehttp.New(ctx) | ||||
| 	if err != nil { | ||||
| 		return nil, err | ||||
| 	} | ||||
|  | ||||
| 	traceProvider := trace.NewTracerProvider( | ||||
| 		trace.WithResource(res), | ||||
| 		trace.WithBatcher(traceExporter), | ||||
| 	) | ||||
|  | ||||
| 	return traceProvider, nil | ||||
| } | ||||
|  | ||||
| func newMeterProvider(ctx context.Context, res *resource.Resource) (*metric.MeterProvider, error) { | ||||
| 	metricExporter, err := otlpmetrichttp.New(ctx) | ||||
| 	if err != nil { | ||||
| 		return nil, err | ||||
| 	} | ||||
|  | ||||
| 	meterProvider := metric.NewMeterProvider( | ||||
| 		metric.WithResource(res), | ||||
| 		metric.WithReader(metric.NewPeriodicReader(metricExporter)), | ||||
| 	) | ||||
|  | ||||
| 	return meterProvider, nil | ||||
| } | ||||
		Reference in New Issue
	
	Block a user