-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Comply with W3C Baggage specification limits #7880
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
a47e403
Comply W3C baggage limit
XSAM e5f8e7b
Add tests
XSAM d8004b2
Update CHANGELOG
XSAM 70eca99
Fix CI
XSAM 0b29d8f
Merge branch 'main' into w3c-baggage-compliance
XSAM 3f30596
Keep the first N complete members that fit within limits
XSAM bcf12b0
Fix lint
XSAM bac8eec
Update Parse() to return partial baggage along with an error
XSAM 45734c5
extract error handler into internal/errorhandler
XSAM 0c94899
update New() to return partial baggage along with an error
XSAM bd1cc88
Use partial baggage and report errors to global error handler
XSAM e267543
Merge branch 'main' into w3c-baggage-compliance
XSAM 1d4c418
Update changelog
XSAM 1b59ccf
Move error handler tests to internal/errorhandler
XSAM ffcf419
Reduce repeated String() calls
XSAM 107f4ec
Use non-deterministic drop instead of first N
XSAM b436fd1
Fix typo
XSAM 94b2ae5
Correct parse byte accounting for duplicate keys
XSAM 61c987f
Merge branch 'main' into w3c-baggage-compliance
XSAM 9365258
Merge branch 'main' into w3c-baggage-compliance
dashpole 74e5d0a
Update tests
XSAM 8a9b109
Remove the logic of pre-computed size in baggage.New
XSAM ee28d7a
Merge branch 'main' into w3c-baggage-compliance
pellared File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,96 @@ | ||
| // Copyright The OpenTelemetry Authors | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| // Package errorhandler provides the global error handler for OpenTelemetry. | ||
| // | ||
| // This package has no OTel dependencies, allowing it to be imported by any | ||
| // package in the module without creating import cycles. | ||
| package errorhandler // import "go.opentelemetry.io/otel/internal/errorhandler" | ||
|
|
||
| import ( | ||
| "errors" | ||
| "log" | ||
| "sync" | ||
| "sync/atomic" | ||
| ) | ||
|
|
||
| // ErrorHandler handles irremediable events. | ||
| type ErrorHandler interface { | ||
| // Handle handles any error deemed irremediable by an OpenTelemetry | ||
| // component. | ||
| Handle(error) | ||
| } | ||
|
|
||
| type ErrDelegator struct { | ||
| delegate atomic.Pointer[ErrorHandler] | ||
| } | ||
|
|
||
| // Compile-time check that delegator implements ErrorHandler. | ||
| var _ ErrorHandler = (*ErrDelegator)(nil) | ||
|
|
||
| func (d *ErrDelegator) Handle(err error) { | ||
| if eh := d.delegate.Load(); eh != nil { | ||
| (*eh).Handle(err) | ||
| return | ||
| } | ||
| log.Print(err) | ||
| } | ||
|
|
||
| // setDelegate sets the ErrorHandler delegate. | ||
| func (d *ErrDelegator) setDelegate(eh ErrorHandler) { | ||
| d.delegate.Store(&eh) | ||
| } | ||
|
|
||
| type errorHandlerHolder struct { | ||
| eh ErrorHandler | ||
| } | ||
|
|
||
| var ( | ||
| globalErrorHandler = defaultErrorHandler() | ||
| delegateErrorHandlerOnce sync.Once | ||
| ) | ||
|
|
||
| // GetErrorHandler returns the global ErrorHandler instance. | ||
| // | ||
| // The default ErrorHandler instance returned will log all errors to STDERR | ||
| // until an override ErrorHandler is set with SetErrorHandler. All | ||
| // ErrorHandler returned prior to this will automatically forward errors to | ||
| // the set instance instead of logging. | ||
| // | ||
| // Subsequent calls to SetErrorHandler after the first will not forward errors | ||
| // to the new ErrorHandler for prior returned instances. | ||
| func GetErrorHandler() ErrorHandler { | ||
| return globalErrorHandler.Load().(errorHandlerHolder).eh | ||
| } | ||
|
|
||
| // SetErrorHandler sets the global ErrorHandler to h. | ||
| // | ||
| // The first time this is called all ErrorHandler previously returned from | ||
| // GetErrorHandler will send errors to h instead of the default logging | ||
| // ErrorHandler. Subsequent calls will set the global ErrorHandler, but not | ||
| // delegate errors to h. | ||
| func SetErrorHandler(h ErrorHandler) { | ||
| current := GetErrorHandler() | ||
|
|
||
| if _, cOk := current.(*ErrDelegator); cOk { | ||
| if _, ehOk := h.(*ErrDelegator); ehOk && current == h { | ||
| // Do not assign to the delegate of the default ErrDelegator to be | ||
| // itself. | ||
| log.Print(errors.New("no ErrorHandler delegate configured"), " ErrorHandler remains its current value.") | ||
| return | ||
| } | ||
| } | ||
|
|
||
| delegateErrorHandlerOnce.Do(func() { | ||
| if def, ok := current.(*ErrDelegator); ok { | ||
| def.setDelegate(h) | ||
| } | ||
| }) | ||
| globalErrorHandler.Store(errorHandlerHolder{eh: h}) | ||
| } | ||
|
|
||
| func defaultErrorHandler() *atomic.Value { | ||
| v := &atomic.Value{} | ||
| v.Store(errorHandlerHolder{eh: &ErrDelegator{}}) | ||
| return v | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.