Open-source status page, incident response and uptime monitoring
TypeScript alertingincident-managementmcpmcp-servermonitoringmonitoring-as-codeobservabilityon-callopen-sourcesrestatus-pagestatuspagesynthetic-monitoringterraformtinybirdtursouptimeuptime-checkeruptime-monitor
🔥 Otel implemenation (#1181)
Thibault Le Ouay881e2854fa4a
diff --git a/apps/checker/README.md b/apps/checker/README.mdindex a1de12e9c..d67e319f4 100644--- a/apps/checker/README.md+++ b/apps/checker/README.md@@ -7,7 +7,15 @@ It pings the service and save thedata to the tinybird## How to run```bash-go run *.go+go run cmd/main.go+```++you can also set the env variable++```fish+set CRON_SECRET YOLO+set CLOUD_PROVIDER local+set TINYBIRD_TOKEN random```## How to build@@ -39,4 +47,4 @@ fly scale count 35 --region ams,arn,atl,bog,bom,bos,cdg,den,dfw,ewr,eze,fra,gdUse our docker image-https://github.com/openstatusHQ/openstatus/pkgs/container/checker+<https://github.com/openstatusHQ/openstatus/pkgs/container/checker>diff --git a/apps/checker/go.mod b/apps/checker/go.modindex cc5ddd527..aaf2050be 100644--- a/apps/checker/go.mod+++ b/apps/checker/go.mod@@ -1,13 +1,14 @@module github.com/openstatushq/openstatus/apps/checker-go 1.22+go 1.22.0++toolchain go1.23.5require (- github.com/WilfredAlmeida/unkey-go v0.2.0github.com/cenkalti/backoff/v4 v4.3.0github.com/gin-gonic/gin v1.9.1github.com/rs/zerolog v1.32.0- github.com/stretchr/testify v1.9.0+ github.com/stretchr/testify v1.10.0)require (@@ -17,11 +18,15 @@ require (github.com/davecgh/go-spew v1.1.1 // indirectgithub.com/gabriel-vasile/mimetype v1.4.3 // indirectgithub.com/gin-contrib/sse v0.1.0 // indirect+ github.com/go-logr/logr v1.4.2 // indirect+ github.com/go-logr/stdr v1.2.2 // indirectgithub.com/go-playground/locales v0.14.1 // indirectgithub.com/go-playground/universal-translator v0.18.1 // indirectgithub.com/go-playground/validator/v10 v10.19.0 // indirectgithub.com/goccy/go-json v0.10.2 // indirectgithub.com/google/go-cmp v0.6.0 // indirect+ github.com/google/uuid v1.6.0 // indirect+ github.com/grpc-ecosystem/grpc-gateway/v2 v2.25.1 // indirectgithub.com/json-iterator/go v1.1.12 // indirectgithub.com/klauspost/cpuid/v2 v2.2.7 // indirectgithub.com/leodido/go-urn v1.4.0 // indirect@@ -33,11 +38,24 @@ require (github.com/pmezard/go-difflib v1.0.0 // indirectgithub.com/twitchyliquid64/golang-asm v0.15.1 // indirectgithub.com/ugorji/go/codec v1.2.12 // indirect+ go.opentelemetry.io/auto/sdk v1.1.0 // indirect+ go.opentelemetry.io/otel v1.34.0 // indirect+ go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc v1.34.0 // indirect+ go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp v1.34.0 // indirect+ go.opentelemetry.io/otel/exporters/stdout/stdoutmetric v1.34.0 // indirect+ go.opentelemetry.io/otel/metric v1.34.0 // indirect+ go.opentelemetry.io/otel/sdk v1.34.0 // indirect+ go.opentelemetry.io/otel/sdk/metric v1.34.0 // indirect+ go.opentelemetry.io/otel/trace v1.34.0 // indirect+ go.opentelemetry.io/proto/otlp v1.5.0 // indirectgolang.org/x/arch v0.7.0 // indirect- golang.org/x/crypto v0.21.0 // indirect- golang.org/x/net v0.22.0 // indirect- golang.org/x/sys v0.18.0 // indirect- golang.org/x/text v0.14.0 // indirect- google.golang.org/protobuf v1.33.0 // indirect+ golang.org/x/crypto v0.32.0 // indirect+ golang.org/x/net v0.34.0 // indirect+ golang.org/x/sys v0.29.0 // indirect+ golang.org/x/text v0.21.0 // indirect+ google.golang.org/genproto/googleapis/api v0.0.0-20250115164207-1a7da9e5054f // indirect+ google.golang.org/genproto/googleapis/rpc v0.0.0-20250115164207-1a7da9e5054f // indirect+ google.golang.org/grpc v1.69.4 // indirect+ google.golang.org/protobuf v1.36.3 // indirectgopkg.in/yaml.v3 v3.0.1 // indirect)diff --git a/apps/checker/go.sum b/apps/checker/go.sumindex 006cfce18..3fc56435b 100644--- a/apps/checker/go.sum+++ b/apps/checker/go.sum@@ -1,5 +1,3 @@-github.com/WilfredAlmeida/unkey-go v0.2.0 h1:WnPDbfrwgiI2uZQmFhSATY5Q1FU8NCGtQ+h1VjJWfoI=-github.com/WilfredAlmeida/unkey-go v0.2.0/go.mod h1:KZZ52al64FQUnWx0Zf2fIFmZvznwUiHqIg0nak/BGMw=github.com/bytedance/sonic v1.5.0/go.mod h1:ED5hyg4y6t3/9Ku1R6dU/4KyJ48DZ4jPhfY1O2AihPM=github.com/bytedance/sonic v1.10.0-rc/go.mod h1:ElCzW+ufi8qKqNW0FY314xriJhyJhuoJ3gFZdAHF7NM=github.com/bytedance/sonic v1.11.3 h1:jRN+yEjakWh8aK5FzrciUHG8OFXK+4/KrAX/ysEtHAA=@@ -23,6 +21,11 @@ github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qEgithub.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI=github.com/gin-gonic/gin v1.9.1 h1:4idEAncQnU5cB7BeOkPtxjfCSye0AAm1R0RVIqJ+Jmg=github.com/gin-gonic/gin v1.9.1/go.mod h1:hPrL7YrpYKXt5YId3A/Tnip5kqbEAP+KLuI3SUcPTeU=+github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=+github.com/go-logr/logr v1.4.2 h1:6pFjapn8bFcIbiKo3XT4j/BhANplGihG6tvd+8rYgrY=+github.com/go-logr/logr v1.4.2/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-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=@@ -37,8 +40,10 @@ github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xgithub.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/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=-github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=-github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=+github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=+github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=+github.com/grpc-ecosystem/grpc-gateway/v2 v2.25.1 h1:VNqngBF40hVlDloBruUehVYC3ArSgIyScOAyMRqBxRg=+github.com/grpc-ecosystem/grpc-gateway/v2 v2.25.1/go.mod h1:RBRO7fro65R6tjKzYgLAFo0t1QEXY1Dp+i/bvpRiqiQ=github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg=@@ -78,27 +83,65 @@ github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29ogithub.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=+github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=+github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS4MhqMhdFk5YI=github.com/twitchyliquid64/golang-asm v0.15.1/go.mod h1:a1lVb/DtPvCB8fslRZhAngC2+aY1QWCk3Cedj/Gdt08=github.com/ugorji/go/codec v1.2.12 h1:9LC83zGrHhuUA9l16C9AHXAqEV/2wBQ4nkvumAE65EE=github.com/ugorji/go/codec v1.2.12/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZgYf6w6lg=+go.opentelemetry.io/auto/sdk v1.1.0 h1:cH53jehLUN6UFLY71z+NDOiNJqDdPRaXzTel0sJySYA=+go.opentelemetry.io/auto/sdk v1.1.0/go.mod h1:3wSPjt5PWp2RhlCcmmOial7AvC4DQqZb7a7wCow3W8A=+go.opentelemetry.io/otel v1.34.0 h1:zRLXxLCgL1WyKsPVrgbSdMN4c0FMkDAskSTQP+0hdUY=+go.opentelemetry.io/otel v1.34.0/go.mod h1:OWFPOQ+h4G8xpyjgqo4SxJYdDQ/qmRH+wivy7zzx9oI=+go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc v1.34.0 h1:ajl4QczuJVA2TU9W9AGw++86Xga/RKt//16z/yxPgdk=+go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc v1.34.0/go.mod h1:Vn3/rlOJ3ntf/Q3zAI0V5lDnTbHGaUsNUeF6nZmm7pA=+go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp v1.34.0 h1:opwv08VbCZ8iecIWs+McMdHRcAXzjAeda3uG2kI/hcA=+go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp v1.34.0/go.mod h1:oOP3ABpW7vFHulLpE8aYtNBodrHhMTrvfxUXGvqm7Ac=+go.opentelemetry.io/otel/exporters/stdout/stdoutmetric v1.34.0 h1:czJDQwFrMbOr9Kk+BPo1y8WZIIFIK58SA1kykuVeiOU=+go.opentelemetry.io/otel/exporters/stdout/stdoutmetric v1.34.0/go.mod h1:lT7bmsxOe58Tq+JIOkTQMCGXdu47oA+VJKLZHbaBKbs=+go.opentelemetry.io/otel/metric v1.34.0 h1:+eTR3U0MyfWjRDhmFMxe2SsW64QrZ84AOhvqS7Y+PoQ=+go.opentelemetry.io/otel/metric v1.34.0/go.mod h1:CEDrp0fy2D0MvkXE+dPV7cMi8tWZwX3dmaIhwPOaqHE=+go.opentelemetry.io/otel/sdk v1.34.0 h1:95zS4k/2GOy069d321O8jWgYsW3MzVV+KuSPKp7Wr1A=+go.opentelemetry.io/otel/sdk v1.34.0/go.mod h1:0e/pNiaMAqaykJGKbi+tSjWfNNHMTxoC9qANsCzbyxU=+go.opentelemetry.io/otel/sdk/metric v1.34.0 h1:5CeK9ujjbFVL5c1PhLuStg1wxA7vQv7ce1EK0Gyvahk=+go.opentelemetry.io/otel/sdk/metric v1.34.0/go.mod h1:jQ/r8Ze28zRKoNRdkjCZxfs6YvBTG1+YIqyFVFYec5w=+go.opentelemetry.io/otel/trace v1.34.0 h1:+ouXS2V8Rd4hp4580a8q23bg0azF2nI8cqLYnC8mh/k=+go.opentelemetry.io/otel/trace v1.34.0/go.mod h1:Svm7lSjQD7kG7KJ/MUHPVXSDGz2OX4h0M2jHBhmSfRE=+go.opentelemetry.io/proto/otlp v1.5.0 h1:xJvq7gMzB31/d406fB8U5CBdyQGw4P399D1aQWU/3i4=+go.opentelemetry.io/proto/otlp v1.5.0/go.mod h1:keN8WnHxOy8PG0rQZjJJ5A2ebUoafqWp0eVQ4yIXvJ4=golang.org/x/arch v0.0.0-20210923205945-b76863e36670/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8=golang.org/x/arch v0.7.0 h1:pskyeJh/3AmoQ8CPE95vxHLqp1G1GfGNXTmcl9NEKTc=golang.org/x/arch v0.7.0/go.mod h1:FEVrYAQjsQXMVJ1nsMoVVXPZg6p2JE2mx8psSWTDQys=golang.org/x/crypto v0.21.0 h1:X31++rzVUdKhX5sWmSOFZxx8UW/ldWx55cbf08iNAMA=golang.org/x/crypto v0.21.0/go.mod h1:0BP7YvVV9gBbVKyeTG0Gyn+gZm94bibOW5BjDEYAOMs=+golang.org/x/crypto v0.32.0 h1:euUpcYgM8WcP71gNpTqQCn6rC2t6ULUPiOzfWaXVVfc=+golang.org/x/crypto v0.32.0/go.mod h1:ZnnJkOaASj8g0AjIduWNlq2NRxL0PlBrbKVyZ6V/Ugc=golang.org/x/net v0.22.0 h1:9sGLhx7iRIHEiX0oAJ3MRZMUCElJgy7Br1nO+AMN3Tc=golang.org/x/net v0.22.0/go.mod h1:JKghWKKOSdJwpW2GEx0Ja7fmaKnMsbu+MWVZTokSYmg=+golang.org/x/net v0.34.0 h1:Mb7Mrk043xzHgnRM88suvJFwzVrRfHEHJEl5/71CKw0=+golang.org/x/net v0.34.0/go.mod h1:di0qlW3YNM5oh6GqDGQr92MyTozJPmybPK4Ev/Gm31k=golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/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.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=golang.org/x/sys v0.18.0 h1:DBdB3niSjOA/O0blCZBqDefyWNYveAYMNF1Wum0DYQ4=golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=+golang.org/x/sys v0.29.0 h1:TPYlXGxvx1MGTn2GiZDhnjPA9wZzZeGKHHmKhHYvgaU=+golang.org/x/sys v0.29.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/text v0.21.0 h1:zyQAAkrwaneQ066sspRyJaG9VNi/YJ1NfzcGB3hZ/qo=+golang.org/x/text v0.21.0/go.mod h1:4IBbMaMmOPCJ8SecivzSH54+73PCFmPWxNTLm+vZkEQ=+google.golang.org/genproto/googleapis/api v0.0.0-20250115164207-1a7da9e5054f h1:gap6+3Gk41EItBuyi4XX/bp4oqJ3UwuIMl25yGinuAA=+google.golang.org/genproto/googleapis/api v0.0.0-20250115164207-1a7da9e5054f/go.mod h1:Ic02D47M+zbarjYYUlK57y316f2MoN0gjAwI3f2S95o=+google.golang.org/genproto/googleapis/rpc v0.0.0-20250115164207-1a7da9e5054f h1:OxYkA3wjPsZyBylwymxSHa7ViiW1Sml4ToBrncvFehI=+google.golang.org/genproto/googleapis/rpc v0.0.0-20250115164207-1a7da9e5054f/go.mod h1:+2Yz8+CLJbIfL9z73EW45avw8Lmge3xVElCP9zEKi50=+google.golang.org/grpc v1.69.4 h1:MF5TftSMkd8GLw/m0KM6V8CMOCY6NZ1NQDPGFgbTt4A=+google.golang.org/grpc v1.69.4/go.mod h1:vyjdE6jLBI76dgpDojsFGNaHlxdjXN9ghpnd2o7JGZ4=google.golang.org/protobuf v1.33.0 h1:uNO2rsAINq/JlFpSdYEKIZ0uKD/R9cpdv0T+yoGwGmI=google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=+google.golang.org/protobuf v1.36.3 h1:82DV7MYdb8anAVi3qge1wSnMDrnKK7ebr+I0hHRN1BU=+google.golang.org/protobuf v1.36.3/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE=gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=diff --git a/apps/checker/handlers/checker.go b/apps/checker/handlers/checker.goindex d4beb153a..230a12157 100644--- a/apps/checker/handlers/checker.go+++ b/apps/checker/handlers/checker.go@@ -12,6 +12,7 @@ import ("github.com/openstatushq/openstatus/apps/checker""github.com/openstatushq/openstatus/apps/checker/pkg/assertions"+ otelOS "github.com/openstatushq/openstatus/apps/checker/pkg/otel""github.com/openstatushq/openstatus/apps/checker/request")@@ -82,7 +83,7 @@ func (h Handler) HTTPCheckerHandler(c *gin.Context) {assertionAsString = ""}- var trigger = "cron"+ trigger := "cron"if req.Trigger != "" {trigger = req.Trigger}@@ -133,7 +134,6 @@ func (h Handler) HTTPCheckerHandler(c *gin.Context) {for _, a := range req.RawAssertions {var assert request.Assertionerr = json.Unmarshal(a, &assert)-if err != nil {// handle errorreturn fmt.Errorf("unable to unmarshal assertion: %w", err)@@ -306,7 +306,10 @@ func (h Handler) HTTPCheckerHandler(c *gin.Context) {CronTimestamp: req.CronTimestamp,})}+ }+ if req.OtelConfig.Endpoint != "" {+ otelOS.RecordHTTPMetrics(ctx, req, result, h.Region)}returnData := c.Query("data")diff --git a/apps/checker/handlers/tcp.go b/apps/checker/handlers/tcp.goindex b7c918588..a14cfc306 100644--- a/apps/checker/handlers/tcp.go+++ b/apps/checker/handlers/tcp.go@@ -10,23 +10,11 @@ import ("github.com/cenkalti/backoff/v4""github.com/gin-gonic/gin""github.com/openstatushq/openstatus/apps/checker"+ otelOS "github.com/openstatushq/openstatus/apps/checker/pkg/otel""github.com/openstatushq/openstatus/apps/checker/request""github.com/rs/zerolog/log")-type TCPResponse struct {- Region string `json:"region"`- ErrorMessage string `json:"errorMessage"`- JobType string `json:"jobType"`- RequestId int64 `json:"requestId,omitempty"`- WorkspaceID int64 `json:"workspaceId"`- MonitorID int64 `json:"monitorId"`- Timestamp int64 `json:"timestamp"`- Latency int64 `json:"latency"`- Timing checker.TCPResponseTiming `json:"timing"`- Error uint8 `json:"error,omitempty"`-}-// Only used for Tinybird.type TCPData struct {Timing string `json:"timing"`@@ -97,7 +85,7 @@ func (h Handler) TCPHandler(c *gin.Context) {var called int- var response TCPResponse+ var response checker.TCPResponseop := func() error {called++@@ -128,7 +116,7 @@ func (h Handler) TCPHandler(c *gin.Context) {URI: req.URI,}- response = TCPResponse{+ response = checker.TCPResponse{Timestamp: res.TCPStart,Timing: checker.TCPResponseTiming{TCPStart: res.TCPStart,@@ -259,7 +247,7 @@ func (h Handler) TCPHandlerRegion(c *gin.Context) {var called int- var response TCPResponse+ var response checker.TCPResponseop := func() error {called++@@ -270,7 +258,7 @@ func (h Handler) TCPHandlerRegion(c *gin.Context) {return fmt.Errorf("unable to check tcp %s", err)}- response = TCPResponse{+ response = checker.TCPResponse{Timestamp: timestamp,Timing: checker.TCPResponseTiming{TCPStart: res.TCPStart,@@ -316,5 +304,11 @@ func (h Handler) TCPHandlerRegion(c *gin.Context) {return}+ if req.OtelConfig.Endpoint != "" {++ otelOS.RecordTCPMetrics(ctx, req, response, region)++ }+c.JSON(http.StatusOK, response)}diff --git a/apps/checker/pkg/otel/otel.go b/apps/checker/pkg/otel/otel.gonew file mode 100644index 000000000..a979f7d88--- /dev/null+++ b/apps/checker/pkg/otel/otel.go@@ -0,0 +1,258 @@+package otel++import (+ "context"+ "errors"+ "fmt"+ "time"++ "github.com/openstatushq/openstatus/apps/checker"+ "github.com/openstatushq/openstatus/apps/checker/request"+ "github.com/rs/zerolog/log"++ "go.opentelemetry.io/otel"+ "go.opentelemetry.io/otel/attribute"+ "go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp"+ "go.opentelemetry.io/otel/metric"+ sdkMetrics "go.opentelemetry.io/otel/sdk/metric"+ "go.opentelemetry.io/otel/sdk/resource"++ semconv "go.opentelemetry.io/otel/semconv/v1.26.0"+)++func SetupOTelSDK(+ ctx context.Context, url string, probes string, headers map[string]string,+) (shutdown func(context.Context) error, err error) {+ var shutdownFuncs []func(context.Context) error++ shutdown = func(ctx context.Context) error {+ var err error++ for _, fn := range shutdownFuncs {+ err = errors.Join(err, fn(ctx))+ }++ shutdownFuncs = nil++ return err+ }++ handleErr := func(inErr error) {+ err = errors.Join(inErr, shutdown(ctx))+ }++ res, err := newResource()+ if err != nil {+ handleErr(err)++ return nil, err+ }++ meterProvider, err := newMeterProvider(ctx, res, url, headers)+ if err != nil {+ handleErr(err)++ return nil, err+ }++ shutdownFuncs = append(shutdownFuncs, meterProvider.Shutdown)++ otel.SetMeterProvider(meterProvider)++ return shutdown, nil+}++func newResource() (*resource.Resource, error) {+ return resource.Merge(resource.Default(),+ resource.NewWithAttributes(semconv.SchemaURL,+ semconv.ServiceName("openstatus-synthetic-check"),+ semconv.ServiceVersion("0.1.0"),+ ))+}++func newMeterProvider(+ ctx context.Context,+ res *resource.Resource,+ url string,+ headers map[string]string,+) (*sdkMetrics.MeterProvider, error) {++ grafanaExporter, err := otlpmetrichttp.New(ctx,+ otlpmetrichttp.WithEndpointURL(url),+ // otlpmetrichttp.WithInsecure(),+ otlpmetrichttp.WithHeaders(headers),+ )+ if err != nil {+ return nil, err+ }++ meterProvider := sdkMetrics.NewMeterProvider(+ sdkMetrics.WithResource(res),++ sdkMetrics.WithReader(sdkMetrics.NewPeriodicReader(grafanaExporter,+ sdkMetrics.WithInterval(3*time.Second))),+ )++ return meterProvider, nil+}++func RecordHTTPMetrics(ctx context.Context, req request.HttpCheckerRequest, result checker.Response, region string) {++ otelShutdown, err := SetupOTelSDK(ctx, req.OtelConfig.Endpoint, region, req.OtelConfig.Headers)++ if err != nil {+ log.Ctx(ctx).Error().Err(err).Msg("Error setting up otel")+ }++ defer func() {+ err = errors.Join(err, otelShutdown(ctx))+ if err != nil {+ log.Ctx(ctx).Error().Err(err).Msg("Error sending the data")+ }+ }()++ meter := otel.Meter("OpenStatus")++ if result.Error != "" {+ att := metric.WithAttributes(+ attribute.String("openstatus.probes", region),+ attribute.String("openstatus.target", req.URL),+ semconv.HTTPResponseStatusCode(result.Status),+ )+ statusError, err := meter.Int64Counter("openstatus.error", metric.WithDescription("Status of the check"))++ if err != nil {+ log.Ctx(ctx).Error().Err(err).Msg("Error setting up counter")+ }++ statusError.Add(ctx, (1), att)++ return+ }++ att := metric.WithAttributes(+ attribute.String("openstatus.probes", region),+ attribute.String("openstatus.target", req.URL),+ semconv.HTTPResponseStatusCode(result.Status),+ )++ status, err := meter.Int64Counter("openstatus.status", metric.WithDescription("Status of the check"))++ if err != nil {+ log.Ctx(ctx).Error().Err(err).Msg("Error setting up conunter")+ }++ status.Add(ctx, 1, att)++ gauge, err := meter.Float64Gauge("openstatus.http.request.duration",+ metric.WithDescription("Duration of the check"), metric.WithUnit("ms"))++ if err != nil {+ fmt.Println("Error creating gauge", err)+ }++ gauge.Record(ctx, float64(result.Latency), att)++ gaugeDns, err := meter.Float64Gauge("openstatus.http.dns.duration",+ metric.WithDescription("Duration of the dns lookup"), metric.WithUnit("ms"))++ if err != nil {+ fmt.Println("Error creating gauge", err)+ }++ gaugeDns.Record(ctx, float64(result.Timing.DnsDone-result.Timing.DnsStart), att)++ gaugeConnect, err := meter.Float64Gauge("openstatus.http.connection.duration",+ metric.WithDescription("Duration of the connection"), metric.WithUnit("ms"))++ if err != nil {+ fmt.Println("Error creating gauge", err)+ }++ gaugeConnect.Record(ctx, float64(result.Timing.ConnectDone-result.Timing.ConnectStart), att)++ gaugeTLS, err := meter.Float64Gauge("openstatus.http.tls.duration",+ metric.WithDescription("Duration of the tls handshake"), metric.WithUnit("ms"))++ if err != nil {+ fmt.Println("Error creating gauge", err)+ }++ gaugeTLS.Record(ctx, float64(result.Timing.TlsHandshakeDone-result.Timing.TlsHandshakeStart), att)++ gaugeTTFB, err := meter.Float64Gauge("openstatus.http.ttfb.duration",+ metric.WithDescription("Duration of the ttfb"), metric.WithUnit("ms"))++ if err != nil {+ fmt.Println("Error creating gauge", err)+ }++ gaugeTTFB.Record(ctx, float64(result.Timing.FirstByteDone-result.Timing.FirstByteStart), att)++ gaugeTransfer, err := meter.Float64Gauge("openstatus.http.transfer.duration",+ metric.WithDescription("Duration of the transfer"), metric.WithUnit("ms"))++ if err != nil {+ fmt.Println("Error creating gauge", err)+ }++ gaugeTransfer.Record(ctx, float64(result.Timing.TransferDone-result.Timing.TransferStart), att)+}++func RecordTCPMetrics(ctx context.Context, req request.TCPCheckerRequest, result checker.TCPResponse, region string) {++ otelShutdown, err := SetupOTelSDK(ctx, req.OtelConfig.Endpoint, region, req.OtelConfig.Headers)++ if err != nil {+ log.Ctx(ctx).Error().Err(err).Msg("Error setting up otel")+ }++ defer func() {+ err = errors.Join(err, otelShutdown(ctx))+ if err != nil {+ log.Ctx(ctx).Error().Err(err).Msg("Error sending the data")+ }+ }()++ meter := otel.Meter("OpenStatus")++ if result.Error == 1 {+ att := metric.WithAttributes(+ attribute.String("openstatus.probes", region),+ attribute.String("openstatus.target", req.URI),+ )+ statusError, err := meter.Int64Counter("openstatus.error", metric.WithDescription("Status of the check"))++ if err != nil {+ log.Ctx(ctx).Error().Err(err).Msg("Error setting up counter")+ }++ statusError.Add(ctx, (1), att)++ return+ }++ att := metric.WithAttributes(+ attribute.String("openstatus.probes", region),+ attribute.String("openstatus.target", req.URI),+ )++ gauge, err := meter.Float64Gauge("openstatus.tcp.request.duration",+ metric.WithDescription("Duration of the check"), metric.WithUnit("ms"))++ if err != nil {+ fmt.Println("Error creating gauge", err)+ }++ gauge.Record(ctx, float64(result.Latency), att)++ gaugeTCP, err := meter.Float64Gauge("openstatus.tcp.tcp.duration",+ metric.WithDescription("Duration of the dns lookup"), metric.WithUnit("ms"))++ if err != nil {+ fmt.Println("Error creating gauge", err)+ }++ gaugeTCP.Record(ctx, float64(result.Timing.TCPDone-result.Timing.TCPStart), att)++}diff --git a/apps/checker/request/request.go b/apps/checker/request/request.goindex a940d2a53..af0b9e56d 100644--- a/apps/checker/request/request.go+++ b/apps/checker/request/request.go@@ -61,6 +61,10 @@ type HttpCheckerRequest struct {CronTimestamp int64 `json:"cronTimestamp"`Timeout int64 `json:"timeout"`DegradedAfter int64 `json:"degradedAfter,omitempty"`+ OtelConfig struct {+ Endpoint string `json:"endpoint"`+ Headers map[string]string `json:"headers,omitempty"`+ } `json:"otelConfig,omitempty"`}type TCPCheckerRequest struct {@@ -74,6 +78,10 @@ type TCPCheckerRequest struct {CronTimestamp int64 `json:"cronTimestamp"`Timeout int64 `json:"timeout"`DegradedAfter int64 `json:"degradedAfter,omitempty"`+ OtelConfig struct {+ Endpoint string `json:"endpoint"`+ Headers map[string]string `json:"headers,omitempty"`+ } `json:"otelConfig,omitempty"`}type TCPRequest struct {diff --git a/apps/checker/tcp.go b/apps/checker/tcp.goindex b097f9e95..5fd99ab39 100644--- a/apps/checker/tcp.go+++ b/apps/checker/tcp.go@@ -18,6 +18,19 @@ type TCPResponseTiming struct {TCPDone int64 `json:"tcpDone"`}+type TCPResponse struct {+ Region string `json:"region"`+ ErrorMessage string `json:"errorMessage"`+ JobType string `json:"jobType"`+ RequestId int64 `json:"requestId,omitempty"`+ WorkspaceID int64 `json:"workspaceId"`+ MonitorID int64 `json:"monitorId"`+ Timestamp int64 `json:"timestamp"`+ Latency int64 `json:"latency"`+ Timing TCPResponseTiming `json:"timing"`+ Error uint8 `json:"error,omitempty"`+}+func PingTcp(timeout int, url string) (TCPResponseTiming, error) {start := time.Now().UTC().UnixMilli()conn, err := net.DialTimeout("tcp", url, time.Duration(timeout)*time.Second)