Documentation

Overview

    Package baggage provides types and functions to manage W3C Baggage.

    Index

    Constants

    This section is empty.

    Variables

    This section is empty.

    Functions

    func ContextWithGetHook

    func ContextWithGetHook(ctx context.Context, hook GetHookFunc) context.Context

      ContextWithGetHook installs a hook function that will be invoked every time MapFromContext is called. To avoid unnecessary callback invocations (recursive or not), the callback can temporarily clear the hooks from the context with the ContextWithNoHooks function.

      Note that NewContext also calls MapFromContext, so the hook will be invoked.

      Passing nil GetHookFunc creates a context with no get hook to call.

      This function should not be used by applications or libraries. It is mostly for interoperation with other observability APIs.

      func ContextWithMap

      func ContextWithMap(ctx context.Context, m Map) context.Context

        ContextWithMap returns a context with the Map entered into it.

        func ContextWithNoCorrelationData

        func ContextWithNoCorrelationData(ctx context.Context) context.Context

          ContextWithNoCorrelationData returns a context stripped of correlation data.

          func ContextWithNoHooks

          func ContextWithNoHooks(ctx context.Context) (context.Context, SetHookFunc, GetHookFunc)

            ContextWithNoHooks creates a context with all the hooks disabled. Also returns old set and get hooks. This function can be used to temporarily clear the context from hooks and then reinstate them by calling ContextWithSetHook and ContextWithGetHook functions passing the hooks returned by this function.

            This function should not be used by applications or libraries. It is mostly for interoperation with other observability APIs.

            func ContextWithSetHook

            func ContextWithSetHook(ctx context.Context, hook SetHookFunc) context.Context

              ContextWithSetHook installs a hook function that will be invoked every time ContextWithMap is called. To avoid unnecessary callback invocations (recursive or not), the callback can temporarily clear the hooks from the context with the ContextWithNoHooks function.

              Note that NewContext also calls ContextWithMap, so the hook will be invoked.

              Passing nil SetHookFunc creates a context with no set hook to call.

              This function should not be used by applications or libraries. It is mostly for interoperation with other observability APIs.

              func NewContext

              func NewContext(ctx context.Context, keyvalues ...label.KeyValue) context.Context

                NewContext returns a context with the map from passed context updated with the passed key-value pairs.

                Types

                type GetHookFunc

                type GetHookFunc func(context.Context, Map) Map

                  GetHookFunc describes a type of a callback that is called when getting baggage from the context.

                  type Map

                  type Map struct {
                  	// contains filtered or unexported fields
                  }

                    Map is an immutable storage for correlations.

                    func MapFromContext

                    func MapFromContext(ctx context.Context) Map

                      MapFromContext gets the current Map from a Context.

                      func NewEmptyMap

                      func NewEmptyMap() Map

                        NewEmptyMap creates an empty correlations map.

                        func NewMap

                        func NewMap(update MapUpdate) Map

                          NewMap creates a map with the contents of the update applied. In this function, having an update with DropSingleK or DropMultiK makes no sense - those fields are effectively ignored.

                          func (Map) Apply

                          func (m Map) Apply(update MapUpdate) Map

                            Apply creates a copy of the map with the contents of the update applied. Apply will first drop the keys from DropSingleK and DropMultiK, then add key-value pairs from SingleKV and MultiKV.

                            func (Map) Foreach

                            func (m Map) Foreach(f func(label.KeyValue) bool)

                              Foreach calls a passed callback once on each key-value pair until all the key-value pairs of the map were iterated or the callback returns false, whichever happens first.

                              func (Map) HasValue

                              func (m Map) HasValue(k label.Key) bool

                                HasValue returns a boolean value indicating whether the key exist in the map.

                                func (Map) Len

                                func (m Map) Len() int

                                  Len returns a length of the map.

                                  func (Map) Value

                                  func (m Map) Value(k label.Key) (label.Value, bool)

                                    Value gets a value from correlations map and returns a boolean value indicating whether the key exist in the map.

                                    type MapUpdate

                                    type MapUpdate struct {
                                    	// DropSingleK contains a single key to be dropped from
                                    	// correlations. Use this to avoid an overhead of a slice
                                    	// allocation if there is only one key to drop.
                                    	DropSingleK label.Key
                                    	// DropMultiK contains all the keys to be dropped from
                                    	// correlations.
                                    	DropMultiK []label.Key
                                    
                                    	// SingleKV contains a single key-value pair to be added to
                                    	// correlations. Use this to avoid an overhead of a slice
                                    	// allocation if there is only one key-value pair to add.
                                    	SingleKV label.KeyValue
                                    	// MultiKV contains all the key-value pairs to be added to
                                    	// correlations.
                                    	MultiKV []label.KeyValue
                                    }

                                      MapUpdate contains information about correlation changes to be made.

                                      type SetHookFunc

                                      type SetHookFunc func(context.Context) context.Context

                                        SetHookFunc describes a type of a callback that is called when storing baggage in the context.

                                        Source Files