Skip to content

Commit

Permalink
Adjust sentry context (#94)
Browse files Browse the repository at this point in the history
* Enrich sentry context

* fix

* fix

* upd

* fix

* upd

* Delete sentry internal
  • Loading branch information
corest authored Sep 14, 2024
1 parent ac1c568 commit 53f4613
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 99 deletions.
9 changes: 5 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
module github.com/kubeshark/tracer

go 1.22.0
go 1.22.2

toolchain go1.22.5
toolchain go1.22.7

require (
github.com/Masterminds/semver v1.5.0
github.com/archdx/zerolog-sentry v1.8.4
github.com/cilium/ebpf v0.12.3
github.com/dlclark/regexp2 v1.11.0
github.com/florianl/go-tc v0.4.3
github.com/getsentry/sentry-go v0.28.1
github.com/getsentry/sentry-go v0.29.0
github.com/gin-contrib/pprof v1.4.0
github.com/gin-gonic/gin v1.9.1
github.com/go-errors/errors v1.4.2
Expand All @@ -19,9 +19,10 @@ require (
github.com/hashicorp/golang-lru/v2 v2.0.2
github.com/jinzhu/copier v0.4.0
github.com/knightsc/gapstone v0.0.0-20191231144527-6fa5afaf11a9
github.com/kubeshark/api v1.1.16
github.com/kubeshark/api v1.1.20
github.com/kubeshark/gopacket v1.1.30
github.com/kubeshark/tracerproto v1.0.3-0.20240730073449-de3a99a3719c
github.com/kubeshark/utils v0.0.0-20240912210808-416dca610f11
github.com/moby/moby v25.0.4+incompatible
github.com/rs/zerolog v1.32.0
github.com/struCoder/pidusage v0.2.1
Expand Down
10 changes: 8 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ github.com/frankban/quicktest v1.14.5 h1:dfYrrRyLtiqT9GyKXgdh+k4inNeTvmGbuSgZ3lx
github.com/frankban/quicktest v1.14.5/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0=
github.com/gabriel-vasile/mimetype v1.4.3 h1:in2uUcidCuFcDKtdcBxlR0rJ1+fsokWf+uqxgUFjbI0=
github.com/gabriel-vasile/mimetype v1.4.3/go.mod h1:d8uq/6HKRL6CGdk+aubisF/M5GcPfT7nKyLpA0lbSSk=
github.com/getsentry/sentry-go v0.28.1 h1:zzaSm/vHmGllRM6Tpx1492r0YDzauArdBfkJRtY6P5k=
github.com/getsentry/sentry-go v0.28.1/go.mod h1:1fQZ+7l7eeJ3wYi82q5Hg8GqAPgefRq+FP/QhafYVgg=
github.com/getsentry/sentry-go v0.29.0 h1:YtWluuCFg9OfcqnaujpY918N/AhCCwarIDWOYSBAjCA=
github.com/getsentry/sentry-go v0.29.0/go.mod h1:jhPesDAL0Q0W2+2YEuVOvdWmVtdsr1+jtBrlDEVWwLY=
github.com/gin-contrib/pprof v1.4.0 h1:XxiBSf5jWZ5i16lNOPbMTVdgHBdhfGRD5PZ1LWazzvg=
github.com/gin-contrib/pprof v1.4.0/go.mod h1:RrehPJasUVBPK6yTUwOl8/NP6i0vbUgmxtis+Z5KE90=
github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE=
Expand Down Expand Up @@ -150,11 +150,17 @@ github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/kubeshark/api v1.1.16 h1:E9MlBpc4zpCE2847+/myEBmug+q6zn4y1nMSUMCKYwI=
github.com/kubeshark/api v1.1.16/go.mod h1:13xpBdys1s9gozDtv29njdT3Rx3xl2ZICgdsFXwqk40=
github.com/kubeshark/api v1.1.20 h1:ZE8dBHalyc8OriBOLQ7Olpzjox6Tka/Z0xohIJmGiB4=
github.com/kubeshark/api v1.1.20/go.mod h1:13xpBdys1s9gozDtv29njdT3Rx3xl2ZICgdsFXwqk40=
github.com/kubeshark/gopacket v1.1.30 h1:Dz6eo7b6+NdVCrgiyKxlGEVTm0L6PwgbVvSomsuwIyU=
github.com/kubeshark/gopacket v1.1.30/go.mod h1:Qo8/i/tdT74CCT7/pjO0L55Pktv5dQfj7M/Arv8MKm8=
github.com/kubeshark/tracerproto v1.0.0/go.mod h1:+efDYkwXxwakmHRpxHVEekyXNtg/aFx0uSo/I0lGV9k=
github.com/kubeshark/tracerproto v1.0.3-0.20240730073449-de3a99a3719c h1:Km6Wm+AwCRO/6aK60PqGpW6bVuXNw+bbZRjX837N/rU=
github.com/kubeshark/tracerproto v1.0.3-0.20240730073449-de3a99a3719c/go.mod h1:+efDYkwXxwakmHRpxHVEekyXNtg/aFx0uSo/I0lGV9k=
github.com/kubeshark/utils v0.0.0-20240912114101-271ed42ebd29 h1:O/t6Nd12MyX6flppOojsAh0gS1pjb0VdsdyxmIEFbjQ=
github.com/kubeshark/utils v0.0.0-20240912114101-271ed42ebd29/go.mod h1:vrL5XTDuLYGhVv/UGEsx+fwbAHcvTUJoP8ApHG11JcQ=
github.com/kubeshark/utils v0.0.0-20240912210808-416dca610f11 h1:g+f7OCI1onHRqEqE5dMlhLfwfdxFI9wmeOvlUaxNzPQ=
github.com/kubeshark/utils v0.0.0-20240912210808-416dca610f11/go.mod h1:vrL5XTDuLYGhVv/UGEsx+fwbAHcvTUJoP8ApHG11JcQ=
github.com/leodido/go-urn v1.2.1/go.mod h1:zt4jvISO2HfUBqxjfIshjdMTYS56ZS/qv49ictyFfxY=
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=
Expand Down
25 changes: 20 additions & 5 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,13 @@ import (
"github.com/kubeshark/tracer/pkg/kubernetes"
"github.com/kubeshark/tracer/pkg/version"
"github.com/kubeshark/tracer/server"
sentrypkg "github.com/kubeshark/utils/sentry"
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
"k8s.io/apimachinery/pkg/types"
"k8s.io/client-go/rest"

"github.com/kubeshark/tracer/pkg/health"

sentrypkg "github.com/kubeshark/tracer/pkg/sentry"
)

const (
Expand Down Expand Up @@ -60,9 +59,9 @@ var tracer *Tracer
func main() {
var sentryDSN string
if sentrypkg.IsSentryEnabled() {
sentryDSN, error := sentrypkg.GetDSN(context.Background())
if error != nil {
log.Error().Err(error).Msg("Failed to get Sentry DSN")
sentryDSN, err := sentrypkg.GetDSN(context.Background(), "tracer", version.Ver)
if err != nil {
log.Error().Err(err).Msg("Failed to get Sentry DSN")
}

// To initialize Sentry's handler, you need to initialize Sentry itself beforehand
Expand All @@ -74,6 +73,7 @@ func main() {
// We recommend adjusting this value in production,
TracesSampleRate: 1.0,
Release: version.Ver,
Environment: sentrypkg.Environment(),
}); err != nil {
log.Error().Err(err).Msg("Sentry initialization failed:")
} else {
Expand Down Expand Up @@ -141,6 +141,8 @@ func run() {

go health.DumpHealthEvery10Seconds(nodeName)

enrichSentryContext(watcher)

if clusterMode {
misc.SetDataDir(fmt.Sprintf("/app/data/%s", nodeName))
}
Expand Down Expand Up @@ -197,3 +199,16 @@ func createTracer() (err error) {

return
}

func enrichSentryContext(watcher *kubernetes.Watcher) {
clusterId, err := kubernetes.GetClusterID(watcher)
if err != nil {
log.Error().Err(err).Msg("Failed to get cluster ID for Sentry tag")
}

tags := map[string]string{
"clusterID": clusterId,
}

sentrypkg.AddTags(tags)
}
15 changes: 15 additions & 0 deletions pkg/kubernetes/utils.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package kubernetes

import (
"context"
"os"
"strings"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

const (
Expand Down Expand Up @@ -36,3 +39,15 @@ func GetSelfPodName() string {
}
return ""
}

// GetClusterID returns the UID field of the `kube-system` namespace object
// This is used as a unique identifier for the cluster
func GetClusterID(watcher *Watcher) (string, error) {

namespaceObj, err := watcher.clientSet.CoreV1().Namespaces().Get(context.Background(), "kube-system", metav1.GetOptions{})
if err != nil {
return "", err
}

return string(namespaceObj.GetUID()), nil
}
88 changes: 0 additions & 88 deletions pkg/sentry/sentry.go

This file was deleted.

0 comments on commit 53f4613

Please sign in to comment.