File: capture_context.go

package info (click to toggle)
golang-gitlab-gitlab-org-labkit 1.17.0-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,092 kB
  • sloc: sh: 210; javascript: 49; makefile: 4
file content (20 lines) | stat: -rw-r--r-- 500 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
package errortracking

import (
	"context"

	"github.com/getsentry/sentry-go"
	"gitlab.com/gitlab-org/labkit/correlation"
)

const sentryExtraKey = "gitlab.CorrelationID"

// WithContext will extract information from the context to add to the error.
func WithContext(ctx context.Context) CaptureOption {
	return func(config *captureConfig, event *sentry.Event) {
		correlationID := correlation.ExtractFromContext(ctx)
		if correlationID != "" {
			event.Tags[sentryExtraKey] = correlationID
		}
	}
}