Skip to content

Commit

Permalink
godocs
Browse files Browse the repository at this point in the history
  • Loading branch information
colesnodgrass committed Oct 15, 2024
1 parent 7aeb2f0 commit 9454dfc
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 17 deletions.
2 changes: 1 addition & 1 deletion internal/cmd/local/helm/airbyte_values.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import (
"fmt"

"github.com/airbytehq/abctl/internal/maps"
"github.com/airbytehq/abctl/internal/trace"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/trace"
)

type ValuesOpts struct {
Expand Down
3 changes: 2 additions & 1 deletion internal/cmd/local/local/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
helmclient "github.com/mittwald/go-helm-client"
"github.com/pterm/pterm"
"go.opentelemetry.io/otel/attribute"
oteltrace "go.opentelemetry.io/otel/trace"
"helm.sh/helm/v3/pkg/action"
"helm.sh/helm/v3/pkg/chart"
"helm.sh/helm/v3/pkg/release"
Expand Down Expand Up @@ -459,7 +460,7 @@ func captureAttributes(ctx context.Context, msg string) {
return
}

trace.SpanFromContext(ctx).SetAttributes(attribute.String(
oteltrace.SpanFromContext(ctx).SetAttributes(attribute.String(
"pulled "+strings.Trim(parts[3], `"`),
strings.Join(parts[5:], " "),
))
Expand Down
37 changes: 22 additions & 15 deletions internal/trace/trace.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,21 @@ import (
"go.opentelemetry.io/otel/trace"
)

const tracerName = "github.com/airbytehq/abctl/trace"
const (
// traceName is the name of the otel tracer
tracerName = "github.com/airbytehq/abctl/trace"
// redactedUserHome is the redacted user home directory
redactedUserHome = "[USER_HOME]"
)

var (
// may not be required
// May not be required, it is unclear if a tracer should be instantiated more than once.
once sync.Once
tracer trace.Tracer
)

// NewSpan initializes the otel tracer, if necessary, and starts a new span with
// the provided name. The returned span will be added to the returned context.
func NewSpan(ctx context.Context, name string) (context.Context, trace.Span) {
once.Do(func() {
tracer = otel.Tracer(tracerName)
Expand All @@ -48,24 +55,28 @@ func AttachLog(name, body string) {
})
}

func SpanFromContext(ctx context.Context) trace.Span {
return trace.SpanFromContext(ctx)
}

// SpanError marks the span with the provided err.
// Returns the same error provided.
func SpanError(span trace.Span, err error) error {
if err == nil {
return nil
}
span.RecordError(err)
span.SetStatus(codes.Error, strings.ReplaceAll(err.Error(), paths.UserHome, userHome))
span.SetStatus(codes.Error, strings.ReplaceAll(err.Error(), paths.UserHome, redactedUserHome))
sentry.CaptureException(err)
return err
}

// CaptureError retrieves the span from the ctx and marks it with the provided err.
// Returns the same error provided.
func CaptureError(ctx context.Context, err error) error {
span := trace.SpanFromContext(ctx)
return SpanError(span, err)
}

type Shutdown func()

// Init initializes the otel framework.
func Init(ctx context.Context) ([]Shutdown, error) {
dsn := "https://[email protected]/4507177762357248"
// TODO: combine telemetry and trace packages?
Expand All @@ -77,7 +88,6 @@ func Init(ctx context.Context) ([]Shutdown, error) {
err := sentry.Init(sentry.ClientOptions{
Dsn: dsn,
EnableTracing: true,
Environment: "dev",
Release: build.Version,
TracesSampleRate: 1.0,
ProfilesSampleRate: 1.0,
Expand Down Expand Up @@ -113,23 +123,20 @@ func Init(ctx context.Context) ([]Shutdown, error) {
return cleanups, nil
}

// userHome is the redacted user home directory
const userHome = "[USER_HOME]"

// removePII removes potentially PII information that may be contained within the trace data.
func removePII(event *sentry.Event, _ *sentry.EventHint) *sentry.Event {
// message
event.Message = strings.ReplaceAll(event.Message, paths.UserHome, userHome)
event.Message = strings.ReplaceAll(event.Message, paths.UserHome, redactedUserHome)

// errors
for _, ex := range event.Exception {
ex.Value = strings.ReplaceAll(ex.Value, paths.UserHome, userHome)
ex.Value = strings.ReplaceAll(ex.Value, paths.UserHome, redactedUserHome)
}

// spans
for _, span := range event.Spans {
span.Name = strings.ReplaceAll(span.Name, paths.UserHome, userHome)
span.Description = strings.ReplaceAll(span.Description, paths.UserHome, userHome)
span.Name = strings.ReplaceAll(span.Name, paths.UserHome, redactedUserHome)
span.Description = strings.ReplaceAll(span.Description, paths.UserHome, redactedUserHome)
}

return event
Expand Down

0 comments on commit 9454dfc

Please sign in to comment.