Update dependencies

This commit is contained in:
eleksir
2026-02-10 20:54:39 +03:00
parent f2fc168abe
commit 170d0d0ed4
559 changed files with 66718 additions and 72415 deletions

View File

@@ -2,10 +2,13 @@ package sentry
import (
"bytes"
"context"
"io"
"net/http"
"sync"
"time"
"github.com/getsentry/sentry-go/internal/debuglog"
)
// Scope holds contextual data for the current scope.
@@ -43,20 +46,22 @@ type Scope struct {
Overflow() bool
}
eventProcessors []EventProcessor
propagationContext PropagationContext
span *Span
}
// NewScope creates a new Scope.
func NewScope() *Scope {
scope := Scope{
breadcrumbs: make([]*Breadcrumb, 0),
attachments: make([]*Attachment, 0),
tags: make(map[string]string),
contexts: make(map[string]Context),
extra: make(map[string]interface{}),
fingerprint: make([]string, 0),
return &Scope{
breadcrumbs: make([]*Breadcrumb, 0),
attachments: make([]*Attachment, 0),
tags: make(map[string]string),
contexts: make(map[string]Context),
extra: make(map[string]interface{}),
fingerprint: make([]string, 0),
propagationContext: NewPropagationContext(),
}
return &scope
}
// AddBreadcrumb adds new breadcrumb to the current scope
@@ -292,6 +297,30 @@ func (scope *Scope) SetLevel(level Level) {
scope.level = level
}
// SetPropagationContext sets the propagation context for the current scope.
func (scope *Scope) SetPropagationContext(propagationContext PropagationContext) {
scope.mu.Lock()
defer scope.mu.Unlock()
scope.propagationContext = propagationContext
}
// GetSpan returns the span from the current scope.
func (scope *Scope) GetSpan() *Span {
scope.mu.RLock()
defer scope.mu.RUnlock()
return scope.span
}
// SetSpan sets a span for the current scope.
func (scope *Scope) SetSpan(span *Span) {
scope.mu.Lock()
defer scope.mu.Unlock()
scope.span = span
}
// Clone returns a copy of the current scope with all data copied over.
func (scope *Scope) Clone() *Scope {
scope.mu.RLock()
@@ -318,6 +347,8 @@ func (scope *Scope) Clone() *Scope {
clone.request = scope.request
clone.requestBody = scope.requestBody
clone.eventProcessors = scope.eventProcessors
clone.propagationContext = scope.propagationContext
clone.span = scope.span
return clone
}
@@ -335,7 +366,7 @@ func (scope *Scope) AddEventProcessor(processor EventProcessor) {
}
// ApplyToEvent takes the data from the current scope and attaches it to the event.
func (scope *Scope) ApplyToEvent(event *Event, hint *EventHint) *Event {
func (scope *Scope) ApplyToEvent(event *Event, hint *EventHint, client *Client) *Event {
scope.mu.RLock()
defer scope.mu.RUnlock()
@@ -379,6 +410,29 @@ func (scope *Scope) ApplyToEvent(event *Event, hint *EventHint) *Event {
}
}
if event.Contexts == nil {
event.Contexts = make(map[string]Context)
}
if scope.span != nil {
if _, ok := event.Contexts["trace"]; !ok {
event.Contexts["trace"] = scope.span.traceContext().Map()
}
transaction := scope.span.GetTransaction()
if transaction != nil {
event.sdkMetaData.dsc = DynamicSamplingContextFromTransaction(transaction)
}
} else {
event.Contexts["trace"] = scope.propagationContext.Map()
dsc := scope.propagationContext.DynamicSamplingContext
if !dsc.HasEntries() && client != nil {
dsc = DynamicSamplingContextFromScope(scope, client)
}
event.sdkMetaData.dsc = dsc
}
if len(scope.extra) > 0 {
if event.Extra == nil {
event.Extra = make(map[string]interface{}, len(scope.extra))
@@ -421,7 +475,7 @@ func (scope *Scope) ApplyToEvent(event *Event, hint *EventHint) *Event {
id := event.EventID
event = processor(event, hint)
if event == nil {
Logger.Printf("Event dropped by one of the Scope EventProcessors: %s\n", id)
debuglog.Printf("Event dropped by one of the Scope EventProcessors: %s\n", id)
return nil
}
}
@@ -435,9 +489,91 @@ func (scope *Scope) ApplyToEvent(event *Event, hint *EventHint) *Event {
// a proper deep copy: if some context values are pointer types (e.g. maps),
// they won't be properly copied.
func cloneContext(c Context) Context {
res := Context{}
res := make(Context, len(c))
for k, v := range c {
res[k] = v
}
return res
}
func (scope *Scope) populateAttrs(attrs map[string]Attribute) {
if scope == nil {
return
}
scope.mu.RLock()
defer scope.mu.RUnlock()
// Add user-related attributes
if !scope.user.IsEmpty() {
if scope.user.ID != "" {
attrs["user.id"] = Attribute{Value: scope.user.ID, Type: AttributeString}
}
if scope.user.Name != "" {
attrs["user.name"] = Attribute{Value: scope.user.Name, Type: AttributeString}
}
if scope.user.Email != "" {
attrs["user.email"] = Attribute{Value: scope.user.Email, Type: AttributeString}
}
}
// In the future, add scope.attributes here
// for k, v := range scope.attributes {
// attrs[k] = v
// }
}
// resolveScopeAndTrace resolves scope, trace ID, and span ID from the given contexts.
//
// The resolution order follows a most-specific-to-least-specific pattern:
// 1. Check for span directly in contexts (SpanFromContext) - this is the most specific
// source as it represents a span explicitly attached to the current operation's context
// 2. Check for hub in contexts (GetHubFromContext) - provides access to scope which may
// contain a span, but this is less specific than a directly attached span
// 3. Fall back to CurrentHub() - the global hub as a last resort
//
// This ordering ensures we always use the most contextually relevant tracing information.
// For example, if a specific span is active for an operation, we use that span's trace/span IDs
// rather than accidentally using a different span that might be set on the hub's scope.
func resolveScopeAndTrace(ctxs ...context.Context) (scope *Scope, traceID TraceID, spanID SpanID) {
var span *Span
var hub *Hub
for _, ctx := range ctxs {
if ctx == nil {
continue
}
if span = SpanFromContext(ctx); span != nil {
break
}
}
for _, ctx := range ctxs {
if ctx == nil {
continue
}
if hub = GetHubFromContext(ctx); hub != nil {
break
}
}
if hub == nil {
hub = CurrentHub()
}
scope = hub.Scope()
if scope != nil {
scope.mu.RLock()
if span == nil {
span = scope.span
}
if span != nil {
traceID = span.TraceID
spanID = span.SpanID
} else {
traceID = scope.propagationContext.TraceID
}
scope.mu.RUnlock()
}
return scope, traceID, spanID
}