gitlab.com/gitlab-org/labkit@v1.21.0/errortracking/capture_context.go (about)

     1  package errortracking
     2  
     3  import (
     4  	"context"
     5  
     6  	"github.com/getsentry/sentry-go"
     7  	"gitlab.com/gitlab-org/labkit/correlation"
     8  )
     9  
    10  const sentryExtraKey = "gitlab.CorrelationID"
    11  
    12  // WithContext will extract information from the context to add to the error.
    13  func WithContext(ctx context.Context) CaptureOption {
    14  	return func(config *captureConfig, event *sentry.Event) {
    15  		correlationID := correlation.ExtractFromContext(ctx)
    16  		if correlationID != "" {
    17  			event.Tags[sentryExtraKey] = correlationID
    18  		}
    19  	}
    20  }