mirror of
https://github.com/ManyakRus/starter.git
synced 2025-11-28 23:20:10 +02:00
сделал make mod
This commit is contained in:
150
vendor/github.com/getsentry/sentry-go/tracing.go
generated
vendored
150
vendor/github.com/getsentry/sentry-go/tracing.go
generated
vendored
@@ -18,6 +18,20 @@ const (
|
||||
SentryBaggageHeader = "baggage"
|
||||
)
|
||||
|
||||
// SpanOrigin indicates what created a trace or a span. See: https://develop.sentry.dev/sdk/performance/trace-origin/
|
||||
type SpanOrigin string
|
||||
|
||||
const (
|
||||
SpanOriginManual = "manual"
|
||||
SpanOriginEcho = "auto.http.echo"
|
||||
SpanOriginFastHTTP = "auto.http.fasthttp"
|
||||
SpanOriginFiber = "auto.http.fiber"
|
||||
SpanOriginGin = "auto.http.gin"
|
||||
SpanOriginStdLib = "auto.http.stdlib"
|
||||
SpanOriginIris = "auto.http.iris"
|
||||
SpanOriginNegroni = "auto.http.negroni"
|
||||
)
|
||||
|
||||
// A Span is the building block of a Sentry transaction. Spans build up a tree
|
||||
// structure of timed operations. The span tree makes up a transaction event
|
||||
// that is sent to Sentry when the root span is finished.
|
||||
@@ -37,6 +51,7 @@ type Span struct { //nolint: maligned // prefer readability over optimal memory
|
||||
Data map[string]interface{} `json:"data,omitempty"`
|
||||
Sampled Sampled `json:"-"`
|
||||
Source TransactionSource `json:"-"`
|
||||
Origin SpanOrigin `json:"origin,omitempty"`
|
||||
|
||||
// mu protects concurrent writes to map fields
|
||||
mu sync.RWMutex
|
||||
@@ -113,11 +128,19 @@ func StartSpan(ctx context.Context, operation string, options ...SpanOption) *Sp
|
||||
parent: parent,
|
||||
}
|
||||
|
||||
_, err := rand.Read(span.SpanID[:])
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
if hasParent {
|
||||
span.TraceID = parent.TraceID
|
||||
span.ParentSpanID = parent.SpanID
|
||||
span.Origin = parent.Origin
|
||||
} else {
|
||||
// Only set the Source if this is a transaction
|
||||
span.Source = SourceCustom
|
||||
span.Origin = SpanOriginManual
|
||||
|
||||
// Implementation note:
|
||||
//
|
||||
@@ -154,13 +177,6 @@ func StartSpan(ctx context.Context, operation string, options ...SpanOption) *Sp
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
_, err := rand.Read(span.SpanID[:])
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
if hasParent {
|
||||
span.ParentSpanID = parent.SpanID
|
||||
}
|
||||
|
||||
// Apply options to override defaults.
|
||||
for _, option := range options {
|
||||
@@ -169,18 +185,22 @@ func StartSpan(ctx context.Context, operation string, options ...SpanOption) *Sp
|
||||
|
||||
span.Sampled = span.sample()
|
||||
|
||||
span.recorder = &spanRecorder{}
|
||||
if hasParent {
|
||||
span.recorder = parent.spanRecorder()
|
||||
} else {
|
||||
span.recorder = &spanRecorder{}
|
||||
}
|
||||
|
||||
span.recorder.record(&span)
|
||||
|
||||
hub := hubFromContext(ctx)
|
||||
|
||||
// Update scope so that all events include a trace context, allowing
|
||||
// Sentry to correlate errors to transactions/spans.
|
||||
hub.Scope().SetContext("trace", span.traceContext().Map())
|
||||
clientOptions := span.clientOptions()
|
||||
if clientOptions.EnableTracing {
|
||||
hub := hubFromContext(ctx)
|
||||
if !span.IsTransaction() {
|
||||
// Push a new scope to stack for non transaction span
|
||||
hub.PushScope()
|
||||
}
|
||||
hub.Scope().SetSpan(&span)
|
||||
}
|
||||
|
||||
// Start profiling only if it's a sampled root transaction.
|
||||
if span.IsTransaction() && span.Sampled.Bool() {
|
||||
@@ -226,7 +246,11 @@ func (s *Span) SetTag(name, value string) {
|
||||
// SetData sets a data on the span. It is recommended to use SetData instead of
|
||||
// accessing the data map directly as SetData takes care of initializing the map
|
||||
// when necessary.
|
||||
func (s *Span) SetData(name, value string) {
|
||||
func (s *Span) SetData(name string, value interface{}) {
|
||||
if value == nil {
|
||||
return
|
||||
}
|
||||
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
|
||||
@@ -304,17 +328,21 @@ func (s *Span) ToSentryTrace() string {
|
||||
// Use this function to propagate the DynamicSamplingContext to a downstream SDK,
|
||||
// either as the value of the "baggage" HTTP header, or as an html "baggage" meta tag.
|
||||
func (s *Span) ToBaggage() string {
|
||||
if containingTransaction := s.GetTransaction(); containingTransaction != nil {
|
||||
// In case there is currently no frozen DynamicSamplingContext attached to the transaction,
|
||||
// create one from the properties of the transaction.
|
||||
if !s.dynamicSamplingContext.IsFrozen() {
|
||||
// This will return a frozen DynamicSamplingContext.
|
||||
s.dynamicSamplingContext = DynamicSamplingContextFromTransaction(containingTransaction)
|
||||
}
|
||||
|
||||
return containingTransaction.dynamicSamplingContext.String()
|
||||
t := s.GetTransaction()
|
||||
if t == nil {
|
||||
return ""
|
||||
}
|
||||
return ""
|
||||
|
||||
// In case there is currently no frozen DynamicSamplingContext attached to the transaction,
|
||||
// create one from the properties of the transaction.
|
||||
if !s.dynamicSamplingContext.IsFrozen() {
|
||||
// This will return a frozen DynamicSamplingContext.
|
||||
if dsc := DynamicSamplingContextFromTransaction(t); dsc.HasEntries() {
|
||||
t.dynamicSamplingContext = dsc
|
||||
}
|
||||
}
|
||||
|
||||
return t.dynamicSamplingContext.String()
|
||||
}
|
||||
|
||||
// SetDynamicSamplingContext sets the given dynamic sampling context on the
|
||||
@@ -331,6 +359,12 @@ func (s *Span) doFinish() {
|
||||
s.EndTime = monotonicTimeSince(s.StartTime)
|
||||
}
|
||||
|
||||
hub := hubFromContext(s.ctx)
|
||||
if !s.IsTransaction() {
|
||||
// Referenced to StartSpan function that pushes current non-transaction span to scope stack
|
||||
defer hub.PopScope()
|
||||
}
|
||||
|
||||
if !s.Sampled.Bool() {
|
||||
return
|
||||
}
|
||||
@@ -346,7 +380,6 @@ func (s *Span) doFinish() {
|
||||
// TODO(tracing): add breadcrumbs
|
||||
// (see https://github.com/getsentry/sentry-python/blob/f6f3525f8812f609/sentry_sdk/tracing.py#L372)
|
||||
|
||||
hub := hubFromContext(s.ctx)
|
||||
hub.CaptureEvent(event)
|
||||
}
|
||||
|
||||
@@ -530,7 +563,7 @@ func (s *Span) toEvent() *Event {
|
||||
s.dynamicSamplingContext = DynamicSamplingContextFromTransaction(s)
|
||||
}
|
||||
|
||||
contexts := map[string]Context{}
|
||||
contexts := make(map[string]Context, len(s.contexts)+1)
|
||||
for k, v := range s.contexts {
|
||||
contexts[k] = cloneContext(v)
|
||||
}
|
||||
@@ -702,31 +735,32 @@ const (
|
||||
maxSpanStatus
|
||||
)
|
||||
|
||||
var spanStatuses = [maxSpanStatus]string{
|
||||
"",
|
||||
"ok",
|
||||
"cancelled", // [sic]
|
||||
"unknown",
|
||||
"invalid_argument",
|
||||
"deadline_exceeded",
|
||||
"not_found",
|
||||
"already_exists",
|
||||
"permission_denied",
|
||||
"resource_exhausted",
|
||||
"failed_precondition",
|
||||
"aborted",
|
||||
"out_of_range",
|
||||
"unimplemented",
|
||||
"internal_error",
|
||||
"unavailable",
|
||||
"data_loss",
|
||||
"unauthenticated",
|
||||
}
|
||||
|
||||
func (ss SpanStatus) String() string {
|
||||
if ss >= maxSpanStatus {
|
||||
return ""
|
||||
}
|
||||
m := [maxSpanStatus]string{
|
||||
"",
|
||||
"ok",
|
||||
"cancelled", // [sic]
|
||||
"unknown",
|
||||
"invalid_argument",
|
||||
"deadline_exceeded",
|
||||
"not_found",
|
||||
"already_exists",
|
||||
"permission_denied",
|
||||
"resource_exhausted",
|
||||
"failed_precondition",
|
||||
"aborted",
|
||||
"out_of_range",
|
||||
"unimplemented",
|
||||
"internal_error",
|
||||
"unavailable",
|
||||
"data_loss",
|
||||
"unauthenticated",
|
||||
}
|
||||
return m[ss]
|
||||
return spanStatuses[ss]
|
||||
}
|
||||
|
||||
func (ss SpanStatus) MarshalJSON() ([]byte, error) {
|
||||
@@ -866,6 +900,25 @@ func WithSpanSampled(sampled Sampled) SpanOption {
|
||||
}
|
||||
}
|
||||
|
||||
// WithSpanOrigin sets the origin of the span.
|
||||
func WithSpanOrigin(origin SpanOrigin) SpanOption {
|
||||
return func(s *Span) {
|
||||
s.Origin = origin
|
||||
}
|
||||
}
|
||||
|
||||
// Continue a trace based on traceparent and bagge values.
|
||||
// If the SDK is configured with tracing enabled,
|
||||
// this function returns populated SpanOption.
|
||||
// In any other cases, it populates the propagation context on the scope.
|
||||
func ContinueTrace(hub *Hub, traceparent, baggage string) SpanOption {
|
||||
scope := hub.Scope()
|
||||
propagationContext, _ := PropagationContextFromHeaders(traceparent, baggage)
|
||||
scope.SetPropagationContext(propagationContext)
|
||||
|
||||
return ContinueFromHeaders(traceparent, baggage)
|
||||
}
|
||||
|
||||
// ContinueFromRequest returns a span option that updates the span to continue
|
||||
// an existing trace. If it cannot detect an existing trace in the request, the
|
||||
// span will be left unchanged.
|
||||
@@ -935,6 +988,7 @@ func SpanFromContext(ctx context.Context) *Span {
|
||||
func StartTransaction(ctx context.Context, name string, options ...SpanOption) *Span {
|
||||
currentTransaction, exists := ctx.Value(spanContextKey{}).(*Span)
|
||||
if exists {
|
||||
currentTransaction.ctx = ctx
|
||||
return currentTransaction
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user