Skip to content

Commit

Permalink
feat: add user ID to sentry telemetry (#142)
Browse files Browse the repository at this point in the history
  • Loading branch information
abuchanan-airbyte authored Oct 30, 2024
1 parent a58bc83 commit 2cde3ab
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 7 deletions.
2 changes: 0 additions & 2 deletions internal/cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"github.com/airbytehq/abctl/internal/cmd/local"
"github.com/airbytehq/abctl/internal/cmd/local/k8s"
"github.com/airbytehq/abctl/internal/cmd/version"
"github.com/airbytehq/abctl/internal/telemetry"
"github.com/alecthomas/kong"
"github.com/pterm/pterm"
)
Expand All @@ -28,6 +27,5 @@ type Cmd struct {

func (c *Cmd) BeforeApply(ctx context.Context, kCtx *kong.Context) error {
kCtx.BindTo(k8s.DefaultProvider, (*k8s.Provider)(nil))
kCtx.BindTo(telemetry.Get(), (*telemetry.Client)(nil))
return nil
}
2 changes: 1 addition & 1 deletion internal/cmd/local/local/install_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ func TestCommand_Install(t *testing.T) {
}

installOpts := &InstallOpts{
HelmValuesYaml: valuesYaml,
HelmValuesYaml: valuesYaml,
AirbyteChartLoc: testAirbyteChartLoc,
}
if err := c.Install(context.Background(), installOpts); err != nil {
Expand Down
6 changes: 5 additions & 1 deletion internal/trace/trace.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func CaptureError(ctx context.Context, err error) error {
type Shutdown func()

// Init initializes the otel framework.
func Init(ctx context.Context) ([]Shutdown, error) {
func Init(ctx context.Context, userId string) ([]Shutdown, error) {
dsn := "https://9e0748223d5bc43e873f811a849e982e@o1009025.ingest.us.sentry.io/4507177762357248"
// TODO: combine telemetry and trace packages?
if telemetry.DNT() {
Expand Down Expand Up @@ -112,6 +112,10 @@ func Init(ctx context.Context) ([]Shutdown, error) {
),
)

sentry.ConfigureScope(func(scope *sentry.Scope) {
scope.SetUser(sentry.User{ID: userId})
})

tracerProvider := sdktrace.NewTracerProvider(
sdktrace.WithSpanProcessor(sentryotel.NewSentrySpanProcessor()),
sdktrace.WithResource(r),
Expand Down
8 changes: 5 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/airbytehq/abctl/internal/build"
"github.com/airbytehq/abctl/internal/cmd"
"github.com/airbytehq/abctl/internal/cmd/local/localerr"
"github.com/airbytehq/abctl/internal/telemetry"
"github.com/airbytehq/abctl/internal/trace"
"github.com/airbytehq/abctl/internal/update"
"github.com/alecthomas/kong"
Expand All @@ -31,12 +32,12 @@ func run() int {
defer stop()
printUpdateMsg := checkForNewerAbctlVersion(ctx)

shutdowns, err := trace.Init(ctx)
telClient := telemetry.Get()

shutdowns, err := trace.Init(ctx, telClient.User())
if err != nil {
pterm.Debug.Printf(fmt.Sprintf("Trace disabled: %s", err))
}
//ctx, span := trace.NewSpan(ctx, "run")
//defer span.End()
defer func() {
for _, shutdown := range shutdowns {
shutdown()
Expand All @@ -51,6 +52,7 @@ func run() int {
kong.Description("Airbyte's command line tool for managing a local Airbyte installation."),
kong.UsageOnError(),
kong.BindToProvider(bindCtx(ctx)),
kong.BindTo(telClient, (*telemetry.Client)(nil)),
)
if err != nil {
return err
Expand Down

0 comments on commit 2cde3ab

Please sign in to comment.