Interface for an attribute container

3.4.0

interface IAttributeContainer<V> {
    attributes: IOTelAttributes;
    child: ((name?: string, snapshot?: boolean) => IAttributeContainer<OTelAttributeValue>);
    clear: (() => void);
    del: ((key: string) => boolean);
    droppedAttributes: number;
    entries: (() => Iterator<[string, V, eAttributeFilter], any, undefined>);
    forEach: ((callback: ((key: string, value: V, source?: eAttributeFilter) => void), thisArg?: any) => void);
    get: ((key: string, source?: eAttributeFilter) => V);
    has: ((key: string, source?: eAttributeFilter) => boolean);
    id: string;
    keys: (() => Iterator<string, any, undefined>);
    listen: ((callback: ((changeInfo: IAttributeChangeInfo<V>) => void)) => IUnloadHook);
    set: ((key: string, value: V) => boolean);
    size: number;
    values: (() => Iterator<V, any, undefined>);
}

Type Parameters

Properties

attributes: IOTelAttributes

Return a snapshot of the current attributes, including inherited ones. This value is read-only and reflects the state of the attributes at the time of access, and the returned instance will not change if any attributes are modified later, you will need to access the attributes property again to get the latest state.

Note: As this causes a snapshot to be taken, it is an expensive operation as it enumerates all attributes, so you SHOULD use this property sparingly.

A read-only snapshot of the current attributes

child: ((name?: string, snapshot?: boolean) => IAttributeContainer<OTelAttributeValue>)

Create a child attribute container that inherits from this one, optionally taking a snapshot so that any future changes to the parent container do not affect the child container. The child will use all of the configuration from the parent container.

Type declaration

clear: (() => void)

Clear all existing attributes from the container, this will also remove any inherited attributes from this instance only (it will not change the inherited attributes / container(s))

del: ((key: string) => boolean)

Delete an existing attribute, if the key doesn't exist this will return false. If the key does exist then it will be removed from this instance and any inherited value will be hidden (even if the inherited value changes)

Type declaration

    • (key): boolean
    • Parameters

      • key: string

        The attribute key to delete

      Returns boolean

      True if the attribute was deleted, false if it didn't exist (which includes if it has already been deleted)

droppedAttributes: number

The number of attributes that were dropped due to the attribute limit being reached

The number of attributes that were dropped due to the attribute limit being reached

entries: (() => Iterator<[string, V, eAttributeFilter], any, undefined>)

The entries() method of returns a new iterator object that contains the [key, value, source?] tuples for each attribute, it returns all existing attributes of this instance including all inherited ones. If the same key exists in both the local and inherited attributes, only the first (non-deleted) tuple will be returned. If the key has been deleted, it will not be included in the iterator.

The source value of the tuple identifies the origin of the attribute (Local or Inherited).

Type declaration

    • (): Iterator<[string, V, eAttributeFilter], any, undefined>
    • Returns Iterator<[string, V, eAttributeFilter], any, undefined>

      An iterator over the entries of the attribute container

forEach: ((callback: ((key: string, value: V, source?: eAttributeFilter) => void), thisArg?: any) => void)

The forEach() method of executes a provided function once per each key/value pair in this attribute container, it will process all local attributes first, then the inherited attributes. If the same key exists in both the local and inherited attributes, only the first (non-deleted) key/value pair will be processed. If a key has been deleted, it will not be included in the set of processed key/value pairs.

Type declaration

    • (callback, thisArg?): void
    • Parameters

      • callback: ((key: string, value: V, source?: eAttributeFilter) => void)

        The function to execute for each key/value pair

          • (key, value, source?): void
          • Parameters

            Returns void

      • OptionalthisArg: any

        Optional value to use as this when executing callback

      Returns void

get: ((key: string, source?: eAttributeFilter) => V)

Get the value of an attribute by key

Type declaration

    • (key, source?): V
    • Parameters

      • key: string

        The attribute key to retrieve

      • Optionalsource: eAttributeFilter

        Optional filter to only check attributes from a specific source (Local or Inherited)

      Returns V

      The attribute value if found, undefined otherwise

has: ((key: string, source?: eAttributeFilter) => boolean)

Check if an attribute exists by key

Type declaration

    • (key, source?): boolean
    • Parameters

      • key: string

        The attribute key to check

      • Optionalsource: eAttributeFilter

        Optional filter to only check attributes from a specific source (Local or Inherited)

      Returns boolean

      True if the attribute exists, false otherwise

id: string

Unique identifier for the attribute container

keys: (() => Iterator<string, any, undefined>)

The keys() method returns a new iterator object that contains the existing keys for each element in this attribute container. It will return all locally set keys first and then the inherited keys. When a key exists in both the local and inherited attributes, only the local key will be returned. If the key has been deleted locally, it will not be included in the iterator.

Type declaration

    • (): Iterator<string, any, undefined>
    • Returns Iterator<string, any, undefined>

      An iterator over the keys of the attribute container

listen: ((callback: ((changeInfo: IAttributeChangeInfo<V>) => void)) => IUnloadHook)

Register a callback listener for any attribute changes, this will include local and inherited changes.

Type declaration

    • (callback): IUnloadHook
    • Parameters

      Returns IUnloadHook

      IUnloadHook instance with rm() function to remove this listener, once called it will never be invoked again

set: ((key: string, value: V) => boolean)

Set the value of an attribute by key on this instance.

Type declaration

    • (key, value): boolean
    • Parameters

      • key: string

        The attribute key to set

      • value: V

        The value to assign to the named attribute

      Returns boolean

      true if the value was successfully set / replaced

size: number

The number of attributes that have been set

The number of attributes that have been set

values: (() => Iterator<V, any, undefined>)

The values() method returns a new iterator instance that contains the values for each element in this attribute container. It will return all locally set values first and then the inherited values. If the same key is present in both the local or inherited attributes only the first (non-deleted) value will be returned. If a key has been deleted, it will not be included in the iterator.

Type declaration

    • (): Iterator<V, any, undefined>
    • Returns Iterator<V, any, undefined>

      An iterator over the values of the attribute container