MSP-8292 Up deps
This commit is contained in:
1 parent
3a66223a89
commit
5daaea50a1
186 files changed
+7092
-1579
No files matched your search
+59
@@ -1,5 +1,64 @@
|
||||
# Changelog
|
||||
|
||||
## 0.48.0
|
||||
|
||||
### Breaking Changes 🛠
|
||||
|
||||
- Remove issue creation from logging integrations by @giortzisg in [#1340](https://github.com/getsentry/sentry-go/pull/1340)
|
||||
|
||||
### New Features ✨
|
||||
|
||||
- Add `ClientOptions.DataCollection` for granular control over data collected by automatic instrumentation, replacing the broad `SendDefaultPII` switch. `DataCollection` can independently configure automatic `user.*` population, cookies, request/response headers, HTTP bodies, and query parameters. When configured, it is the source of truth and `SendDefaultPII` is ignored. by @giortzisg in [#1339](https://github.com/getsentry/sentry-go/pull/1339)
|
||||
- For backwards compatibility, clients that do not configure `DataCollection` keep a best-effort mapping of the previous `SendDefaultPII` behavior. To opt in to the new defaults, pass an empty `DataCollection` and then restrict individual categories as needed.
|
||||
```go
|
||||
sentry.Init(sentry.ClientOptions{
|
||||
Dsn: "https://public@example.com/1",
|
||||
|
||||
// Opt in to the new data collection defaults. Omitted fields use their
|
||||
// defaults: user info, cookies, headers, query params, and supported HTTP
|
||||
// bodies are collected, with sensitive values filtered.
|
||||
DataCollection: &sentry.DataCollection{},
|
||||
})
|
||||
```
|
||||
- To opt in while disabling automatic user info and HTTP bodies, configure those fields explicitly:
|
||||
```go
|
||||
sentry.Init(sentry.ClientOptions{
|
||||
Dsn: "https://public@example.com/1",
|
||||
DataCollection: &sentry.DataCollection{
|
||||
UserInfo: sentry.Set(false),
|
||||
HTTPBodies: []sentry.BodyType{},
|
||||
},
|
||||
})
|
||||
```
|
||||
- PushScope shorthand now returns the new scope reference by @DoctorJohn in [#1335](https://github.com/getsentry/sentry-go/pull/1335)
|
||||
|
||||
### Bug Fixes 🐛
|
||||
|
||||
- Fix fiber route name when using middlewares by @giortzisg in [#1363](https://github.com/getsentry/sentry-go/pull/1363)
|
||||
- Omit empty event id for standalone client reports by @giortzisg in [#1362](https://github.com/getsentry/sentry-go/pull/1362)
|
||||
- Preserve '%' literal in log messages by @giortzisg in [#1358](https://github.com/getsentry/sentry-go/pull/1358)
|
||||
- Unaligned 64-bit atomic panic on 32-bit platforms in telemetry buffers by @Kirill-INQ in [#1355](https://github.com/getsentry/sentry-go/pull/1355)
|
||||
- Isolate event processor across clones by @giortzisg in [#1337](https://github.com/getsentry/sentry-go/pull/1337)
|
||||
|
||||
### Internal Changes 🔧
|
||||
|
||||
#### Deps
|
||||
|
||||
- Bump fiber/v2 to 2.52.14 by @giortzisg in [#1359](https://github.com/getsentry/sentry-go/pull/1359)
|
||||
- Bump actions/checkout from 6.0.3 to 7.0.0 by @dependabot in [#1349](https://github.com/getsentry/sentry-go/pull/1349)
|
||||
- Bump golangci/golangci-lint-action from 9.2.1 to 9.3.0 by @dependabot in [#1346](https://github.com/getsentry/sentry-go/pull/1346)
|
||||
- Bump codecov/codecov-action from 6.0.0 to 7.0.0 by @dependabot in [#1347](https://github.com/getsentry/sentry-go/pull/1347)
|
||||
- Bump actions/setup-go from 6.4.0 to 6.5.0 by @dependabot in [#1343](https://github.com/getsentry/sentry-go/pull/1343)
|
||||
- Bump golang.org/x/crypto to 0.52.0 and golang/x/net to 0.55.0 by @giortzisg in [#1341](https://github.com/getsentry/sentry-go/pull/1341)
|
||||
- Bump getsentry/github-workflows/validate-pr from c802283cd9075b7a2b7a32655019c21c21676e34 to 4013fc6e1aeb1be1f9d3b4d232624f0ec1afa613 by @dependabot in [#1344](https://github.com/getsentry/sentry-go/pull/1344)
|
||||
|
||||
#### Other
|
||||
|
||||
- Remove changelog-preview and codecov actions by @giortzisg in [#1357](https://github.com/getsentry/sentry-go/pull/1357)
|
||||
- Add govulncheck audit action by @giortzisg in [#1342](https://github.com/getsentry/sentry-go/pull/1342)
|
||||
- Limit changelog-preview secret access by @giortzisg in [#1350](https://github.com/getsentry/sentry-go/pull/1350)
|
||||
- Move limited buffer under utils by @giortzisg in [#1338](https://github.com/getsentry/sentry-go/pull/1338)
|
||||
|
||||
## 0.47.0
|
||||
|
||||
### Breaking Changes 🛠
|
||||
|
||||
+26
-3
@@ -172,9 +172,18 @@ type ClientOptions struct {
|
||||
// List of regexp strings that will be used to match against a transaction's
|
||||
// name. If a match is found, then the transaction will be dropped.
|
||||
IgnoreTransactions []string
|
||||
// Deprecated: Use DataCollection for granular control over what data the
|
||||
// SDK collects. When DataCollection is configured, SendDefaultPII is
|
||||
// ignored.
|
||||
//
|
||||
// If this flag is enabled, certain personally identifiable information (PII) is added by active integrations.
|
||||
// By default, no such data is sent.
|
||||
SendDefaultPII bool
|
||||
// DataCollection configures what data the SDK collects automatically. All fields are optional. By default
|
||||
// the SDK collects rich context for debugging while scrubbing sensitive values.
|
||||
//
|
||||
// See https://docs.sentry.io/platforms/go/configuration/options/#DataCollection
|
||||
DataCollection *DataCollection
|
||||
// BeforeSend is called before error events are sent to Sentry.
|
||||
// You can use it to mutate the event or return nil to discard it.
|
||||
BeforeSend func(event *Event, hint *EventHint) *Event
|
||||
@@ -373,6 +382,9 @@ func NewClient(options ClientOptions) (*Client, error) {
|
||||
options.TraceIgnoreStatusCodes = [][]int{{404}}
|
||||
}
|
||||
|
||||
resolvedDataCollection := snapshotDataCollection(options.DataCollection, options.SendDefaultPII)
|
||||
options.DataCollection = cloneDataCollection(&resolvedDataCollection)
|
||||
|
||||
// SENTRYGODEBUG is a comma-separated list of key=value pairs (similar
|
||||
// to GODEBUG). It is not a supported feature: recognized debug options
|
||||
// may change any time.
|
||||
@@ -585,7 +597,18 @@ func (client *Client) externalTraceContextFromContext(ctx context.Context) (Trac
|
||||
// Options return ClientOptions for the current Client.
|
||||
func (client *Client) Options() ClientOptions {
|
||||
// Note: internally, consider using `client.options` instead of `client.Options()` to avoid copying the object each time.
|
||||
return client.options
|
||||
opts := client.options
|
||||
opts.DataCollection = cloneDataCollection(client.options.DataCollection)
|
||||
return opts
|
||||
}
|
||||
|
||||
// GetDataCollection returns a copy of the resolved data collection
|
||||
// configuration used by the client.
|
||||
func (client *Client) GetDataCollection() DataCollection {
|
||||
if client == nil || client.options.DataCollection == nil {
|
||||
return DataCollection{}
|
||||
}
|
||||
return *cloneDataCollection(client.options.DataCollection)
|
||||
}
|
||||
|
||||
// CaptureMessage captures an arbitrary message.
|
||||
@@ -686,7 +709,7 @@ func (client *Client) captureMetric(metric *Metric, _ *Scope) bool {
|
||||
|
||||
// Recover captures a panic.
|
||||
// Returns EventID if successfully, or nil if there's no error to recover from.
|
||||
func (client *Client) Recover(err interface{}, hint *EventHint, scope EventModifier) *EventID {
|
||||
func (client *Client) Recover(err any, hint *EventHint, scope EventModifier) *EventID {
|
||||
if err == nil {
|
||||
err = recover()
|
||||
}
|
||||
@@ -703,7 +726,7 @@ func (client *Client) Recover(err interface{}, hint *EventHint, scope EventModif
|
||||
// Returns EventID if successfully, or nil if there's no error to recover from.
|
||||
func (client *Client) RecoverWithContext(
|
||||
ctx context.Context,
|
||||
err interface{},
|
||||
err any,
|
||||
hint *EventHint,
|
||||
scope EventModifier,
|
||||
) *EventID {
|
||||
|
||||
+217
@@ -0,0 +1,217 @@
|
||||
package sentry
|
||||
|
||||
import "slices"
|
||||
|
||||
// CollectionMode controls how key-value data (headers, cookies, query params) is collected.
|
||||
//
|
||||
// Defaults to CollectionDenyList.
|
||||
type CollectionMode int
|
||||
|
||||
const (
|
||||
// CollectionDenyList keeps all keys and filters denied values.
|
||||
CollectionDenyList CollectionMode = iota
|
||||
|
||||
// CollectionOff disables collection of the category entirely.
|
||||
CollectionOff
|
||||
|
||||
// CollectionAllowList keeps all keys and sends real values only for allowed keys.
|
||||
CollectionAllowList
|
||||
)
|
||||
|
||||
// KeyValueCollectionBehavior configures how key-value data is collected and filtered.
|
||||
type KeyValueCollectionBehavior struct {
|
||||
// Mode controls the collection strategy.
|
||||
Mode CollectionMode
|
||||
// Terms is a list of additional terms used by the active mode.
|
||||
Terms []string
|
||||
}
|
||||
|
||||
// HeaderCollectionConfig configures how HTTP headers are collected for
|
||||
// requests and responses independently.
|
||||
type HeaderCollectionConfig struct {
|
||||
// Request configures collection of HTTP request headers.
|
||||
Request *KeyValueCollectionBehavior
|
||||
// Response configures collection of HTTP response headers.
|
||||
Response *KeyValueCollectionBehavior
|
||||
}
|
||||
|
||||
// BodyType identifies a category of HTTP body to collect.
|
||||
type BodyType string
|
||||
|
||||
const (
|
||||
// BodyIncomingRequest collects bodies from incoming HTTP requests
|
||||
// (server-side).
|
||||
BodyIncomingRequest BodyType = "incomingRequest"
|
||||
|
||||
// BodyOutgoingRequest collects bodies from outgoing HTTP requests
|
||||
// (client-side).
|
||||
BodyOutgoingRequest BodyType = "outgoingRequest"
|
||||
|
||||
// BodyIncomingResponse collects bodies from incoming HTTP responses
|
||||
// (client-side).
|
||||
BodyIncomingResponse BodyType = "incomingResponse"
|
||||
)
|
||||
|
||||
// DataCollection configures what data the SDK collects automatically.
|
||||
// All fields are optional. nil or zero-value fields use the documented
|
||||
// defaults, which collect rich context for debugging while scrubbing sensitive
|
||||
// values via a built-in denylist.
|
||||
//
|
||||
// See https://docs.sentry.io/platforms/go/configuration/options/#DataCollection
|
||||
type DataCollection struct {
|
||||
// UserInfo controls automatic population of user.* fields from auto-instrumentation.
|
||||
//
|
||||
// This does NOT gate data explicitly set via Scope.SetUser(); that is
|
||||
// always attached. Defaults to true.
|
||||
UserInfo Option[bool]
|
||||
|
||||
// Cookies configures collection of HTTP cookies.
|
||||
//
|
||||
// Defaults to using the built-in DenyList.
|
||||
Cookies *KeyValueCollectionBehavior
|
||||
|
||||
// HTTPHeaders configures collection of HTTP request and response headers
|
||||
// independently.
|
||||
//
|
||||
// Defaults to both request and response using the built-in DenyList.
|
||||
HTTPHeaders *HeaderCollectionConfig
|
||||
|
||||
// HTTPBodies controls which HTTP body types are collected.
|
||||
//
|
||||
// Defaults to collecting all valid body types.
|
||||
HTTPBodies []BodyType
|
||||
|
||||
// QueryParams configures collection of URL query parameters.
|
||||
//
|
||||
// Defaults to using the built-in DenyList.
|
||||
QueryParams *KeyValueCollectionBehavior
|
||||
|
||||
// sensitiveTerms is the deny-list used for built-in sensitive-key
|
||||
// scrubbing.
|
||||
sensitiveTerms []string
|
||||
}
|
||||
|
||||
// cloneKeyValueCollectionBehavior returns a deep copy of b.
|
||||
func cloneKeyValueCollectionBehavior(b *KeyValueCollectionBehavior) *KeyValueCollectionBehavior {
|
||||
if b == nil {
|
||||
return nil
|
||||
}
|
||||
cloned := &KeyValueCollectionBehavior{Mode: b.Mode}
|
||||
if b.Terms != nil {
|
||||
cloned.Terms = slices.Clone(b.Terms)
|
||||
}
|
||||
return cloned
|
||||
}
|
||||
|
||||
// cloneHeaderCollectionConfig returns a deep copy of c.
|
||||
func cloneHeaderCollectionConfig(c *HeaderCollectionConfig) *HeaderCollectionConfig {
|
||||
if c == nil {
|
||||
return nil
|
||||
}
|
||||
return &HeaderCollectionConfig{
|
||||
Request: cloneKeyValueCollectionBehavior(c.Request),
|
||||
Response: cloneKeyValueCollectionBehavior(c.Response),
|
||||
}
|
||||
}
|
||||
|
||||
// cloneDataCollection returns a deep copy of dc.
|
||||
func cloneDataCollection(dc *DataCollection) *DataCollection {
|
||||
if dc == nil {
|
||||
return nil
|
||||
}
|
||||
cloned := &DataCollection{
|
||||
UserInfo: dc.UserInfo,
|
||||
Cookies: cloneKeyValueCollectionBehavior(dc.Cookies),
|
||||
HTTPHeaders: cloneHeaderCollectionConfig(dc.HTTPHeaders),
|
||||
QueryParams: cloneKeyValueCollectionBehavior(dc.QueryParams),
|
||||
sensitiveTerms: dc.sensitiveTerms,
|
||||
}
|
||||
if dc.HTTPBodies != nil {
|
||||
cloned.HTTPBodies = slices.Clone(dc.HTTPBodies)
|
||||
}
|
||||
return cloned
|
||||
}
|
||||
|
||||
// allBodyTypes returns all valid body types.
|
||||
func allBodyTypes() []BodyType {
|
||||
return []BodyType{
|
||||
BodyIncomingRequest,
|
||||
BodyOutgoingRequest,
|
||||
BodyIncomingResponse,
|
||||
}
|
||||
}
|
||||
|
||||
// snapshotDataCollection builds a fully-populated DataCollection based on given options.
|
||||
// It handles any unspecified values by applying the defaults. If the given opts are nil, this
|
||||
// provides a best-effort snapshot to align with sendDefaultPII for backwards compatibility.
|
||||
func snapshotDataCollection(opts *DataCollection, sendDefaultPII bool) DataCollection {
|
||||
if opts == nil {
|
||||
return legacyDataCollection(sendDefaultPII)
|
||||
}
|
||||
return resolveDataCollection(opts)
|
||||
}
|
||||
|
||||
func resolveDataCollection(dc *DataCollection) DataCollection {
|
||||
var resolved DataCollection
|
||||
if cloned := cloneDataCollection(dc); cloned != nil {
|
||||
resolved = *cloned
|
||||
}
|
||||
|
||||
if !resolved.UserInfo.IsSet {
|
||||
resolved.UserInfo = Set(true)
|
||||
}
|
||||
if resolved.Cookies == nil {
|
||||
resolved.Cookies = &KeyValueCollectionBehavior{}
|
||||
}
|
||||
if resolved.HTTPHeaders == nil {
|
||||
resolved.HTTPHeaders = &HeaderCollectionConfig{}
|
||||
}
|
||||
if resolved.HTTPHeaders.Request == nil {
|
||||
resolved.HTTPHeaders.Request = &KeyValueCollectionBehavior{}
|
||||
}
|
||||
if resolved.HTTPHeaders.Response == nil {
|
||||
resolved.HTTPHeaders.Response = &KeyValueCollectionBehavior{}
|
||||
}
|
||||
if resolved.HTTPBodies == nil {
|
||||
resolved.HTTPBodies = allBodyTypes()
|
||||
}
|
||||
if resolved.QueryParams == nil {
|
||||
resolved.QueryParams = &KeyValueCollectionBehavior{}
|
||||
}
|
||||
return resolved
|
||||
}
|
||||
|
||||
func legacyDataCollection(sendDefaultPII bool) DataCollection {
|
||||
if sendDefaultPII {
|
||||
return resolveDataCollection(&DataCollection{
|
||||
UserInfo: Set(true),
|
||||
Cookies: &KeyValueCollectionBehavior{},
|
||||
HTTPHeaders: &HeaderCollectionConfig{Request: &KeyValueCollectionBehavior{}, Response: &KeyValueCollectionBehavior{}},
|
||||
HTTPBodies: allBodyTypes(),
|
||||
QueryParams: &KeyValueCollectionBehavior{},
|
||||
})
|
||||
}
|
||||
|
||||
return resolveDataCollection(&DataCollection{
|
||||
UserInfo: Set(false),
|
||||
HTTPBodies: []BodyType{},
|
||||
Cookies: &KeyValueCollectionBehavior{Mode: CollectionOff},
|
||||
HTTPHeaders: &HeaderCollectionConfig{
|
||||
Request: &KeyValueCollectionBehavior{Mode: CollectionDenyList},
|
||||
Response: &KeyValueCollectionBehavior{Mode: CollectionDenyList},
|
||||
},
|
||||
QueryParams: &KeyValueCollectionBehavior{Mode: CollectionDenyList},
|
||||
sensitiveTerms: extendedSensitiveTerms,
|
||||
})
|
||||
}
|
||||
|
||||
// extendedSensitiveTerms are additional privacy terms that cover
|
||||
// user-identifying data such as IP forwarding headers and user IDs. Used for
|
||||
// backwards compatibility with SendDefaultPII=false.
|
||||
var extendedSensitiveTerms = []string{
|
||||
"forwarded",
|
||||
"-ip",
|
||||
"remote-",
|
||||
"via",
|
||||
"-user",
|
||||
}
|
||||
+308
@@ -0,0 +1,308 @@
|
||||
package sentry
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/url"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// defaultSensitiveTerms is the canonical list of case-insensitive,
|
||||
// partial-match terms used for scrubbing.
|
||||
//
|
||||
// See https://develop.sentry.dev/sdk/foundations/client/data-collection/#sensitive-denylist
|
||||
var defaultSensitiveTerms = []string{
|
||||
"auth",
|
||||
"bearer",
|
||||
"credentials",
|
||||
"csrf",
|
||||
"identity",
|
||||
"jwt",
|
||||
"key",
|
||||
"passwd",
|
||||
"password",
|
||||
"pwd",
|
||||
"saml",
|
||||
"secret",
|
||||
"session",
|
||||
"sid",
|
||||
"sso",
|
||||
"token",
|
||||
"xsrf",
|
||||
}
|
||||
|
||||
// filteredValue is the replacement for sensitive values.
|
||||
const filteredValue = "[Filtered]"
|
||||
|
||||
// filterKeyValues applies a KeyValueCollectionBehavior to a map of key-value
|
||||
// pairs. Keys are always preserved and values are replaced with "[Filtered]".
|
||||
//
|
||||
// Returns nil when the mode is CollectionOff.
|
||||
func (dc DataCollection) filterKeyValues(data map[string]string, behavior *KeyValueCollectionBehavior) map[string]string {
|
||||
if behavior == nil {
|
||||
behavior = &KeyValueCollectionBehavior{}
|
||||
}
|
||||
if behavior.Mode == CollectionOff {
|
||||
return nil
|
||||
}
|
||||
result := make(map[string]string, len(data))
|
||||
for k, v := range data {
|
||||
if dc.shouldFilterKey(k, behavior) {
|
||||
result[k] = filteredValue
|
||||
} else {
|
||||
result[k] = v
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
// FilterRequestHeaders applies the configured request-header collection behavior.
|
||||
func (dc DataCollection) FilterRequestHeaders(headers map[string]string) map[string]string {
|
||||
var behavior *KeyValueCollectionBehavior
|
||||
if dc.HTTPHeaders != nil {
|
||||
behavior = dc.HTTPHeaders.Request
|
||||
}
|
||||
return dc.filterKeyValues(headers, behavior)
|
||||
}
|
||||
|
||||
// FilterResponseHeaders applies the configured response-header collection behavior.
|
||||
func (dc DataCollection) FilterResponseHeaders(headers map[string]string) map[string]string {
|
||||
var behavior *KeyValueCollectionBehavior
|
||||
if dc.HTTPHeaders != nil {
|
||||
behavior = dc.HTTPHeaders.Response
|
||||
}
|
||||
return dc.filterKeyValues(headers, behavior)
|
||||
}
|
||||
|
||||
// CollectHTTPBody reports whether the given body type should be collected.
|
||||
func (dc *DataCollection) CollectHTTPBody(bt BodyType) bool {
|
||||
if dc == nil || dc.HTTPBodies == nil {
|
||||
return true
|
||||
}
|
||||
for _, t := range dc.HTTPBodies {
|
||||
if t == bt {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// CollectCookies reports whether cookies should be collected.
|
||||
func (dc *DataCollection) CollectCookies() bool {
|
||||
return dc == nil || dc.Cookies == nil || dc.Cookies.Mode != CollectionOff
|
||||
}
|
||||
|
||||
// CollectQueryParams reports whether query parameters should be collected.
|
||||
func (dc DataCollection) CollectQueryParams() bool {
|
||||
return dc.QueryParams == nil || dc.QueryParams.Mode != CollectionOff
|
||||
}
|
||||
|
||||
// FilterQueryString applies the configured query-parameter collection behavior.
|
||||
func (dc DataCollection) FilterQueryString(rawQuery string) string {
|
||||
if rawQuery == "" {
|
||||
return ""
|
||||
}
|
||||
values, _ := url.ParseQuery(rawQuery)
|
||||
return dc.filterURLValues(values, dc.QueryParams)
|
||||
}
|
||||
|
||||
// FilterURL applies query-parameter filtering to u and returns its redacted string form.
|
||||
func (dc DataCollection) FilterURL(u *url.URL) string {
|
||||
if u == nil {
|
||||
return ""
|
||||
}
|
||||
filtered := *u
|
||||
filtered.RawQuery = dc.FilterQueryString(u.RawQuery)
|
||||
return filtered.Redacted()
|
||||
}
|
||||
|
||||
// FilterCookies applies the configured cookie collection behavior.
|
||||
func (dc DataCollection) FilterCookies(values []string) string {
|
||||
parsed := parseKeyValueStrings(values, ';')
|
||||
if len(parsed) == 0 {
|
||||
return ""
|
||||
}
|
||||
filtered := dc.filterKeyValues(parsed, dc.Cookies)
|
||||
if len(filtered) == 0 {
|
||||
return ""
|
||||
}
|
||||
|
||||
parts := make([]string, 0, len(filtered))
|
||||
for key, value := range filtered {
|
||||
parts = append(parts, key+"="+value)
|
||||
}
|
||||
return strings.Join(parts, "; ")
|
||||
}
|
||||
|
||||
// FilterSetCookies applies the configured cookie collection behavior to
|
||||
// Set-Cookie header values.
|
||||
func (dc DataCollection) FilterSetCookies(values []string) string {
|
||||
filtered := make([]string, 0, len(values))
|
||||
for _, value := range values {
|
||||
if cookie := dc.filterSetCookie(value); cookie != "" {
|
||||
filtered = append(filtered, cookie)
|
||||
}
|
||||
}
|
||||
return strings.Join(filtered, ", ")
|
||||
}
|
||||
|
||||
func (dc DataCollection) filterSetCookie(setCookie string) string {
|
||||
if !dc.CollectCookies() {
|
||||
return ""
|
||||
}
|
||||
parts := strings.Split(setCookie, ";")
|
||||
name, value, ok := strings.Cut(parts[0], "=")
|
||||
name = strings.TrimSpace(name)
|
||||
if !ok || name == "" {
|
||||
return ""
|
||||
}
|
||||
if dc.shouldFilterKey(name, dc.Cookies) {
|
||||
value = filteredValue
|
||||
}
|
||||
parts[0] = name + "=" + value
|
||||
|
||||
for i := 1; i < len(parts); i++ {
|
||||
attribute, _, ok := strings.Cut(parts[i], "=")
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
if name := strings.TrimSpace(attribute); name != "" && dc.shouldFilterKey(name, dc.Cookies) {
|
||||
parts[i] = attribute + "=" + filteredValue
|
||||
}
|
||||
}
|
||||
|
||||
return strings.Join(parts, ";")
|
||||
}
|
||||
|
||||
// FilterHTTPBody applies sensitive-key filtering to parseable HTTP body data.
|
||||
// Opaque raw bodies are replaced entirely.
|
||||
func (dc DataCollection) FilterHTTPBody(body []byte, contentType string) string {
|
||||
if len(body) == 0 {
|
||||
return ""
|
||||
}
|
||||
|
||||
if strings.Contains(strings.ToLower(contentType), "application/json") || looksLikeJSON(body) {
|
||||
var value any
|
||||
if err := json.Unmarshal(body, &value); err == nil {
|
||||
filteredJSON := dc.filterJSONValue(value, nil)
|
||||
filtered, err := json.Marshal(filteredJSON)
|
||||
if err == nil {
|
||||
return string(filtered)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if strings.Contains(strings.ToLower(contentType), "application/x-www-form-urlencoded") {
|
||||
if values, err := url.ParseQuery(string(body)); err == nil {
|
||||
return dc.filterURLValues(values, nil)
|
||||
}
|
||||
}
|
||||
|
||||
return filteredValue
|
||||
}
|
||||
|
||||
func looksLikeJSON(body []byte) bool {
|
||||
trimmed := strings.TrimSpace(string(body))
|
||||
return strings.HasPrefix(trimmed, "{") || strings.HasPrefix(trimmed, "[")
|
||||
}
|
||||
|
||||
func (dc DataCollection) filterURLValues(values url.Values, behavior *KeyValueCollectionBehavior) string {
|
||||
if behavior == nil {
|
||||
behavior = &KeyValueCollectionBehavior{}
|
||||
}
|
||||
if behavior.Mode == CollectionOff {
|
||||
return ""
|
||||
}
|
||||
for key := range values {
|
||||
if dc.shouldFilterKey(key, behavior) {
|
||||
values.Set(key, filteredValue)
|
||||
}
|
||||
}
|
||||
return strings.ReplaceAll(values.Encode(), url.QueryEscape(filteredValue), filteredValue)
|
||||
}
|
||||
|
||||
func (dc DataCollection) filterJSONValue(value any, behavior *KeyValueCollectionBehavior) any {
|
||||
return dc.filterJSONNode(value, behavior, false)
|
||||
}
|
||||
|
||||
// filterJSONNode recursively filters a decoded JSON value.
|
||||
func (dc DataCollection) filterJSONNode(value any, behavior *KeyValueCollectionBehavior, keyed bool) any {
|
||||
if behavior != nil && behavior.Mode == CollectionOff {
|
||||
return nil
|
||||
}
|
||||
|
||||
switch value := value.(type) {
|
||||
case map[string]any:
|
||||
filtered := make(map[string]any, len(value))
|
||||
for key, child := range value {
|
||||
if dc.shouldFilterKey(key, behavior) {
|
||||
filtered[key] = filteredValue
|
||||
} else {
|
||||
filtered[key] = dc.filterJSONNode(child, behavior, true)
|
||||
}
|
||||
}
|
||||
return filtered
|
||||
case []any:
|
||||
filtered := make([]any, len(value))
|
||||
for i, child := range value {
|
||||
filtered[i] = dc.filterJSONNode(child, behavior, keyed)
|
||||
}
|
||||
return filtered
|
||||
default:
|
||||
if !keyed {
|
||||
return filteredValue
|
||||
}
|
||||
return value
|
||||
}
|
||||
}
|
||||
|
||||
// shouldFilterKey reports whether a key's value should be redacted under the
|
||||
// given behavior. It combines the built-in sensitive terms with the behavior's
|
||||
// user-provided terms.
|
||||
func (dc DataCollection) shouldFilterKey(key string, behavior *KeyValueCollectionBehavior) bool {
|
||||
if behavior == nil {
|
||||
behavior = &KeyValueCollectionBehavior{}
|
||||
}
|
||||
|
||||
sensitive := matchesDenyTerms(key, defaultSensitiveTerms) || matchesDenyTerms(key, dc.sensitiveTerms)
|
||||
|
||||
switch behavior.Mode {
|
||||
case CollectionOff:
|
||||
return true
|
||||
case CollectionAllowList:
|
||||
return sensitive || !matchesDenyTerms(key, behavior.Terms)
|
||||
default:
|
||||
return sensitive || matchesDenyTerms(key, behavior.Terms)
|
||||
}
|
||||
}
|
||||
|
||||
// matchesDenyTerms reports whether the key (case-insensitive) contains any of
|
||||
// the given terms as a substring.
|
||||
func matchesDenyTerms(key string, terms []string) bool {
|
||||
lower := strings.ToLower(key)
|
||||
for _, term := range terms {
|
||||
if strings.Contains(lower, strings.ToLower(term)) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// parseKeyValueStrings splits strings like "a=1; b=2" into a map.
|
||||
// Malformed parts without '=' and parts with empty keys are skipped.
|
||||
func parseKeyValueStrings(values []string, separator rune) map[string]string {
|
||||
result := make(map[string]string)
|
||||
for _, value := range values {
|
||||
for _, part := range strings.Split(value, string(separator)) {
|
||||
part = strings.TrimSpace(part)
|
||||
if part == "" {
|
||||
continue
|
||||
}
|
||||
key, value, ok := strings.Cut(part, "=")
|
||||
if !ok || strings.TrimSpace(key) == "" {
|
||||
continue
|
||||
}
|
||||
result[key] = value
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
+6
-3
@@ -36,7 +36,6 @@ github.com/cncf/xds/go v0.0.0-20251210132809-ee656c7534f5 h1:6xNmx7iTtyBRev0+D/T
|
||||
github.com/cncf/xds/go v0.0.0-20251210132809-ee656c7534f5/go.mod h1:KdCmV+x/BuvyMxRnYBlmVaq4OLiKW6iRQfvC62cvdkI=
|
||||
github.com/coreos/go-systemd/v22 v22.5.0 h1:RrqgGjYQKalulkV8NGVIfkXQf6YYmOyiJKk8iXXhfZs=
|
||||
github.com/creack/pty v1.1.9 h1:uDmaGzcdjhF4i/plgjmEsriH11Y0o7RKapEf/LDaM3w=
|
||||
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/dgraph-io/badger/v2 v2.2007.4 h1:TRWBQg8UrlUhaFdco01nO2uXwzKS7zd+HVdwV/GHc4o=
|
||||
github.com/dgraph-io/badger/v2 v2.2007.4/go.mod h1:vSw/ax2qojzbN6eXHIx6KPKtCSHJN/Uz0X0VPruTIhk=
|
||||
github.com/dgraph-io/ristretto v0.0.3-0.20200630154024-f66de99634de h1:t0UHb5vdojIDUqktM6+xJAfScFBsVpXZmqC9dsgJmeA=
|
||||
@@ -119,7 +118,6 @@ github.com/philhofer/fwd v1.1.3-0.20240916144458-20a13a1f6b7c/go.mod h1:RqIHx9QI
|
||||
github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e h1:aoZm08cpOy4WuID//EZDgcC4zIxODThtZNPirFr42+A=
|
||||
github.com/planetscale/vtprotobuf v0.6.1-0.20240319094008-0393e58bdf10 h1:GFCKgmp0tecUJ0sJuv4pzYCqS9+RGSn52M3FUwPs+uo=
|
||||
github.com/planetscale/vtprotobuf v0.6.1-0.20240319094008-0393e58bdf10/go.mod h1:t/avpk3KcrXxUnYOhZhMXJlSEyie6gQbtLq5NM3loB8=
|
||||
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c h1:ncq/mPwQF4JjgDlrVEn3C11VoGHZN7m8qihwgMEtzYw=
|
||||
github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c/go.mod h1:OmDBASR4679mdNQnz2pUhc2G8CO2JrUAVFDRBDP/hJE=
|
||||
github.com/prometheus/client_model v0.6.2 h1:oBsgwpGs7iVziMvrGhE53c/GrLUsZdHnqNwqPLxwZyk=
|
||||
@@ -128,7 +126,6 @@ github.com/rogpeppe/fastuuid v1.2.0 h1:Ppwyp6VYCF1nvBTXL3trRso7mXMlRrw9ooo375wvi
|
||||
github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ=
|
||||
github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc=
|
||||
github.com/rogpeppe/go-internal v1.8.0/go.mod h1:WmiCO8CzOY8rg0OYDC4/i/2WRWAB6poM+XZ2dLUbcbE=
|
||||
github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs=
|
||||
github.com/rs/xid v1.5.0 h1:mKX4bl4iPYJtEIxp6CYiUuLQ/8DYMoz0PUdtGgMFRVc=
|
||||
github.com/shirou/gopsutil/v3 v3.23.2 h1:PAWSuiAszn7IhPMBtXsbSCafej7PqUOvY6YywlQUExU=
|
||||
github.com/shirou/gopsutil/v3 v3.23.2/go.mod h1:gv0aQw33GLo3pG8SiWKiQrbDzbRY1K80RyZJ7V4Th1M=
|
||||
@@ -147,6 +144,9 @@ github.com/tklauser/go-sysconf v0.3.11/go.mod h1:GqXfhXY3kiPa0nAXPDIQIWzJbMCB7Am
|
||||
github.com/tklauser/numcpus v0.6.0 h1:kebhY2Qt+3U6RNK7UqpYNA+tJ23IBEGKkB7JQBfDYms=
|
||||
github.com/tklauser/numcpus v0.6.0/go.mod h1:FEZLMke0lhOUG6w2JadTzp0a+Nl8PF/GFkQ5UVIcaL4=
|
||||
github.com/valyala/fasthttp v1.58.0/go.mod h1:SYXvHHaFp7QZHGKSHmoMipInhrI5StHrhDTYVEjK/Kw=
|
||||
github.com/valyala/tcplisten v1.0.0 h1:rBHj/Xf+E1tRGZyWIWwJDiRY0zc1Js+CV5DqwacVSA8=
|
||||
github.com/valyala/tcplisten v1.0.0/go.mod h1:T0xQ8SeCZGxckz9qRXTfG43PvQ/mcWh7FwZEA7Ioqkc=
|
||||
github.com/yuin/goldmark v1.4.1 h1:/vn0k+RBvwlxEmP5E7SZMqNxPhfMVFEJiykr15/0XKM=
|
||||
github.com/yuin/goldmark v1.4.13 h1:fVcFKWvrslecOb/tg+Cc05dkeYx540o0FuFt3nUVDoE=
|
||||
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
|
||||
github.com/yusufpapurcu/wmi v1.2.2 h1:KBNDSne4vP5mbSWnJbO+51IMOXJB67QiYCSBrubbPRg=
|
||||
@@ -163,6 +163,7 @@ golang.org/x/image v0.25.0/go.mod h1:tCAmOEGthTtkalusGp1g3xa2gke8J6c2N565dTyl9Rs
|
||||
golang.org/x/mod v0.21.0/go.mod h1:6SkKJ3Xj0I0BrPOZoBy3bdMptDDU9oJrpohJ3eWZ1fY=
|
||||
golang.org/x/mod v0.33.0 h1:tHFzIWbBifEmbwtGz65eaWyGiGZatSrT9prnU8DbVL8=
|
||||
golang.org/x/mod v0.33.0/go.mod h1:swjeQEj+6r7fODbD2cqrnje9PnziFuw4bmLbBZFrQ5w=
|
||||
golang.org/x/mod v0.35.0 h1:Ww1D637e6Pg+Zb2KrWfHQUnH2dQRLBQyAtpr/haaJeM=
|
||||
golang.org/x/mod v0.35.0/go.mod h1:+GwiRhIInF8wPm+4AoT6L0FA1QWAad3OMdTRx4tFYlU=
|
||||
golang.org/x/net v0.30.0/go.mod h1:2wGyMJ5iFasEhkwi13ChkO/t1ECNC4X4eBKkVFyYFlU=
|
||||
golang.org/x/net v0.51.0/go.mod h1:aamm+2QF5ogm02fjy5Bb7CQ0WMt1/WVM7FtyaTLlA9Y=
|
||||
@@ -184,6 +185,7 @@ golang.org/x/telemetry v0.0.0-20260209163413-e7419c687ee4/go.mod h1:g5NllXBEermZ
|
||||
golang.org/x/telemetry v0.0.0-20260409153401-be6f6cb8b1fa/go.mod h1:kHjTxDEnAu6/Nl9lDkzjWpR+bmKfxeiRuSDlsMb70gE=
|
||||
golang.org/x/term v0.41.0 h1:QCgPso/Q3RTJx2Th4bDLqML4W6iJiaXFq2/ftQF13YU=
|
||||
golang.org/x/term v0.41.0/go.mod h1:3pfBgksrReYfZ5lvYM0kSO0LIkAl4Yl2bXOkKP7Ec2A=
|
||||
golang.org/x/term v0.43.0 h1:S4RLU2sB31O/NCl+zFN9Aru9A/Cq2aqKpTZJ6B+DwT4=
|
||||
golang.org/x/term v0.43.0/go.mod h1:lrhlHNdQJHO+1qVYiHfFKVuVioJIheAc3fBSMFYEIsk=
|
||||
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
|
||||
golang.org/x/text v0.19.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY=
|
||||
@@ -192,6 +194,7 @@ golang.org/x/tools v0.41.0/go.mod h1:XSY6eDqxVNiYgezAVqqCeihT4j1U2CCsqvH3WhQpnlg
|
||||
golang.org/x/tools v0.42.0 h1:uNgphsn75Tdz5Ji2q36v/nsFSfR/9BRFvqhGBaJGd5k=
|
||||
golang.org/x/tools v0.42.0/go.mod h1:Ma6lCIwGZvHK6XtgbswSoWroEkhugApmsXyrUmBhfr0=
|
||||
golang.org/x/tools v0.43.0/go.mod h1:uHkMso649BX2cZK6+RpuIPXS3ho2hZo4FVwfoy1vIk0=
|
||||
golang.org/x/tools v0.44.0 h1:UP4ajHPIcuMjT1GqzDWRlalUEoY+uzoZKnhOjbIPD2c=
|
||||
golang.org/x/tools v0.44.0/go.mod h1:KA0AfVErSdxRZIsOVipbv3rQhVXTnlU6UhKxHd1seDI=
|
||||
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE=
|
||||
gonum.org/v1/plot v0.15.2 h1:Tlfh/jBk2tqjLZ4/P8ZIwGrLEWQSPDLRm/SNWKNXiGI=
|
||||
|
||||
+21
-28
@@ -247,50 +247,43 @@ type Request struct {
|
||||
Env map[string]string `json:"env,omitempty"`
|
||||
}
|
||||
|
||||
func sendDefaultPIIEnabled(client *Client) bool {
|
||||
return client != nil && client.options.SendDefaultPII
|
||||
}
|
||||
|
||||
func newRequest(r *http.Request, sendDefaultPII bool) *Request {
|
||||
func newRequest(r *http.Request, client *Client) *Request {
|
||||
prot := protocol.SchemeHTTP
|
||||
if r.TLS != nil || r.Header.Get("X-Forwarded-Proto") == "https" {
|
||||
prot = protocol.SchemeHTTPS
|
||||
}
|
||||
url := fmt.Sprintf("%s://%s%s", prot, r.Host, r.URL.Path)
|
||||
|
||||
dc := client.GetDataCollection()
|
||||
|
||||
var cookies string
|
||||
var env map[string]string
|
||||
headers := map[string]string{}
|
||||
|
||||
if sendDefaultPII {
|
||||
// We read only the first Cookie header because of the specification:
|
||||
// https://tools.ietf.org/html/rfc6265#section-5.4
|
||||
// When the user agent generates an HTTP request, the user agent MUST NOT
|
||||
// attach more than one Cookie header field.
|
||||
cookies = r.Header.Get("Cookie")
|
||||
|
||||
headers = make(map[string]string, len(r.Header))
|
||||
for k, v := range r.Header {
|
||||
headers[k] = strings.Join(v, ",")
|
||||
headers := make(map[string]string, len(r.Header)+1)
|
||||
if dc.CollectCookies() {
|
||||
cookies = dc.FilterCookies(r.Header.Values("Cookie"))
|
||||
if cookies != "" {
|
||||
headers["Cookie"] = cookies
|
||||
}
|
||||
}
|
||||
for k, v := range r.Header {
|
||||
if strings.EqualFold(k, "Cookie") {
|
||||
continue
|
||||
}
|
||||
headers[k] = strings.Join(v, ",")
|
||||
}
|
||||
headers["Host"] = r.Host
|
||||
headers = dc.FilterRequestHeaders(headers)
|
||||
|
||||
var env map[string]string
|
||||
if dc.UserInfo.Value {
|
||||
if addr, port, err := net.SplitHostPort(r.RemoteAddr); err == nil {
|
||||
env = map[string]string{"REMOTE_ADDR": addr, "REMOTE_PORT": port}
|
||||
}
|
||||
} else {
|
||||
for k, v := range r.Header {
|
||||
if !IsSensitiveHeader(k) {
|
||||
headers[k] = strings.Join(v, ",")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
headers["Host"] = r.Host
|
||||
|
||||
return &Request{
|
||||
URL: url,
|
||||
Method: r.Method,
|
||||
QueryString: r.URL.RawQuery,
|
||||
QueryString: dc.FilterQueryString(r.URL.RawQuery),
|
||||
Cookies: cookies,
|
||||
Headers: headers,
|
||||
Env: env,
|
||||
@@ -302,7 +295,7 @@ func newRequest(r *http.Request, sendDefaultPII bool) *Request {
|
||||
// NewRequest avoids operations that depend on network access. In particular, it
|
||||
// does not read r.Body.
|
||||
func NewRequest(r *http.Request) *Request {
|
||||
return newRequest(r, sendDefaultPIIEnabled(CurrentHub().Client()))
|
||||
return newRequest(r, CurrentHub().Client())
|
||||
}
|
||||
|
||||
// Mechanism is the mechanism by which an exception was generated and handled.
|
||||
|
||||
+78
@@ -0,0 +1,78 @@
|
||||
package httputils
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"io"
|
||||
)
|
||||
|
||||
// MaxBodyBytes is the maximum number of bytes the SDK captures from an HTTP
|
||||
// body for attaching to events or spans. Bodies larger than this are dropped
|
||||
// rather than truncated, to avoid invalid partial structured payloads.
|
||||
const MaxBodyBytes = 10 * 1024
|
||||
|
||||
// ReadCloser combines an io.Reader and an io.Closer to implement io.ReadCloser.
|
||||
type ReadCloser struct {
|
||||
io.Reader
|
||||
io.Closer
|
||||
}
|
||||
|
||||
// LimitedBuffer is like a bytes.Buffer, but limited to store at most Capacity
|
||||
// bytes. Any writes past the capacity are silently discarded, similar to
|
||||
// io.Discard.
|
||||
type LimitedBuffer struct {
|
||||
Capacity int
|
||||
|
||||
bytes.Buffer
|
||||
overflow bool
|
||||
}
|
||||
|
||||
// NewLimitedBuffer returns a LimitedBuffer with the given capacity.
|
||||
func NewLimitedBuffer(capacity int) *LimitedBuffer {
|
||||
return &LimitedBuffer{Capacity: capacity}
|
||||
}
|
||||
|
||||
// NewLimitedBufferFromBytes returns a LimitedBuffer initialized from b.
|
||||
func NewLimitedBufferFromBytes(capacity int, b []byte) *LimitedBuffer {
|
||||
buf := NewLimitedBuffer(capacity)
|
||||
if len(b) > capacity {
|
||||
buf.overflow = true
|
||||
b = b[:capacity]
|
||||
}
|
||||
buf.Buffer = *bytes.NewBuffer(b)
|
||||
return buf
|
||||
}
|
||||
|
||||
// Write implements io.Writer.
|
||||
func (b *LimitedBuffer) Write(p []byte) (n int, err error) {
|
||||
originalLen := len(p)
|
||||
if b.overflow {
|
||||
return originalLen, nil
|
||||
}
|
||||
left := b.Capacity - b.Len()
|
||||
if left < 0 {
|
||||
left = 0
|
||||
}
|
||||
if len(p) > left {
|
||||
b.overflow = true
|
||||
p = p[:left]
|
||||
}
|
||||
_, err = b.Buffer.Write(p)
|
||||
return originalLen, err
|
||||
}
|
||||
|
||||
// Overflow returns true if the LimitedBuffer discarded bytes written to it.
|
||||
func (b *LimitedBuffer) Overflow() bool {
|
||||
return b.overflow
|
||||
}
|
||||
|
||||
// ReadBody reads up to MaxBodyBytes from r and returns the bytes read.
|
||||
func ReadBody(r io.Reader) []byte {
|
||||
if r == nil {
|
||||
return nil
|
||||
}
|
||||
data, err := io.ReadAll(io.LimitReader(r, MaxBodyBytes+1))
|
||||
if err != nil || len(data) == 0 || len(data) > MaxBodyBytes {
|
||||
return nil
|
||||
}
|
||||
return data
|
||||
}
|
||||
+199
@@ -0,0 +1,199 @@
|
||||
package httputils
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"io"
|
||||
"net"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// This wrapper is derived from https://github.com/go-chi/chi/blob/master/middleware/wrap_writer.go
|
||||
// Copyright (c) 2015-present Peter Kieltyka (https://github.com/pkieltyka), Google Inc.
|
||||
|
||||
// MIT License
|
||||
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
// this software and associated documentation files (the "Software"), to deal in
|
||||
// the Software without restriction, including without limitation the rights to
|
||||
// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||
// the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
// subject to the following conditions:
|
||||
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
// FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
// COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
// IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
// NewWrapResponseWriter wraps an http.ResponseWriter, returning a proxy that allows you to
|
||||
// hook into various parts of the response process.
|
||||
|
||||
func NewWrapResponseWriter(w http.ResponseWriter, protoMajor int) WrapResponseWriter {
|
||||
_, fl := w.(http.Flusher)
|
||||
|
||||
bw := basicWriter{ResponseWriter: w, code: http.StatusOK}
|
||||
|
||||
if protoMajor == 2 {
|
||||
_, ps := w.(http.Pusher)
|
||||
if fl && ps {
|
||||
return &http2FancyWriter{bw}
|
||||
}
|
||||
} else {
|
||||
_, hj := w.(http.Hijacker)
|
||||
_, rf := w.(io.ReaderFrom)
|
||||
if fl && hj && rf {
|
||||
return &httpFancyWriter{bw}
|
||||
}
|
||||
}
|
||||
if fl {
|
||||
return &flushWriter{bw}
|
||||
}
|
||||
|
||||
return &bw
|
||||
}
|
||||
|
||||
// WrapResponseWriter is a proxy around an http.ResponseWriter that allows you to hook
|
||||
// into various parts of the response process.
|
||||
type WrapResponseWriter interface {
|
||||
http.ResponseWriter
|
||||
// Status returns the HTTP status of the request, or 200 if one has not
|
||||
// yet been sent.
|
||||
Status() int
|
||||
// BytesWritten returns the total number of bytes sent to the client.
|
||||
BytesWritten() int
|
||||
// Tee causes the response body to be written to the given io.Writer in
|
||||
// addition to proxying the writes through. Only one io.Writer can be
|
||||
// tee'd to at once: setting a second one will overwrite the first.
|
||||
// Writes will be sent to the proxy before being written to this
|
||||
// io.Writer. It is illegal for the tee'd writer to be modified
|
||||
// concurrently with writes.
|
||||
Tee(io.Writer)
|
||||
// Unwrap returns the original proxied target.
|
||||
Unwrap() http.ResponseWriter
|
||||
}
|
||||
|
||||
// basicWriter wraps a http.ResponseWriter that implements the minimal
|
||||
// http.ResponseWriter interface.
|
||||
type basicWriter struct {
|
||||
http.ResponseWriter
|
||||
tee io.Writer
|
||||
code int
|
||||
bytes int
|
||||
wroteHeader bool
|
||||
}
|
||||
|
||||
func (b *basicWriter) WriteHeader(code int) {
|
||||
if !b.wroteHeader {
|
||||
b.code = code
|
||||
b.wroteHeader = true
|
||||
}
|
||||
b.ResponseWriter.WriteHeader(code)
|
||||
}
|
||||
|
||||
func (b *basicWriter) Write(buf []byte) (int, error) {
|
||||
b.maybeWriteHeader()
|
||||
n, err := b.ResponseWriter.Write(buf)
|
||||
if b.tee != nil {
|
||||
_, err2 := b.tee.Write(buf[:n])
|
||||
// Prefer errors generated by the proxied writer.
|
||||
if err == nil {
|
||||
err = err2
|
||||
}
|
||||
}
|
||||
b.bytes += n
|
||||
return n, err
|
||||
}
|
||||
|
||||
func (b *basicWriter) maybeWriteHeader() {
|
||||
if !b.wroteHeader {
|
||||
b.WriteHeader(http.StatusOK)
|
||||
}
|
||||
}
|
||||
|
||||
func (b *basicWriter) Status() int {
|
||||
return b.code
|
||||
}
|
||||
|
||||
func (b *basicWriter) BytesWritten() int {
|
||||
return b.bytes
|
||||
}
|
||||
|
||||
func (b *basicWriter) Tee(w io.Writer) {
|
||||
b.tee = w
|
||||
}
|
||||
|
||||
func (b *basicWriter) Unwrap() http.ResponseWriter {
|
||||
return b.ResponseWriter
|
||||
}
|
||||
|
||||
type flushWriter struct {
|
||||
basicWriter
|
||||
}
|
||||
|
||||
func (f *flushWriter) Flush() {
|
||||
f.wroteHeader = true
|
||||
|
||||
fl := f.ResponseWriter.(http.Flusher)
|
||||
fl.Flush()
|
||||
}
|
||||
|
||||
var _ http.Flusher = &flushWriter{}
|
||||
|
||||
// httpFancyWriter is a HTTP writer that additionally satisfies
|
||||
// http.Flusher, http.Hijacker, and io.ReaderFrom. It exists for the common case
|
||||
// of wrapping the http.ResponseWriter that package http gives you, in order to
|
||||
// make the proxied object support the full method set of the proxied object.
|
||||
type httpFancyWriter struct {
|
||||
basicWriter
|
||||
}
|
||||
|
||||
func (f *httpFancyWriter) Flush() {
|
||||
f.wroteHeader = true
|
||||
f.ResponseWriter.(http.Flusher).Flush()
|
||||
}
|
||||
|
||||
func (f *httpFancyWriter) Hijack() (net.Conn, *bufio.ReadWriter, error) {
|
||||
return f.ResponseWriter.(http.Hijacker).Hijack()
|
||||
}
|
||||
|
||||
func (f *http2FancyWriter) Push(target string, opts *http.PushOptions) error {
|
||||
return f.ResponseWriter.(http.Pusher).Push(target, opts)
|
||||
}
|
||||
|
||||
func (f *httpFancyWriter) ReadFrom(r io.Reader) (int64, error) {
|
||||
if f.tee != nil {
|
||||
n, err := io.Copy(&f.basicWriter, r)
|
||||
f.bytes += int(n)
|
||||
return n, err
|
||||
}
|
||||
rf := f.ResponseWriter.(io.ReaderFrom)
|
||||
f.maybeWriteHeader()
|
||||
n, err := rf.ReadFrom(r)
|
||||
f.bytes += int(n)
|
||||
return n, err
|
||||
}
|
||||
|
||||
var _ http.Flusher = &httpFancyWriter{}
|
||||
var _ http.Hijacker = &httpFancyWriter{}
|
||||
var _ http.Pusher = &http2FancyWriter{}
|
||||
var _ io.ReaderFrom = &httpFancyWriter{}
|
||||
|
||||
// http2FancyWriter is a HTTP2 writer that additionally satisfies
|
||||
// http.Flusher, and io.ReaderFrom. It exists for the common case
|
||||
// of wrapping the http.ResponseWriter that package http gives you, in order to
|
||||
// make the proxied object support the full method set of the proxied object.
|
||||
type http2FancyWriter struct {
|
||||
basicWriter
|
||||
}
|
||||
|
||||
func (f *http2FancyWriter) Flush() {
|
||||
f.wroteHeader = true
|
||||
|
||||
f.basicWriter.ResponseWriter.(http.Flusher).Flush()
|
||||
}
|
||||
|
||||
var _ http.Flusher = &http2FancyWriter{}
|
||||
+1
-1
@@ -17,7 +17,7 @@ type Envelope struct {
|
||||
// EnvelopeHeader represents the header of a Sentry envelope.
|
||||
type EnvelopeHeader struct {
|
||||
// EventID is the unique identifier for this event
|
||||
EventID string `json:"event_id"`
|
||||
EventID string `json:"event_id,omitempty"`
|
||||
|
||||
// SentAt is the timestamp when the event was sent from the SDK as string in RFC 3339 format.
|
||||
// Used for clock drift correction of the event timestamp. The time zone must be UTC.
|
||||
|
||||
+11
-9
@@ -46,8 +46,10 @@ type BucketedBuffer[T any] struct {
|
||||
timeout time.Duration
|
||||
lastFlushTime time.Time
|
||||
|
||||
offered int64
|
||||
dropped int64
|
||||
// atomic.Int64 instead of int64 + atomic ops: 64-bit atomics on plain
|
||||
// mid-struct fields panic on 32-bit platforms (4-byte field alignment).
|
||||
offered atomic.Int64
|
||||
dropped atomic.Int64
|
||||
onDropped func(item T, reason string)
|
||||
}
|
||||
|
||||
@@ -94,7 +96,7 @@ func NewBucketedBuffer[T any](
|
||||
}
|
||||
|
||||
func (b *BucketedBuffer[T]) Offer(item T) bool {
|
||||
atomic.AddInt64(&b.offered, 1)
|
||||
b.offered.Add(1)
|
||||
|
||||
traceID := ""
|
||||
if ta, ok := any(item).(TraceAware); ok {
|
||||
@@ -152,7 +154,7 @@ func (b *BucketedBuffer[T]) handleOverflow(item T, traceID string) bool {
|
||||
oldestBucket := b.buckets[b.head]
|
||||
if oldestBucket == nil {
|
||||
b.recordDroppedItem(item)
|
||||
atomic.AddInt64(&b.dropped, 1)
|
||||
b.dropped.Add(1)
|
||||
if b.onDropped != nil {
|
||||
b.onDropped(item, "buffer_full_invalid_state")
|
||||
}
|
||||
@@ -162,7 +164,7 @@ func (b *BucketedBuffer[T]) handleOverflow(item T, traceID string) bool {
|
||||
delete(b.traceIndex, oldestBucket.traceID)
|
||||
}
|
||||
droppedCount := len(oldestBucket.items)
|
||||
atomic.AddInt64(&b.dropped, int64(droppedCount))
|
||||
b.dropped.Add(int64(droppedCount))
|
||||
for _, di := range oldestBucket.items {
|
||||
b.recordDroppedItem(di)
|
||||
if b.onDropped != nil {
|
||||
@@ -183,14 +185,14 @@ func (b *BucketedBuffer[T]) handleOverflow(item T, traceID string) bool {
|
||||
b.totalItems++
|
||||
return true
|
||||
case OverflowPolicyDropNewest:
|
||||
atomic.AddInt64(&b.dropped, 1)
|
||||
b.dropped.Add(1)
|
||||
b.recordDroppedItem(item)
|
||||
if b.onDropped != nil {
|
||||
b.onDropped(item, "buffer_full_drop_newest")
|
||||
}
|
||||
return false
|
||||
default:
|
||||
atomic.AddInt64(&b.dropped, 1)
|
||||
b.dropped.Add(1)
|
||||
b.recordDroppedItem(item)
|
||||
if b.onDropped != nil {
|
||||
b.onDropped(item, "unknown_overflow_policy")
|
||||
@@ -351,8 +353,8 @@ func (b *BucketedBuffer[T]) Utilization() float64 {
|
||||
}
|
||||
return float64(b.totalItems) / float64(b.itemCapacity)
|
||||
}
|
||||
func (b *BucketedBuffer[T]) OfferedCount() int64 { return atomic.LoadInt64(&b.offered) }
|
||||
func (b *BucketedBuffer[T]) DroppedCount() int64 { return atomic.LoadInt64(&b.dropped) }
|
||||
func (b *BucketedBuffer[T]) OfferedCount() int64 { return b.offered.Load() }
|
||||
func (b *BucketedBuffer[T]) DroppedCount() int64 { return b.dropped.Load() }
|
||||
func (b *BucketedBuffer[T]) AcceptedCount() int64 { return b.OfferedCount() - b.DroppedCount() }
|
||||
func (b *BucketedBuffer[T]) DropRate() float64 {
|
||||
off := b.OfferedCount()
|
||||
|
||||
+10
-8
@@ -30,8 +30,10 @@ type RingBuffer[T any] struct {
|
||||
timeout time.Duration
|
||||
lastFlushTime time.Time
|
||||
|
||||
offered int64
|
||||
dropped int64
|
||||
// atomic.Int64 instead of int64 + atomic ops: 64-bit atomics on plain
|
||||
// mid-struct fields panic on 32-bit platforms (4-byte field alignment).
|
||||
offered atomic.Int64
|
||||
dropped atomic.Int64
|
||||
onDropped func(item T, reason string)
|
||||
}
|
||||
|
||||
@@ -72,7 +74,7 @@ func (b *RingBuffer[T]) SetDroppedCallback(callback func(item T, reason string))
|
||||
}
|
||||
|
||||
func (b *RingBuffer[T]) Offer(item T) bool {
|
||||
atomic.AddInt64(&b.offered, 1)
|
||||
b.offered.Add(1)
|
||||
|
||||
b.mu.Lock()
|
||||
defer b.mu.Unlock()
|
||||
@@ -91,7 +93,7 @@ func (b *RingBuffer[T]) Offer(item T) bool {
|
||||
b.head = (b.head + 1) % b.capacity
|
||||
b.tail = (b.tail + 1) % b.capacity
|
||||
|
||||
atomic.AddInt64(&b.dropped, 1)
|
||||
b.dropped.Add(1)
|
||||
b.recordDroppedItem(oldItem)
|
||||
if b.onDropped != nil {
|
||||
b.onDropped(oldItem, "buffer_full_drop_oldest")
|
||||
@@ -99,7 +101,7 @@ func (b *RingBuffer[T]) Offer(item T) bool {
|
||||
return true
|
||||
|
||||
case OverflowPolicyDropNewest:
|
||||
atomic.AddInt64(&b.dropped, 1)
|
||||
b.dropped.Add(1)
|
||||
b.recordDroppedItem(item)
|
||||
if b.onDropped != nil {
|
||||
b.onDropped(item, "buffer_full_drop_newest")
|
||||
@@ -107,7 +109,7 @@ func (b *RingBuffer[T]) Offer(item T) bool {
|
||||
return false
|
||||
|
||||
default:
|
||||
atomic.AddInt64(&b.dropped, 1)
|
||||
b.dropped.Add(1)
|
||||
b.recordDroppedItem(item)
|
||||
if b.onDropped != nil {
|
||||
b.onDropped(item, "unknown_overflow_policy")
|
||||
@@ -244,11 +246,11 @@ func (b *RingBuffer[T]) Utilization() float64 {
|
||||
}
|
||||
|
||||
func (b *RingBuffer[T]) OfferedCount() int64 {
|
||||
return atomic.LoadInt64(&b.offered)
|
||||
return b.offered.Load()
|
||||
}
|
||||
|
||||
func (b *RingBuffer[T]) DroppedCount() int64 {
|
||||
return atomic.LoadInt64(&b.dropped)
|
||||
return b.dropped.Load()
|
||||
}
|
||||
|
||||
func (b *RingBuffer[T]) AcceptedCount() int64 {
|
||||
|
||||
+10
-5
@@ -101,7 +101,7 @@ func (l *sentryLogger) Write(p []byte) (int, error) {
|
||||
return len(p), nil
|
||||
}
|
||||
|
||||
func (l *sentryLogger) log(ctx context.Context, level LogLevel, severity int, message string, entryAttrs map[string]attribute.Value, args ...interface{}) {
|
||||
func (l *sentryLogger) log(ctx context.Context, level LogLevel, severity int, message string, entryAttrs map[string]attribute.Value, format bool, args ...interface{}) {
|
||||
if message == "" {
|
||||
return
|
||||
}
|
||||
@@ -138,6 +138,11 @@ func (l *sentryLogger) log(ctx context.Context, level LogLevel, severity int, me
|
||||
attrs[k] = v
|
||||
}
|
||||
|
||||
body := message
|
||||
if format {
|
||||
body = fmt.Sprintf(message, args...)
|
||||
}
|
||||
|
||||
if len(args) > 0 {
|
||||
attrs["sentry.message.template"] = attribute.StringValue(message)
|
||||
for i, p := range args {
|
||||
@@ -151,14 +156,14 @@ func (l *sentryLogger) log(ctx context.Context, level LogLevel, severity int, me
|
||||
SpanID: spanID,
|
||||
Level: level,
|
||||
Severity: severity,
|
||||
Body: fmt.Sprintf(message, args...),
|
||||
Body: body,
|
||||
Attributes: attrs,
|
||||
}
|
||||
log.approximateSize = computeLogSize(log)
|
||||
|
||||
client.captureLog(log, scope)
|
||||
if client.options.Debug {
|
||||
debuglog.Printf(message, args...)
|
||||
debuglog.Print(body)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -327,7 +332,7 @@ func (e *logEntry) Uint64(key string, value uint64) LogEntry {
|
||||
}
|
||||
|
||||
func (e *logEntry) Emit(args ...interface{}) {
|
||||
e.logger.log(e.ctx, e.level, e.severity, fmt.Sprint(args...), e.attributes)
|
||||
e.logger.log(e.ctx, e.level, e.severity, fmt.Sprint(args...), e.attributes, false)
|
||||
|
||||
if e.level == LogLevelFatal {
|
||||
if e.shouldPanic {
|
||||
@@ -340,7 +345,7 @@ func (e *logEntry) Emit(args ...interface{}) {
|
||||
}
|
||||
|
||||
func (e *logEntry) Emitf(format string, args ...interface{}) {
|
||||
e.logger.log(e.ctx, e.level, e.severity, format, e.attributes, args...)
|
||||
e.logger.log(e.ctx, e.level, e.severity, format, e.attributes, true, args...)
|
||||
|
||||
if e.level == LogLevelFatal {
|
||||
if e.shouldPanic {
|
||||
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
package sentry
|
||||
|
||||
// Option represents an optional configuration value.
|
||||
//
|
||||
// The zero value is unset. Use Set to distinguish an explicitly configured
|
||||
// zero value, such as false, 0, or "", from an unset option.
|
||||
type Option[T any] struct {
|
||||
Value T
|
||||
IsSet bool
|
||||
}
|
||||
|
||||
// Set returns an Option containing v.
|
||||
func Set[T any](v T) Option[T] {
|
||||
return Option[T]{Value: v, IsSet: true}
|
||||
}
|
||||
|
||||
// Or returns the option value when set, or defaultValue otherwise.
|
||||
func (o Option[T]) Or(defaultValue T) T {
|
||||
if o.IsSet {
|
||||
return o.Value
|
||||
}
|
||||
return defaultValue
|
||||
}
|
||||
+10
-61
@@ -1,7 +1,6 @@
|
||||
package sentry
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"io"
|
||||
"maps"
|
||||
@@ -11,6 +10,7 @@ import (
|
||||
|
||||
"github.com/getsentry/sentry-go/attribute"
|
||||
"github.com/getsentry/sentry-go/internal/debuglog"
|
||||
"github.com/getsentry/sentry-go/internal/httputils"
|
||||
"github.com/getsentry/sentry-go/internal/ratelimit"
|
||||
"github.com/getsentry/sentry-go/report"
|
||||
)
|
||||
@@ -128,15 +128,15 @@ func (scope *Scope) SetRequest(r *http.Request) {
|
||||
}
|
||||
|
||||
// Don't buffer request body if we know it is oversized.
|
||||
if r.ContentLength > maxRequestBodyBytes {
|
||||
if r.ContentLength > httputils.MaxBodyBytes {
|
||||
return
|
||||
}
|
||||
// Don't buffer if there is no body.
|
||||
if r.Body == nil || r.Body == http.NoBody {
|
||||
return
|
||||
}
|
||||
buf := &limitedBuffer{Capacity: maxRequestBodyBytes}
|
||||
r.Body = readCloser{
|
||||
buf := httputils.NewLimitedBuffer(httputils.MaxBodyBytes)
|
||||
r.Body = httputils.ReadCloser{
|
||||
Reader: io.TeeReader(r.Body, buf),
|
||||
Closer: r.Body,
|
||||
}
|
||||
@@ -152,59 +152,7 @@ func (scope *Scope) SetRequestBody(b []byte) {
|
||||
scope.mu.Lock()
|
||||
defer scope.mu.Unlock()
|
||||
|
||||
capacity := maxRequestBodyBytes
|
||||
overflow := false
|
||||
if len(b) > capacity {
|
||||
overflow = true
|
||||
b = b[:capacity]
|
||||
}
|
||||
scope.requestBody = &limitedBuffer{
|
||||
Capacity: capacity,
|
||||
Buffer: *bytes.NewBuffer(b),
|
||||
overflow: overflow,
|
||||
}
|
||||
}
|
||||
|
||||
// maxRequestBodyBytes is the default maximum request body size to send to
|
||||
// Sentry.
|
||||
const maxRequestBodyBytes = 10 * 1024
|
||||
|
||||
// A limitedBuffer is like a bytes.Buffer, but limited to store at most Capacity
|
||||
// bytes. Any writes past the capacity are silently discarded, similar to
|
||||
// io.Discard.
|
||||
type limitedBuffer struct {
|
||||
Capacity int
|
||||
|
||||
bytes.Buffer
|
||||
overflow bool
|
||||
}
|
||||
|
||||
// Write implements io.Writer.
|
||||
func (b *limitedBuffer) Write(p []byte) (n int, err error) {
|
||||
// Silently ignore writes after overflow.
|
||||
if b.overflow {
|
||||
return len(p), nil
|
||||
}
|
||||
left := b.Capacity - b.Len()
|
||||
if left < 0 {
|
||||
left = 0
|
||||
}
|
||||
if len(p) > left {
|
||||
b.overflow = true
|
||||
p = p[:left]
|
||||
}
|
||||
return b.Buffer.Write(p)
|
||||
}
|
||||
|
||||
// Overflow returns true if the limitedBuffer discarded bytes written to it.
|
||||
func (b *limitedBuffer) Overflow() bool {
|
||||
return b.overflow
|
||||
}
|
||||
|
||||
// readCloser combines an io.Reader and an io.Closer to implement io.ReadCloser.
|
||||
type readCloser struct {
|
||||
io.Reader
|
||||
io.Closer
|
||||
scope.requestBody = httputils.NewLimitedBufferFromBytes(httputils.MaxBodyBytes, b)
|
||||
}
|
||||
|
||||
// SetAttributes adds attributes to the current scope.
|
||||
@@ -346,7 +294,7 @@ func (scope *Scope) Clone() *Scope {
|
||||
clone.level = scope.level
|
||||
clone.request = scope.request
|
||||
clone.requestBody = scope.requestBody
|
||||
clone.eventProcessors = scope.eventProcessors
|
||||
clone.eventProcessors = scope.eventProcessors[:len(scope.eventProcessors):len(scope.eventProcessors)]
|
||||
clone.propagationContext = scope.propagationContext
|
||||
clone.span = scope.span
|
||||
return clone
|
||||
@@ -463,7 +411,7 @@ func (scope *Scope) ApplyToEvent(event *Event, hint *EventHint, client *Client)
|
||||
}
|
||||
|
||||
if event.Request == nil && scope.request != nil {
|
||||
event.Request = newRequest(scope.request, sendDefaultPIIEnabled(client))
|
||||
event.Request = newRequest(scope.request, client)
|
||||
// NOTE: The SDK does not attempt to send partial request body data.
|
||||
//
|
||||
// The reason being that Sentry's ingest pipeline and UI are optimized
|
||||
@@ -473,8 +421,9 @@ func (scope *Scope) ApplyToEvent(event *Event, hint *EventHint, client *Client)
|
||||
//
|
||||
// Users can still send more data along their events if they want to,
|
||||
// for example using Event.Contexts.
|
||||
if scope.requestBody != nil && !scope.requestBody.Overflow() {
|
||||
event.Request.Data = string(scope.requestBody.Bytes())
|
||||
dc := client.GetDataCollection()
|
||||
if scope.requestBody != nil && !scope.requestBody.Overflow() && dc.CollectHTTPBody(BodyIncomingRequest) {
|
||||
event.Request.Data = dc.FilterHTTPBody(scope.requestBody.Bytes(), scope.request.Header.Get("Content-Type"))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+3
-3
@@ -6,7 +6,7 @@ import (
|
||||
)
|
||||
|
||||
// The version of the SDK.
|
||||
const SDKVersion = "0.47.0"
|
||||
const SDKVersion = "0.48.0"
|
||||
|
||||
// apiVersion is the minimum version of the Sentry API compatible with the
|
||||
// sentry-go SDK.
|
||||
@@ -101,9 +101,9 @@ func ConfigureScope(f func(scope *Scope)) {
|
||||
}
|
||||
|
||||
// PushScope is a shorthand for CurrentHub().PushScope.
|
||||
func PushScope() {
|
||||
func PushScope() *Scope {
|
||||
hub := CurrentHub()
|
||||
hub.PushScope()
|
||||
return hub.PushScope()
|
||||
}
|
||||
|
||||
// PopScope is a shorthand for CurrentHub().PopScope.
|
||||
|
||||
-39
@@ -111,45 +111,6 @@ func Pointer[T any](v T) *T {
|
||||
return &v
|
||||
}
|
||||
|
||||
var sensitiveHeaders = map[string]struct{}{
|
||||
"_csrf": {},
|
||||
"_csrf_token": {},
|
||||
"_session": {},
|
||||
"_xsrf": {},
|
||||
"api-key": {},
|
||||
"apikey": {},
|
||||
"auth": {},
|
||||
"authorization": {},
|
||||
"cookie": {},
|
||||
"credentials": {},
|
||||
"csrf": {},
|
||||
"csrf-token": {},
|
||||
"csrftoken": {},
|
||||
"ip-address": {},
|
||||
"passwd": {},
|
||||
"password": {},
|
||||
"private-key": {},
|
||||
"privatekey": {},
|
||||
"proxy-authorization": {},
|
||||
"remote-addr": {},
|
||||
"secret": {},
|
||||
"session": {},
|
||||
"sessionid": {},
|
||||
"token": {},
|
||||
"user-session": {},
|
||||
"x-api-key": {},
|
||||
"x-csrftoken": {},
|
||||
"x-forwarded-for": {},
|
||||
"x-real-ip": {},
|
||||
"xsrf-token": {},
|
||||
}
|
||||
|
||||
// IsSensitiveHeader reports whether a header or metadata key should be treated as sensitive.
|
||||
func IsSensitiveHeader(key string) bool {
|
||||
_, ok := sensitiveHeaders[strings.ToLower(key)]
|
||||
return ok
|
||||
}
|
||||
|
||||
// eventIdentifier returns a human-readable identifier for the event to be used in log messages.
|
||||
// Format: "<description> [<event-id>]".
|
||||
func eventIdentifier(event *Event) string {
|
||||
|
||||
Reference in new issue
Block a user