Skip to content

The only tool you need to know what is happening and how to fix it.

client code moved to tracewayapp/go-client

dduxd108d7b9f9c2
diff --git a/clients/go-client/go.mod b/clients/go-client/go.mod
deleted file mode 100644
index c431fe1e..00000000
--- a/clients/go-client/go.mod
+++ /dev/null
@@ -1,51 +0,0 @@
-module go.tracewayapp.com
-
-go 1.25.1
-
-require github.com/gin-gonic/gin v1.11.0
-
-require (
- github.com/go-ole/go-ole v1.2.6 // indirect
- github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 // indirect
- github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c // indirect
- github.com/shoenig/go-m1cpu v0.1.6 // indirect
- github.com/tklauser/go-sysconf v0.3.12 // indirect
- github.com/tklauser/numcpus v0.6.1 // indirect
- github.com/yusufpapurcu/wmi v1.2.4 // indirect
-)
-
-require (
- github.com/bytedance/sonic v1.14.0 // indirect
- github.com/bytedance/sonic/loader v0.3.0 // indirect
- github.com/cloudwego/base64x v0.1.6 // indirect
- github.com/gabriel-vasile/mimetype v1.4.8 // indirect
- github.com/gin-contrib/sse v1.1.0 // indirect
- github.com/go-playground/locales v0.14.1 // indirect
- github.com/go-playground/universal-translator v0.18.1 // indirect
- github.com/go-playground/validator/v10 v10.27.0 // indirect
- github.com/goccy/go-json v0.10.2 // indirect
- github.com/goccy/go-yaml v1.18.0 // indirect
- github.com/google/uuid v1.6.0
- github.com/json-iterator/go v1.1.12 // indirect
- github.com/klauspost/cpuid/v2 v2.3.0 // indirect
- github.com/leodido/go-urn v1.4.0 // indirect
- github.com/mattn/go-isatty v0.0.20 // indirect
- github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 // indirect
- github.com/modern-go/reflect2 v1.0.2 // indirect
- github.com/pelletier/go-toml/v2 v2.2.4 // indirect
- github.com/quic-go/qpack v0.5.1 // indirect
- github.com/quic-go/quic-go v0.54.0 // indirect
- github.com/shirou/gopsutil/v3 v3.24.5
- github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
- github.com/ugorji/go/codec v1.3.0 // indirect
- go.uber.org/mock v0.5.0 // indirect
- golang.org/x/arch v0.20.0 // indirect
- golang.org/x/crypto v0.40.0 // indirect
- golang.org/x/mod v0.25.0 // indirect
- golang.org/x/net v0.42.0 // indirect
- golang.org/x/sync v0.16.0 // indirect
- golang.org/x/sys v0.35.0 // indirect
- golang.org/x/text v0.27.0 // indirect
- golang.org/x/tools v0.34.0 // indirect
- google.golang.org/protobuf v1.36.9 // indirect
-)
diff --git a/clients/go-client/go.sum b/clients/go-client/go.sum
deleted file mode 100644
index b175be3c..00000000
--- a/clients/go-client/go.sum
+++ /dev/null
@@ -1,103 +0,0 @@
-github.com/bytedance/sonic v1.14.0 h1:/OfKt8HFw0kh2rj8N0F6C/qPGRESq0BbaNZgcNXXzQQ=
-github.com/bytedance/sonic v1.14.0/go.mod h1:WoEbx8WTcFJfzCe0hbmyTGrfjt8PzNEBdxlNUO24NhA=
-github.com/bytedance/sonic/loader v0.3.0 h1:dskwH8edlzNMctoruo8FPTJDF3vLtDT0sXZwvZJyqeA=
-github.com/bytedance/sonic/loader v0.3.0/go.mod h1:N8A3vUdtUebEY2/VQC0MyhYeKUFosQU6FxH2JmUe6VI=
-github.com/cloudwego/base64x v0.1.6 h1:t11wG9AECkCDk5fMSoxmufanudBtJ+/HemLstXDLI2M=
-github.com/cloudwego/base64x v0.1.6/go.mod h1:OFcloc187FXDaYHvrNIjxSe8ncn0OOM8gEHfghB2IPU=
-github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
-github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
-github.com/gabriel-vasile/mimetype v1.4.8 h1:FfZ3gj38NjllZIeJAmMhr+qKL8Wu+nOoI3GqacKw1NM=
-github.com/gabriel-vasile/mimetype v1.4.8/go.mod h1:ByKUIKGjh1ODkGM1asKUbQZOLGrPjydw3hYPU2YU9t8=
-github.com/gin-contrib/sse v1.1.0 h1:n0w2GMuUpWDVp7qSpvze6fAu9iRxJY4Hmj6AmBOU05w=
-github.com/gin-contrib/sse v1.1.0/go.mod h1:hxRZ5gVpWMT7Z0B0gSNYqqsSCNIJMjzvm6fqCz9vjwM=
-github.com/gin-gonic/gin v1.11.0 h1:OW/6PLjyusp2PPXtyxKHU0RbX6I/l28FTdDlae5ueWk=
-github.com/gin-gonic/gin v1.11.0/go.mod h1:+iq/FyxlGzII0KHiBGjuNn4UNENUlKbGlNmc+W50Dls=
-github.com/go-ole/go-ole v1.2.6 h1:/Fpf6oFPoeFik9ty7siob0G6Ke8QvQEuVcuChpwXzpY=
-github.com/go-ole/go-ole v1.2.6/go.mod h1:pprOEPIfldk/42T2oK7lQ4v4JSDwmV0As9GaiUsvbm0=
-github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/oXslEjJA=
-github.com/go-playground/locales v0.14.1/go.mod h1:hxrqLVvrK65+Rwrd5Fc6F2O76J/NuW9t0sjnWqG1slY=
-github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJnYK9S473LQFuzCbDbfSFY=
-github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY=
-github.com/go-playground/validator/v10 v10.27.0 h1:w8+XrWVMhGkxOaaowyKH35gFydVHOvC0/uWoy2Fzwn4=
-github.com/go-playground/validator/v10 v10.27.0/go.mod h1:I5QpIEbmr8On7W0TktmJAumgzX4CA1XNl4ZmDuVHKKo=
-github.com/goccy/go-json v0.10.2 h1:CrxCmQqYDkv1z7lO7Wbh2HN93uovUHgrECaO5ZrCXAU=
-github.com/goccy/go-json v0.10.2/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I=
-github.com/goccy/go-yaml v1.18.0 h1:8W7wMFS12Pcas7KU+VVkaiCng+kG8QiFeFwzFb+rwuw=
-github.com/goccy/go-yaml v1.18.0/go.mod h1:XBurs7gK8ATbW4ZPGKgcbrY1Br56PdM69F7LkFRi1kA=
-github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
-github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
-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/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.3.0 h1:S4CRMLnYUhGeDFDqkGriYKdfoFlDnMtqTiI/sFzhA9Y=
-github.com/klauspost/cpuid/v2 v2.3.0/go.mod h1:hqwkgyIinND0mEev00jJYCxPNVRVXFQeu1XKlok6oO0=
-github.com/leodido/go-urn v1.4.0 h1:WT9HwE9SGECu3lg4d/dIA+jxlljEa1/ffXKmRjqdmIQ=
-github.com/leodido/go-urn v1.4.0/go.mod h1:bvxc+MVxLKB4z00jd1z+Dvzr47oO32F/QSNjSBOlFxI=
-github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 h1:6E+4a0GO5zZEnZ81pIr0yLvtUWk2if982qA3F3QD6H4=
-github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0/go.mod h1:zJYVVT2jmtg6P3p1VtQj7WsuWi/y4VnjVBn7F8KPB3I=
-github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
-github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
-github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 h1:ZqeYNhU3OHLH3mGKHDcjJRFFRrJa6eAM5H+CtDdOsPc=
-github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
-github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M=
-github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
-github.com/pelletier/go-toml/v2 v2.2.4 h1:mye9XuhQ6gvn5h28+VilKrrPoQVanw5PMw/TB0t5Ec4=
-github.com/pelletier/go-toml/v2 v2.2.4/go.mod h1:2gIqNv+qfxSVS7cM2xJQKtLSTLUE9V8t9Stt+h56mCY=
-github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
-github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c h1:ncq/mPwQF4JjgDlrVEn3C11VoGHZN7m8qihwgMEtzYw=
-github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c/go.mod h1:OmDBASR4679mdNQnz2pUhc2G8CO2JrUAVFDRBDP/hJE=
-github.com/quic-go/qpack v0.5.1 h1:giqksBPnT/HDtZ6VhtFKgoLOWmlyo9Ei6u9PqzIMbhI=
-github.com/quic-go/qpack v0.5.1/go.mod h1:+PC4XFrEskIVkcLzpEkbLqq1uCoxPhQuvK5rH1ZgaEg=
-github.com/quic-go/quic-go v0.54.0 h1:6s1YB9QotYI6Ospeiguknbp2Znb/jZYjZLRXn9kMQBg=
-github.com/quic-go/quic-go v0.54.0/go.mod h1:e68ZEaCdyviluZmy44P6Iey98v/Wfz6HCjQEm+l8zTY=
-github.com/shirou/gopsutil/v3 v3.24.5 h1:i0t8kL+kQTvpAYToeuiVk3TgDeKOFioZO3Ztz/iZ9pI=
-github.com/shirou/gopsutil/v3 v3.24.5/go.mod h1:bsoOS1aStSs9ErQ1WWfxllSeS1K5D+U30r2NfcubMVk=
-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/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
-github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
-github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
-github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
-github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
-github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
-github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
-github.com/tklauser/go-sysconf v0.3.12 h1:0QaGUFOdQaIVdPgfITYzaTegZvdCjmYO52cSFAEVmqU=
-github.com/tklauser/go-sysconf v0.3.12/go.mod h1:Ho14jnntGE1fpdOqQEEaiKRpvIavV0hSfmBq8nJbHYI=
-github.com/tklauser/numcpus v0.6.1 h1:ng9scYS7az0Bk4OZLvrNXNSAO2Pxr1XXRAPyjhIx+Fk=
-github.com/tklauser/numcpus v0.6.1/go.mod h1:1XfjsgE2zo8GVw7POkMbHENHzVg3GzmoZ9fESEdAacY=
-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.3.0 h1:Qd2W2sQawAfG8XSvzwhBeoGq71zXOC/Q1E9y/wUcsUA=
-github.com/ugorji/go/codec v1.3.0/go.mod h1:pRBVtBSKl77K30Bv8R2P+cLSGaTtex6fsA2Wjqmfxj4=
-github.com/yusufpapurcu/wmi v1.2.4 h1:zFUKzehAFReQwLys1b/iSMl+JQGSCSjtVqQn9bBrPo0=
-github.com/yusufpapurcu/wmi v1.2.4/go.mod h1:SBZ9tNy3G9/m5Oi98Zks0QjeHVDvuK0qfxQmPyzfmi0=
-go.uber.org/mock v0.5.0 h1:KAMbZvZPyBPWgD14IrIQ38QCyjwpvVVV6K/bHl1IwQU=
-go.uber.org/mock v0.5.0/go.mod h1:ge71pBPLYDk7QIi1LupWxdAykm7KIEFchiOqd6z7qMM=
-golang.org/x/arch v0.20.0 h1:dx1zTU0MAE98U+TQ8BLl7XsJbgze2WnNKF/8tGp/Q6c=
-golang.org/x/arch v0.20.0/go.mod h1:bdwinDaKcfZUGpH09BB7ZmOfhalA8lQdzl62l8gGWsk=
-golang.org/x/crypto v0.40.0 h1:r4x+VvoG5Fm+eJcxMaY8CQM7Lb0l1lsmjGBQ6s8BfKM=
-golang.org/x/crypto v0.40.0/go.mod h1:Qr1vMER5WyS2dfPHAlsOj01wgLbsyWtFn/aY+5+ZdxY=
-golang.org/x/mod v0.25.0 h1:n7a+ZbQKQA/Ysbyb0/6IbB1H/X41mKgbhfv7AfG/44w=
-golang.org/x/mod v0.25.0/go.mod h1:IXM97Txy2VM4PJ3gI61r1YEk/gAj6zAHN3AdZt6S9Ww=
-golang.org/x/net v0.42.0 h1:jzkYrhi3YQWD6MLBJcsklgQsoAcw89EcZbJw8Z614hs=
-golang.org/x/net v0.42.0/go.mod h1:FF1RA5d3u7nAYA4z2TkclSCKh68eSXtiFwcWQpPXdt8=
-golang.org/x/sync v0.16.0 h1:ycBJEhp9p4vXvUZNszeOq0kGTPghopOL8q0fq3vstxw=
-golang.org/x/sync v0.16.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA=
-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.6.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.35.0 h1:vz1N37gP5bs89s7He8XuIYXpyY0+QlsKmzipCbUtyxI=
-golang.org/x/sys v0.35.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
-golang.org/x/text v0.27.0 h1:4fGWRpyh641NLlecmyl4LOe6yDdfaYNrGb2zdfo4JV4=
-golang.org/x/text v0.27.0/go.mod h1:1D28KMCvyooCX9hBiosv5Tz/+YLxj0j7XhWjpSUF7CU=
-golang.org/x/tools v0.34.0 h1:qIpSLOxeCYGg9TrcJokLBG4KFA6d795g0xkBkiESGlo=
-golang.org/x/tools v0.34.0/go.mod h1:pAP9OwEaY1CAW3HOmg3hLZC5Z0CCmzjAF2UQMSqNARg=
-golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
-google.golang.org/protobuf v1.36.9 h1:w2gp2mA27hUeUzj9Ex9FBjsBm40zfaDtEWow293U7Iw=
-google.golang.org/protobuf v1.36.9/go.mod h1:fuxRtAxBytpl4zzqUh6/eyUujkJdNiuEkXntxiD/uRU=
-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=
-gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
diff --git a/clients/go-client/metrics/cpu/cpu_darwin.go b/clients/go-client/metrics/cpu/cpu_darwin.go
deleted file mode 100644
index de795fec..00000000
--- a/clients/go-client/metrics/cpu/cpu_darwin.go
+++ /dev/null
@@ -1,106 +0,0 @@
-//go:build darwin
-
-package cpu
-
-/*
-#include <mach/mach.h>
-#include <mach/processor_info.h>
-#include <mach/mach_host.h>
-
-typedef struct {
- unsigned int user;
- unsigned int system;
- unsigned int idle;
- unsigned int nice;
-} cpu_usage_t;
-
-int get_cpu_ticks(cpu_usage_t *usage) {
- mach_msg_type_number_t count;
- processor_cpu_load_info_t cpu_load;
- natural_t num_cpus;
-
- kern_return_t ret = host_processor_info(
- mach_host_self(),
- PROCESSOR_CPU_LOAD_INFO,
- &num_cpus,
- (processor_info_array_t *)&cpu_load,
- &count
- );
-
- if (ret != KERN_SUCCESS) {
- return -1;
- }
-
- usage->user = 0;
- usage->system = 0;
- usage->idle = 0;
- usage->nice = 0;
-
- for (natural_t i = 0; i < num_cpus; i++) {
- usage->user += cpu_load[i].cpu_ticks[CPU_STATE_USER];
- usage->system += cpu_load[i].cpu_ticks[CPU_STATE_SYSTEM];
- usage->idle += cpu_load[i].cpu_ticks[CPU_STATE_IDLE];
- usage->nice += cpu_load[i].cpu_ticks[CPU_STATE_NICE];
- }
-
- vm_deallocate(mach_task_self(), (vm_address_t)cpu_load,
- count * sizeof(*cpu_load));
-
- return 0;
-}
-*/
-import "C"
-import (
- "fmt"
- "time"
-)
-
-type CPUTicks struct {
- User uint32
- System uint32
- Idle uint32
- Nice uint32
-}
-
-func getCPUTicks() (CPUTicks, error) {
- var usage C.cpu_usage_t
- ret := C.get_cpu_ticks(&usage)
- if ret != 0 {
- return CPUTicks{}, fmt.Errorf("failed to get CPU ticks")
- }
- return CPUTicks{
- User: uint32(usage.user),
- System: uint32(usage.system),
- Idle: uint32(usage.idle),
- Nice: uint32(usage.nice),
- }, nil
-}
-
-func (t CPUTicks) Total() uint64 {
- return uint64(t.User) + uint64(t.System) + uint64(t.Idle) + uint64(t.Nice)
-}
-
-// GetCPUUsage returns CPU usage percentage over the given duration
-func GetCpuPercent(interval time.Duration) (float64, error) {
- ticks1, err := getCPUTicks()
- if err != nil {
- return 0, err
- }
-
- time.Sleep(interval)
-
- ticks2, err := getCPUTicks()
- if err != nil {
- return 0, err
- }
-
- totalDiff := float64(ticks2.Total() - ticks1.Total())
- if totalDiff == 0 {
- return 0, nil
- }
-
- idleDiff := float64(ticks2.Idle - ticks1.Idle)
- usage := 100.0 * (1.0 - idleDiff/totalDiff)
-
- return usage, nil
-}
diff --git a/clients/go-client/metrics/cpu/cpu_linux.go b/clients/go-client/metrics/cpu/cpu_linux.go
deleted file mode 100644
index 9f4c4f35..00000000
--- a/clients/go-client/metrics/cpu/cpu_linux.go
+++ /dev/null
@@ -1,72 +0,0 @@
-//go:build linux
-
-package cpu
-
-import (
- "bufio"
- "os"
- "strconv"
- "strings"
- "time"
-)
-
-// TODO: TEST LINUX CPU READING
-
-func GetCpuPercent(interval time.Duration) (float64, error) {
- idle1, total1, err := readLinuxCPUStat()
- if err != nil {
- return 0, err
- }
-
- time.Sleep(interval)
-
- idle2, total2, err := readLinuxCPUStat()
- if err != nil {
- return 0, err
- }
-
- idleDelta := float64(idle2 - idle1)
- totalDelta := float64(total2 - total1)
-
- if totalDelta == 0 {
- return 0, nil
- }
-
- return (1.0 - idleDelta/totalDelta) * 100, nil
-}
-
-func readLinuxCPUStat() (idle, total uint64, err error) {
- file, err := os.Open("/proc/stat")
- if err != nil {
- return 0, 0, err
- }
- defer file.Close()
-
- scanner := bufio.NewScanner(file)
- for scanner.Scan() {
- line := scanner.Text()
- if strings.HasPrefix(line, "cpu ") {
- fields := strings.Fields(line)
- if len(fields) < 5 {
- continue
- }
- for i, field := range fields[1:] {
- val, _ := strconv.ParseUint(field, 10, 64)
- total += val
- if i == 3 {
- idle = val
- }
- }
- break
- }
- }
- return idle, total, scanner.Err()
-}
-
-func getDarwinCPUPercent(interval time.Duration) (float64, error) {
- return 0, nil
-}
-
-func getWindowsCPUPercent(interval time.Duration) (float64, error) {
- return 0, nil
-}
diff --git a/clients/go-client/metrics/cpu/cpu_windows.go b/clients/go-client/metrics/cpu/cpu_windows.go
deleted file mode 100644
index f5ed8e60..00000000
--- a/clients/go-client/metrics/cpu/cpu_windows.go
+++ /dev/null
@@ -1,62 +0,0 @@
-//go:build windows
-
-package cpu
-
-import (
- "time"
- "unsafe"
-
- "golang.org/x/sys/windows"
-)
-
-// TODO: TEST WINDOWS CPU READING
-
-var (
- modkernel32 = windows.NewLazySystemDLL("kernel32.dll")
- procGetSystemTimes = modkernel32.NewProc("GetSystemTimes")
-)
-
-func GetCpuPercent(interval time.Duration) (float64, error) {
- idle1, kernel1, user1, err := getSystemTimes()
- if err != nil {
- return 0, err
- }
-
- time.Sleep(interval)
-
- idle2, kernel2, user2, err := getSystemTimes()
- if err != nil {
- return 0, err
- }
-
- idleDelta := idle2 - idle1
- kernelDelta := kernel2 - kernel1
- userDelta := user2 - user1
-
- totalDelta := kernelDelta + userDelta
- if totalDelta == 0 {
- return 0, nil
- }
-
- // kernel time includes idle time
- return float64(totalDelta-idleDelta) / float64(totalDelta) * 100, nil
-}
-
-func getSystemTimes() (idle, kernel, user uint64, err error) {
- var idleTime, kernelTime, userTime windows.Filetime
-
- ret, _, err := procGetSystemTimes.Call(
- uintptr(unsafe.Pointer(&idleTime)),
- uintptr(unsafe.Pointer(&kernelTime)),
- uintptr(unsafe.Pointer(&userTime)),
- )
- if ret == 0 {
- return 0, 0, 0, err
- }
-
- return fileTimeToUint64(idleTime), fileTimeToUint64(kernelTime), fileTimeToUint64(userTime), nil
-}
-
-func fileTimeToUint64(ft windows.Filetime) uint64 {
- return uint64(ft.HighDateTime)<<32 | uint64(ft.LowDateTime)
-}
diff --git a/clients/go-client/metrics/mem/mem_darwin.go b/clients/go-client/metrics/mem/mem_darwin.go
deleted file mode 100644
index c097dbd8..00000000
--- a/clients/go-client/metrics/mem/mem_darwin.go
+++ /dev/null
@@ -1,58 +0,0 @@
-//go:build darwin
-
-package mem
-
-import (
- "encoding/binary"
- "fmt"
- "syscall"
- "unsafe"
-)
-
-// GetTotalMemory returns total physical memory in bytes
-func GetTotalMemory() (uint64, error) {
- return getTotalVirtualMemory()
-}
-
-func getTotalVirtualMemory() (uint64, error) {
- // Get physical memory size using sysctl
- physMem, err := syscall.Sysctl("hw.memsize")
- if err != nil {
- return 0, fmt.Errorf("failed to get hw.memsize: %w", err)
- }
-
- // The result is a binary representation of uint64
- // syscall.Sysctl returns a string, but the data is actually binary
- if len(physMem) < 8 {
- // Pad if necessary
- padded := make([]byte, 8)
- copy(padded, []byte(physMem))
- return binary.LittleEndian.Uint64(padded), nil
- }
-
- return binary.LittleEndian.Uint64([]byte(physMem)[:8]), nil
-}
-
-// Alternative using SysctlUint64 (cleaner approach)
-func getTotalPhysicalMemory() (uint64, error) {
- mib := []int32{6, 24} // CTL_HW, HW_MEMSIZE
-
- var value uint64
- size := uintptr(unsafe.Sizeof(value))
-
- _, _, errno := syscall.Syscall6(
- syscall.SYS___SYSCTL,
- uintptr(unsafe.Pointer(&mib[0])),
- uintptr(len(mib)),
- uintptr(unsafe.Pointer(&value)),
- uintptr(unsafe.Pointer(&size)),
- 0,
- 0,
- )
-
- if errno != 0 {
- return 0, errno
- }
-
- return value, nil
-}
diff --git a/clients/go-client/metrics/mem/mem_linux.go b/clients/go-client/metrics/mem/mem_linux.go
deleted file mode 100644
index d9361aec..00000000
--- a/clients/go-client/metrics/mem/mem_linux.go
+++ /dev/null
@@ -1,32 +0,0 @@
-//go:build linux
-
-package mem
-
-import (
- "bufio"
- "os"
- "strconv"
- "strings"
-)
-
-// GetTotalMemory returns total physical memory in bytes
-func GetTotalMemory() (uint64, error) {
- file, err := os.Open("/proc/meminfo")
- if err != nil {
- return 0, err
- }
- defer file.Close()
-
- scanner := bufio.NewScanner(file)
- for scanner.Scan() {
- fields := strings.Fields(scanner.Text())
- if len(fields) < 2 {
- continue
- }
- if fields[0] == "MemTotal:" {
- val, _ := strconv.ParseUint(fields[1], 10, 64)
- return val * 1024, nil // Convert from KB to bytes
- }
- }
- return 0, nil
-}
diff --git a/clients/go-client/metrics/mem/mem_windows.go b/clients/go-client/metrics/mem/mem_windows.go
deleted file mode 100644
index 8330078e..00000000
--- a/clients/go-client/metrics/mem/mem_windows.go
+++ /dev/null
@@ -1,27 +0,0 @@
-package mem
-
-import (
- "syscall"
- "unsafe"
-)
-
-// GetTotalMemory returns total physical memory in bytes
-func GetTotalMemory() (uint64, error) {
- kernel32 := syscall.NewLazyDLL("kernel32.dll")
- proc := kernel32.NewProc("GlobalMemoryStatusEx")
-
- var mem struct {
- dwLength uint32
- dwMemoryLoad uint32
- ullTotalPhys uint64
- ullAvailPhys uint64
- _ [4]uint64 // remaining fields we don't need
- }
- mem.dwLength = uint32(unsafe.Sizeof(mem))
-
- ret, _, err := proc.Call(uintptr(unsafe.Pointer(&mem)))
- if ret == 0 {
- return 0, err
- }
- return mem.ullTotalPhys, nil
-}
diff --git a/clients/go-client/traceway.go b/clients/go-client/traceway.go
deleted file mode 100644
index 99b35955..00000000
--- a/clients/go-client/traceway.go
+++ /dev/null
@@ -1,848 +0,0 @@
-package traceway
-
-import (
- "bytes"
- "compress/gzip"
- "context"
- "encoding/json"
- "fmt"
- "log"
- "net/http"
- "os"
- "reflect"
- "runtime"
- "runtime/debug"
- "strings"
- "sync"
- "time"
- "go.tracewayapp.com/metrics/cpu"
- "go.tracewayapp.com/metrics/mem"
-
- "github.com/gin-gonic/gin"
- "github.com/google/uuid"
-)
-
-// Context key for scope
-type tracewayContextKey string
-
-const CtxScopeKey tracewayContextKey = "TRACEWAY_SCOPE"
-const CtxTransactionKey tracewayContextKey = "TRACEWAY_TRANSACTION"
-
-// Scope holds contextual data for exceptions and transactions
-type Scope struct {
- tags map[string]string
- mu sync.RWMutex
-}
-
-// NewScope creates a new empty scope
-func NewScope() *Scope {
- return &Scope{tags: make(map[string]string)}
-}
-
-// SetTag sets a tag on the scope
-func (s *Scope) SetTag(key, value string) {
- s.mu.Lock()
- defer s.mu.Unlock()
- s.tags[key] = value
-}
-
-// GetTag gets a tag from the scope
-func (s *Scope) GetTag(key string) (string, bool) {
- s.mu.RLock()
- defer s.mu.RUnlock()
- val, ok := s.tags[key]
- return val, ok
-}
-
-// GetTags returns a copy of all tags
-func (s *Scope) GetTags() map[string]string {
- s.mu.RLock()
- defer s.mu.RUnlock()
- result := make(map[string]string, len(s.tags))
- for k, v := range s.tags {
- result[k] = v
- }
- return result
-}
-
-// Clone creates a deep copy of the scope
-func (s *Scope) Clone() *Scope {
- return &Scope{tags: s.GetTags()}
-}
-
-// Clear removes all tags from the scope
-func (s *Scope) Clear() {
- s.mu.Lock()
- defer s.mu.Unlock()
- s.tags = make(map[string]string)
-}
-
-// Global default scope
-var defaultScope = NewScope()
-
-// TransactionContext holds transaction data including segments
-type TransactionContext struct {
- Id string
- Segments []Segment
- mu sync.Mutex
-}
-
-// AddSegment adds a segment to the transaction context
-func (t *TransactionContext) AddSegment(seg Segment) {
- t.mu.Lock()
- defer t.mu.Unlock()
- t.Segments = append(t.Segments, seg)
-}
-
-// GetSegments returns a copy of segments
-func (t *TransactionContext) GetSegments() []Segment {
- t.mu.Lock()
- defer t.mu.Unlock()
- return t.Segments
-}
-
-// ConfigureScope modifies the global default scope (persistent changes)
-func ConfigureScope(fn func(*Scope)) {
- fn(defaultScope)
-}
-
-// WithScope creates an isolated scope clone for the callback and returns a new context
-func WithScope(ctx context.Context, fn func(*Scope)) context.Context {
- scope := GetScopeFromContext(ctx).Clone()
- fn(scope)
- return context.WithValue(ctx, CtxScopeKey, scope)
-}
-
-// GetScopeFromContext retrieves scope from context, falls back to default clone
-func GetScopeFromContext(ctx context.Context) *Scope {
- if ctx == nil {
- return defaultScope.Clone()
- }
- if scope, ok := ctx.Value(string(CtxScopeKey)).(*Scope); ok && scope != nil {
- return scope
- }
-
- return defaultScope.Clone()
-}
-
-// GetScopeFromGin is a convenience helper for Gin handlers
-func GetScopeFromGin(c *gin.Context) *Scope {
- if scope, ok := c.Get(string(CtxScopeKey)); ok {
- if s, ok := scope.(*Scope); ok {
- return s
- }
- }
- return GetScopeFromContext(c.Request.Context())
-}
-
-// GetTransactionFromContext retrieves the transaction context
-func GetTransactionFromContext(ctx context.Context) *TransactionContext {
- if val, ok := ctx.Value(string(CtxTransactionKey)).(*TransactionContext); ok {
- return val
- }
- return nil
-}
-
-func GetTransactionIdFromContext(ctx context.Context) *string {
- if txn := GetTransactionFromContext(ctx); txn != nil {
- return &txn.Id
- }
- return nil
-}
-
-// GetHostname returns the hostname, cached for efficiency
-var cachedHostname string
-var hostnameOnce sync.Once
-
-func getHostname() string {
- hostnameOnce.Do(func() {
- hostname, err := os.Hostname()
- if err != nil {
- cachedHostname = "unknown"
- } else {
- cachedHostname = hostname
- }
- })
- return cachedHostname
-}
-
-// GetEnvironment returns the environment from TRACEWAY_ENV or GO_ENV
-var cachedEnvironment string
-var envOnce sync.Once
-
-func getEnvironment() string {
- envOnce.Do(func() {
- cachedEnvironment = os.Getenv("TRACEWAY_ENV")
- if cachedEnvironment == "" {
- cachedEnvironment = os.Getenv("GO_ENV")
- }
- if cachedEnvironment == "" {
- cachedEnvironment = "development"
- }
- })
- return cachedEnvironment
-}
-
-func CaptureStack(skip int) []runtime.Frame {
- const maxDepth = 64
- pcs := make([]uintptr, maxDepth)
-
- // +2 skips runtime.Callers and CaptureStack
- n := runtime.Callers(skip+2, pcs)
- if n == 0 {
- return nil
- }
-
- frames := runtime.CallersFrames(pcs[:n])
- result := make([]runtime.Frame, 0, n)
-
- for {
- frame, more := frames.Next()
- result = append(result, frame)
- if !more {
- break
- }
- }
- return result
-}
-
-func FormatRWithStack(r interface{}, frames []runtime.Frame) string {
- var err error
- switch v := r.(type) {
- case error:
- err = v
- default:
- err = fmt.Errorf("%v", v)
- }
- return FormatErrorWithStack(err, frames)
-}
-
-func FormatErrorWithStack(err error, frames []runtime.Frame) string {
- var sb strings.Builder
-
- if err != nil {
- errType := reflect.TypeOf(err).String()
- fmt.Fprintf(&sb, "%s: %s\n", errType, err.Error())
- }
-
- for _, frame := range frames {
- fn := frame.Function
- // Extract just the function/method name
- if idx := strings.LastIndex(fn, "/"); idx >= 0 {
- fn = fn[idx+1:]
- }
- if idx := strings.Index(fn, "."); idx >= 0 {
- fn = fn[idx+1:] // Remove package name, keep (*Type).Method
- }
- fmt.Fprintf(&sb, "%s()\n", fn)
- fmt.Fprintf(&sb, " %s:%d\n", frame.File, frame.Line)
- }
-
- return sb.String()
-}
-
-type ExceptionStackTrace struct {
- TransactionId *string `json:"transactionId"`
- StackTrace string `json:"stackTrace"`
- RecordedAt time.Time `json:"recordedAt"`
- Scope map[string]string `json:"scope,omitempty"`
- IsMessage bool `json:"isMessage"`
-}
-
-type MetricRecord struct {
- Name string `json:"name"`
- Value float64 `json:"value"`
- RecordedAt time.Time `json:"recordedAt"`
-}
-
-type Transaction struct {
- Id string `json:"id"`
- Endpoint string `json:"endpoint"`
- Duration time.Duration `json:"duration"`
- RecordedAt time.Time `json:"recordedAt"`
- StatusCode int `json:"statusCode"`
- BodySize int `json:"bodySize"`
- ClientIP string `json:"clientIP"`
- Scope map[string]string `json:"scope,omitempty"`
- Segments []Segment `json:"segments,omitempty"`
-}
-
-// Segment represents a timed slice within a transaction
-type Segment struct {
- Id string `json:"id"`
- Name string `json:"name"`
- StartTime time.Time `json:"startTime"`
- Duration time.Duration `json:"duration"`
-}
-
-// ActiveSegment is a running segment that can be ended
-type ActiveSegment struct {
- segment Segment
- txn *TransactionContext
- startedAt time.Time
- ended bool
- mu sync.Mutex
-}
-
-// End completes the segment and records its duration
-func (s *ActiveSegment) End() {
- if s == nil || s.txn == nil {
- return
- }
- s.mu.Lock()
- defer s.mu.Unlock()
-
- if s.ended {
- return // Already ended
- }
-
- s.ended = true
- s.segment.Duration = time.Since(s.startedAt)
- s.txn.AddSegment(s.segment)
-}
-
-type CollectionFrame struct {
- StackTraces []*ExceptionStackTrace `json:"stackTraces"`
- Metrics []*MetricRecord `json:"metrics"`
- Transactions []*Transaction `json:"transactions"`
-}
-
-type collectionFrameMessageType int
-
-const (
- CollectionFrameMessageTypeException = 0
- CollectionFrameMessageTypeMetric = 1
- CollectionFrameMessageTypeTransaction = 2
- CollectionFrameMessageTypeClearFrames = 3
-)
-
-type CollectionFrameMessage struct {
- msgType collectionFrameMessageType
- exceptionStackTrace *ExceptionStackTrace
- metric *MetricRecord
- transaction *Transaction
- collectionFramesToRemove []*CollectionFrame
-}
-
-type CollectionFrameStore struct {
- current *CollectionFrame
- currentSetAt time.Time
- sendQueue TypedRing[*CollectionFrame, CollectionFrame]
-
- mu sync.RWMutex
-
- stopCh chan struct{}
- wg sync.WaitGroup
-
- messageQueue chan CollectionFrameMessage
-
- lastUploadStarted *time.Time
-
- // Config fields
- apiUrl string
- token string
- debug bool
- maxCollectionFrames int
- collectionInterval time.Duration
- uploadTimeout time.Duration
- metricsInterval time.Duration
- version string
- serverName string
-}
-
-func InitCollectionFrameStore(
- apiUrl string,
- token string,
- debug bool,
- maxCollectionFrames int,
- collectionInterval time.Duration,
- uploadTimeout time.Duration,
- metricsInterval time.Duration,
- version string,
- serverName string,
-) *CollectionFrameStore {
- store := &CollectionFrameStore{
- current: nil,
- currentSetAt: time.Now(),
- sendQueue: InitTypedRing[*CollectionFrame](maxCollectionFrames),
- stopCh: make(chan struct{}),
- messageQueue: make(chan CollectionFrameMessage),
-
- apiUrl: apiUrl,
- token: token,
- debug: debug,
-
- maxCollectionFrames: maxCollectionFrames,
- collectionInterval: collectionInterval,
- uploadTimeout: uploadTimeout,
- metricsInterval: metricsInterval,
- version: version,
- serverName: serverName,
- }
-
- store.wg.Add(1)
- go store.process()
- go store.processMetrics()
-
- return store
-}
-
-const (
- MetricNameMemoryUsage = "mem.used"
- MetricNameMemoryTotal = "mem.total"
- MetricNameCpuUsage = "cpu.used_pcnt"
- MetricNameGoRoutines = "go.go_routines"
- MetricNameHeapObjects = "go.heap_objects"
- MetricNameNumGC = "go.num_gc"
- MetricNameGCPauseTotal = "go.gc_pause"
-)
-
-func (s *CollectionFrameStore) processMetrics() {
- metricsTicker := time.NewTicker(s.metricsInterval)
- defer metricsTicker.Stop()
-
- for {
- select {
- case <-s.stopCh:
- return
- case <-metricsTicker.C:
- s.safeProcessMetrics()
- }
- }
-}
-
-func (s *CollectionFrameStore) safeProcessMetrics() {
- defer func() {
- if r := recover(); r != nil {
- log.Print("Traceway: failed to get metrics data")
- }
- }()
- cpuPercent, err := cpu.GetCpuPercent(time.Second)
- if err == nil {
- CaptureMetric(MetricNameCpuUsage, cpuPercent)
- } else {
- if s.debug {
- log.Println("Traceway cpu not read", err)
- }
- }
-
- var m runtime.MemStats
- runtime.ReadMemStats(&m)
- CaptureMetric(MetricNameMemoryUsage, float64(m.Alloc)/1024/1024)
-
- totalMem, err := mem.GetTotalMemory()
- if err == nil && totalMem > 0 {
- // Convert bytes to MB for total system memory
- CaptureMetric(MetricNameMemoryTotal, float64(totalMem)/1024/1024)
- } else {
- if s.debug {
- log.Println("Traceway total mem not read", err)
- }
- }
- CaptureMetric(MetricNameGoRoutines, float64(runtime.NumGoroutine()))
- CaptureMetric(MetricNameHeapObjects, float64(m.HeapObjects))
- CaptureMetric(MetricNameNumGC, float64(m.NumGC))
- CaptureMetric(MetricNameGCPauseTotal, float64(m.PauseTotalNs))
-}
-func (s *CollectionFrameStore) process() {
- defer s.wg.Done()
-
- rotationTicker := time.NewTicker(s.collectionInterval)
- defer rotationTicker.Stop()
-
- for {
- select {
- case <-s.stopCh:
- return
- case <-rotationTicker.C:
- if s.current != nil {
- if s.currentSetAt.Before(time.Now().Add(-s.collectionInterval)) {
- s.rotateCurrentCollectionFrame()
- s.processSendQueue()
- }
- } else if s.sendQueue.len > 0 {
- s.processSendQueue()
- }
- case msg := <-s.messageQueue:
- if msg.msgType == CollectionFrameMessageTypeClearFrames {
- s.sendQueue.Remove(msg.collectionFramesToRemove)
- continue
- }
-
- if s.current == nil {
- // we need to start a new frame
- s.current = &CollectionFrame{}
- s.currentSetAt = time.Now()
- }
-
- switch msg.msgType {
- case CollectionFrameMessageTypeException:
- s.current.StackTraces = append(s.current.StackTraces, msg.exceptionStackTrace)
- case CollectionFrameMessageTypeMetric:
- s.current.Metrics = append(s.current.Metrics, msg.metric)
- case CollectionFrameMessageTypeTransaction:
- s.current.Transactions = append(s.current.Transactions, msg.transaction)
- }
- }
- }
-}
-func (s *CollectionFrameStore) rotateCurrentCollectionFrame() {
- s.sendQueue.Push(s.current)
- s.current = nil
-}
-func (s *CollectionFrameStore) processSendQueue() {
- // we are triggering an upload - we need to make sure no other uploads are going on
- if s.lastUploadStarted == nil || s.lastUploadStarted.Before(time.Now().Add(s.uploadTimeout)) {
- now := time.Now()
- s.lastUploadStarted = &now
- go s.triggerUpload(s.sendQueue.ReadAll())
- }
-}
-
-// Report adds an exception event to the current envelope
-func (s *CollectionFrameStore) triggerUpload(framesToSend []*CollectionFrame) {
- defer func() {
- if r := recover(); s.debug && r != nil {
- log.Print("Traceway: failed to upload the CollectionFrame")
- log.Println(r)
- debug.PrintStack()
- }
- }()
-
- jsonData, err := json.Marshal(gin.H{
- "collectionFrames": framesToSend,
- "appVersion": s.version,
- "serverName": s.serverName,
- })
- if err != nil {
- if s.debug {
- log.Printf("Traceway: failed to marshal frames: %v", err)
- }
- return
- }
-
- var buf bytes.Buffer
- gz := gzip.NewWriter(&buf)
- if _, err := gz.Write(jsonData); err != nil {
- if s.debug {
- log.Printf("Traceway: gz write failed: %v", err)
- }
- return
- }
- if err := gz.Close(); err != nil { // Close flushes the compressed data
- if s.debug {
- log.Printf("Traceway: gz write failed: %v", err)
- }
- return
- }
-
- req, err := http.NewRequest("POST", s.apiUrl, &buf)
- if err != nil {
- if s.debug {
- log.Printf("Traceway: failed to create request: %v", err)
- }
- return
- }
-
- req.Header.Set("Content-Type", "application/json")
- req.Header.Set("Authorization", "Bearer "+s.token)
- req.Header.Set("Content-Encoding", "gzip")
-
- client := &http.Client{}
- resp, err := client.Do(req)
- if err != nil {
- if s.debug {
- log.Printf("Traceway: failed to send request: %v", err)
- }
- return
- }
- defer resp.Body.Close()
-
- if resp.StatusCode == 200 {
- // we need to clear out the frames
- s.messageQueue <- CollectionFrameMessage{
- msgType: CollectionFrameMessageTypeClearFrames,
- collectionFramesToRemove: framesToSend,
- }
- }
-}
-
-var collectionFrameStore *CollectionFrameStore
-
-func PrintCollectionFrameMetrics() {
- val, _ := json.Marshal(collectionFrameStore.current)
- fmt.Println("current", string(val))
-
- fmt.Println("currentSetAt", collectionFrameStore.currentSetAt)
- fmt.Println("sendQueue", collectionFrameStore.sendQueue)
- fmt.Println("lastUploadStarted", collectionFrameStore.lastUploadStarted)
- fmt.Println("apiUrl", collectionFrameStore.apiUrl)
- fmt.Println("token", collectionFrameStore.token)
- fmt.Println("debug", collectionFrameStore.debug)
- fmt.Println("maxCollectionFrames", collectionFrameStore.maxCollectionFrames)
- fmt.Println("collectionInterval", collectionFrameStore.collectionInterval)
- fmt.Println("uploadTimeout", collectionFrameStore.uploadTimeout)
-}
-
-type TracewayOptions struct {
- debug bool
- maxCollectionFrames int
- collectionInterval time.Duration
- uploadTimeout time.Duration
- metricsInterval time.Duration
- version string
- serverName string
-}
-
-func NewTracewayOptions(options ...func(*TracewayOptions)) *TracewayOptions {
- svr := &TracewayOptions{
- maxCollectionFrames: 12,
- collectionInterval: 5 * time.Second,
- uploadTimeout: 2 * time.Second,
- metricsInterval: 30 * time.Second,
- version: "",
- serverName: getHostname(),
- }
- for _, o := range options {
- o(svr)
- }
- return svr
-}
-func WithDebug(val bool) func(*TracewayOptions) {
- return func(s *TracewayOptions) {
- s.debug = val
- }
-}
-func WithMaxCollectionFrames(val int) func(*TracewayOptions) {
- return func(s *TracewayOptions) {
- s.maxCollectionFrames = val
- }
-}
-func WithCollectionInterval(val time.Duration) func(*TracewayOptions) {
- return func(s *TracewayOptions) {
- s.collectionInterval = val
- }
-}
-func WithUploadTimeout(val time.Duration) func(*TracewayOptions) {
- return func(s *TracewayOptions) {
- s.uploadTimeout = val
- }
-}
-func WithMetricsInterval(val time.Duration) func(*TracewayOptions) {
- return func(s *TracewayOptions) {
- s.metricsInterval = val
- }
-}
-func WithVersion(val string) func(*TracewayOptions) {
- return func(s *TracewayOptions) {
- s.version = val
- }
-}
-func WithServerName(val string) func(*TracewayOptions) {
- return func(s *TracewayOptions) {
- s.serverName = val
- }
-}
-
-func Init(connectionString string, options ...func(*TracewayOptions)) error {
- if collectionFrameStore != nil {
- return fmt.Errorf("Second Traceway initialization detected")
- }
- connParts := strings.Split(connectionString, "@")
-
- token := connParts[0]
- apiUrl := connParts[1]
-
- tracewayOptions := NewTracewayOptions(options...)
-
- collectionFrameStore = InitCollectionFrameStore(
- apiUrl,
- token,
- tracewayOptions.debug,
- tracewayOptions.maxCollectionFrames,
- tracewayOptions.collectionInterval,
- tracewayOptions.uploadTimeout,
- tracewayOptions.metricsInterval,
- tracewayOptions.version,
- tracewayOptions.serverName,
- )
- return nil
-}
-
-func CaptureMetric(name string, value float64) {
- collectionFrameStore.messageQueue <- CollectionFrameMessage{
- msgType: CollectionFrameMessageTypeMetric,
- metric: &MetricRecord{
- Name: name,
- Value: value,
- RecordedAt: time.Now(),
- },
- }
-}
-
-// CaptureTransaction captures a transaction without scope (backward compatible)
-func CaptureTransaction(
- txn *TransactionContext,
- endpoint string,
- d time.Duration,
- startedAt time.Time,
- statusCode, bodySize int,
- clientIP string,
-) {
- CaptureTransactionWithScope(txn, endpoint, d, startedAt, statusCode, bodySize, clientIP, nil)
-}
-
-// CaptureTransactionWithScope captures a transaction with scope
-func CaptureTransactionWithScope(
- txn *TransactionContext,
- endpoint string,
- d time.Duration,
- startedAt time.Time,
- statusCode, bodySize int,
- clientIP string,
- scope map[string]string,
-) {
- if txn == nil {
- return
- }
- collectionFrameStore.messageQueue <- CollectionFrameMessage{
- msgType: CollectionFrameMessageTypeTransaction,
- transaction: &Transaction{
- Id: txn.Id,
- Endpoint: endpoint,
- Duration: d,
- RecordedAt: startedAt,
- StatusCode: statusCode,
- BodySize: bodySize,
- ClientIP: clientIP,
- Scope: scope,
- Segments: txn.GetSegments(),
- },
- }
-}
-
-// StartSegment starts a segment using transaction ID from context
-func StartSegment(ctx context.Context, name string) *ActiveSegment {
- txn := GetTransactionFromContext(ctx)
- if txn == nil {
- return nil
- }
- now := time.Now()
- return &ActiveSegment{
- segment: Segment{
- Id: uuid.NewString(),
- Name: name,
- StartTime: now,
- },
- txn: txn,
- startedAt: now,
- }
-}
-
-// CaptureTransactionException captures an exception linked to a transaction (backward compatible)
-func CaptureTransactionException(transactionId string, stacktrace string) {
- CaptureTransactionExceptionWithScope(transactionId, stacktrace, nil)
-}
-
-// CaptureTransactionExceptionWithScope captures an exception linked to a transaction with scope
-func CaptureTransactionExceptionWithScope(transactionId string, stacktrace string, scope map[string]string) {
- collectionFrameStore.messageQueue <- CollectionFrameMessage{
- msgType: CollectionFrameMessageTypeException,
- exceptionStackTrace: &ExceptionStackTrace{
- TransactionId: &transactionId,
- StackTrace: stacktrace,
- RecordedAt: time.Now(),
- Scope: scope,
- },
- }
-}
-
-// CaptureException captures an exception without context (backward compatible)
-func CaptureException(err error) {
- CaptureExceptionWithScope(err, nil, nil)
-}
-
-// CaptureExceptionWithScope captures an exception with scope
-func CaptureExceptionWithScope(err error, scope map[string]string, transactionId *string) {
- collectionFrameStore.messageQueue <- CollectionFrameMessage{
- msgType: CollectionFrameMessageTypeException,
- exceptionStackTrace: &ExceptionStackTrace{
- TransactionId: transactionId,
- StackTrace: FormatErrorWithStack(err, CaptureStack(2)),
- RecordedAt: time.Now(),
- Scope: scope,
- },
- }
-}
-
-// CaptureExceptionWithContext captures an exception extracting scope from context
-func CaptureExceptionWithContext(ctx context.Context, err error) {
- scope := GetScopeFromContext(ctx)
- CaptureExceptionWithScope(err, scope.GetTags(), GetTransactionIdFromContext(ctx))
-}
-
-// Recover recovers from panic and captures it (backward compatible, no scope)
-func Recover() {
- r := recover()
-
- if r != nil {
- collectionFrameStore.messageQueue <- CollectionFrameMessage{
- msgType: CollectionFrameMessageTypeException,
- exceptionStackTrace: &ExceptionStackTrace{
- TransactionId: nil,
- StackTrace: FormatRWithStack(r, CaptureStack(2)),
- RecordedAt: time.Now(),
- },
- }
- }
-}
-
-// RecoverWithContext recovers from panic and captures it with scope from context
-func RecoverWithContext(ctx context.Context) {
- r := recover()
-
- if r != nil {
- scope := GetScopeFromContext(ctx)
- collectionFrameStore.messageQueue <- CollectionFrameMessage{
- msgType: CollectionFrameMessageTypeException,
- exceptionStackTrace: &ExceptionStackTrace{
- TransactionId: nil,
- StackTrace: FormatRWithStack(r, CaptureStack(2)),
- RecordedAt: time.Now(),
- Scope: scope.GetTags(),
- },
- }
- }
-}
-
-// CaptureMessage captures a message as an exception with minimal stack trace
-func CaptureMessage(msg string) {
- CaptureMessageWithContext(context.Background(), msg)
-}
-
-// CaptureMessageWithContext captures a message with context as an exception
-func CaptureMessageWithContext(ctx context.Context, msg string) {
- if collectionFrameStore == nil {
- return
- }
-
- _, file, line, ok := runtime.Caller(1)
- if !ok {
- file = "unknown"
- line = 0
- }
-
- stackTrace := fmt.Sprintf("Message: %s\n at %s:%d", msg, file, line)
-
- scope := GetScopeFromContext(ctx)
- collectionFrameStore.messageQueue <- CollectionFrameMessage{
- msgType: CollectionFrameMessageTypeException,
- exceptionStackTrace: &ExceptionStackTrace{
- TransactionId: GetTransactionIdFromContext(ctx),
- StackTrace: stackTrace,
- RecordedAt: time.Now(),
- Scope: scope.GetTags(),
- IsMessage: true,
- },
- }
-}
diff --git a/clients/go-client/traceway_gin/traceway_gin.go b/clients/go-client/traceway_gin/traceway_gin.go
deleted file mode 100644
index 1a63e467..00000000
--- a/clients/go-client/traceway_gin/traceway_gin.go
+++ /dev/null
@@ -1,110 +0,0 @@
-package tracewaygin
-
-import (
- "context"
- "net/http"
- "os"
- "sync"
- "time"
- "go.tracewayapp.com"
-
- "github.com/gin-gonic/gin"
- "github.com/google/uuid"
-)
-
-// Cached values for default scope tags
-var (
- cachedHostname string
- cachedEnvironment string
- initOnce sync.Once
-)
-
-func initCachedValues() {
- initOnce.Do(func() {
- hostname, err := os.Hostname()
- if err != nil {
- cachedHostname = "unknown"
- } else {
- cachedHostname = hostname
- }
-
- cachedEnvironment = os.Getenv("TRACEWAY_ENV")
- if cachedEnvironment == "" {
- cachedEnvironment = os.Getenv("GO_ENV")
- }
- if cachedEnvironment == "" {
- cachedEnvironment = "development"
- }
- })
-}
-
-func wrapAndExecute(c *gin.Context) (s *string) {
- defer func() {
- if r := recover(); r != nil {
- m := traceway.FormatRWithStack(r, traceway.CaptureStack(2))
- s = &m
- // we don't propagate just report
- c.AbortWithStatus(http.StatusInternalServerError)
- }
- }()
- c.Next()
- return nil
-}
-
-func New(connectionString string, options ...func(*traceway.TracewayOptions)) gin.HandlerFunc {
- traceway.Init(connectionString, options...)
- initCachedValues()
-
- return func(c *gin.Context) {
- start := time.Now()
-
- method := c.Request.Method
- clientIP := c.ClientIP()
-
- // Create transaction context
- txn := &traceway.TransactionContext{
- Id: uuid.NewString(),
- }
-
- // Create request-scoped scope with defaults
- scope := traceway.NewScope()
-
- // Store scope and transaction in both gin.Context and request context
- ctx := context.WithValue(c.Request.Context(), string(traceway.CtxScopeKey), scope)
- ctx = context.WithValue(ctx, string(traceway.CtxTransactionKey), txn)
- c.Request = c.Request.WithContext(ctx)
- c.Set(string(traceway.CtxScopeKey), scope)
- c.Set(string(traceway.CtxTransactionKey), txn)
-
- stackTraceFormatted := wrapAndExecute(c)
-
- duration := time.Since(start)
-
- statusCode := c.Writer.Status()
- bodySize := c.Writer.Size()
-
- if bodySize < 0 {
- bodySize = 0
- }
-
- // Use the registered route pattern (e.g., /users/:id) instead of actual path
- routePath := c.FullPath()
- if routePath == "" {
- // Fallback to actual path for unmatched routes
- routePath = c.Request.URL.Path
- }
-
- transactionEndpoint := method + " " + routePath
-
- defer recover()
-
- // Capture transaction with scope
- traceway.CaptureTransactionWithScope(txn, transactionEndpoint, duration, start, statusCode, bodySize, clientIP, scope.GetTags())
-
- if stackTraceFormatted != nil {
- exceptionTags := scope.GetTags()
- exceptionTags["user_agent"] = c.Request.UserAgent() // we'll only store the user agent IF an exception happens
- traceway.CaptureTransactionExceptionWithScope(txn.Id, *stackTraceFormatted, exceptionTags)
- }
- }
-}
diff --git a/clients/go-client/typed_ring.go b/clients/go-client/typed_ring.go
deleted file mode 100644
index ed8efdd7..00000000
--- a/clients/go-client/typed_ring.go
+++ /dev/null
@@ -1,76 +0,0 @@
-package traceway
-
-type TypedRing[T *E, E any] struct {
- arr []T
- head int
- capacity int
- len int
-}
-
-func InitTypedRing[T *E, E any](capacity int) TypedRing[T, E] {
- return TypedRing[T, E]{
- arr: make([]T, capacity),
- capacity: capacity,
- }
-}
-
-func (t *TypedRing[T, E]) Push(val T) {
- t.arr[t.head] = val
- t.head = (t.head + 1) % t.capacity
- if t.len < t.capacity {
- t.len += 1
- }
-}
-
-func (t *TypedRing[T, E]) ReadAll() []T {
- result := make([]T, t.len)
- for i := 0; i < t.len; i++ {
- idx := (t.head - t.len + i + t.capacity) % t.capacity
- result[i] = t.arr[idx]
- }
- return result
-}
-
-func (t *TypedRing[T, E]) Clear() {
- for i := range t.arr {
- t.arr[i] = nil
- }
- t.head = 0
- t.len = 0
-}
-
-func (t *TypedRing[T, E]) Remove(vals []T) int {
- if len(vals) == 0 {
- return 0
- }
-
- toRemove := make(map[T]struct{}, len(vals))
- for _, v := range vals {
- toRemove[v] = struct{}{}
- }
-
- writeIdx := 0
- removed := 0
- for i := 0; i < t.len; i++ {
- readIdx := (t.head - t.len + i + t.capacity) % t.capacity
- if _, shouldRemove := toRemove[t.arr[readIdx]]; shouldRemove {
- removed++
- } else {
- if writeIdx != i {
- destIdx := (t.head - t.len + writeIdx + t.capacity) % t.capacity
- t.arr[destIdx] = t.arr[readIdx]
- }
- writeIdx++
- }
- }
-
- for i := writeIdx; i < t.len; i++ {
- idx := (t.head - t.len + i + t.capacity) % t.capacity
- t.arr[idx] = nil
- }
-
- t.len = writeIdx
- t.head = (t.head - removed + t.capacity) % t.capacity
-
- return removed
-}
diff --git a/go-tracewayapp-com/index.html b/go-tracewayapp-com/index.html
deleted file mode 100644
index aa154e99..00000000
--- a/go-tracewayapp-com/index.html
+++ /dev/null
@@ -1,9 +0,0 @@
-<!DOCTYPE html>
-<html>
-<head>
- <meta name="go-import" content="go.tracewayapp.com git https://github.com/tracewayapp/traceway">
-</head>
-<body>
- <a href="https://pkg.go.dev/go.tracewayapp.com">Documentation</a>
-</body>
-</html>
diff --git a/scripts/release-go-client.sh b/scripts/release-go-client.sh
deleted file mode 100755
index adff81ee..00000000
--- a/scripts/release-go-client.sh
+++ /dev/null
@@ -1,93 +0,0 @@
-#!/bin/bash
-set -e
-
-# Release script for go.tracewayapp.com Go client library
-
-SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
-PROJECT_ROOT="$(dirname "$SCRIPT_DIR")"
-GO_CLIENT_DIR="$PROJECT_ROOT/clients/go-client"
-
-# Colors for output
-RED='\033[0;31m'
-GREEN='\033[0;32m'
-YELLOW='\033[1;33m'
-NC='\033[0m' # No Color
-
-usage() {
- echo "Usage: $0 <version>"
- echo ""
- echo "Arguments:"
- echo " version Semantic version (e.g., v1.0.0, v0.1.0)"
- echo ""
- echo "Examples:"
- echo " $0 v1.0.0"
- echo " $0 v0.2.1"
- exit 1
-}
-
-# Check for version argument
-if [ -z "$1" ]; then
- echo -e "${RED}Error: Version argument required${NC}"
- usage
-fi
-
-VERSION="$1"
-
-# Validate semver format (vX.Y.Z)
-if ! [[ "$VERSION" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
- echo -e "${RED}Error: Invalid version format '$VERSION'${NC}"
- echo "Version must be in semver format: vX.Y.Z (e.g., v1.0.0)"
- exit 1
-fi
-
-echo -e "${GREEN}=== Releasing go.tracewayapp.com $VERSION ===${NC}"
-echo ""
-
-# Change to go-client directory
-cd "$GO_CLIENT_DIR"
-echo -e "${YELLOW}Working directory: $GO_CLIENT_DIR${NC}"
-echo ""
-
-# Verify the build
-echo -e "${YELLOW}Building library...${NC}"
-go build ./...
-echo -e "${GREEN}Build successful${NC}"
-echo ""
-
-# Run vet
-echo -e "${YELLOW}Running go vet...${NC}"
-go vet ./...
-echo -e "${GREEN}Vet passed${NC}"
-echo ""
-
-# Check for uncommitted changes
-cd "$PROJECT_ROOT"
-if [ -n "$(git status --porcelain)" ]; then
- echo -e "${RED}Error: You have uncommitted changes${NC}"
- echo "Please commit all changes before releasing."
- git status --short
- exit 1
-fi
-
-# Create the tag
-TAG="clients/go-client/$VERSION"
-echo -e "${YELLOW}Creating tag: $TAG${NC}"
-
-git tag -a "$TAG" -m "Release go.tracewayapp.com $VERSION"
-echo -e "${GREEN}Tag created${NC}"
-echo ""
-
-# Push the tag
-echo -e "${YELLOW}Pushing tag to origin...${NC}"
-git push origin "$TAG"
-echo -e "${GREEN}Tag pushed${NC}"
-echo ""
-
-echo -e "${GREEN}=== Release Complete ===${NC}"
-echo ""
-echo "Next steps:"
-echo "1. The Go module proxy will automatically pick up the new version"
-echo "2. Users can install with: go get go.tracewayapp.com@$VERSION"
-echo ""
-echo "Note: Make sure go.tracewayapp.com is configured to redirect to your Git repository."
-echo "See: https://go.dev/ref/mod#vcs-find for vanity import setup"