• Helper function to identify if a passed argument is or implements the IAttributeContainer interface

    Parameters

    • value: any

      The value to check

    Returns value is IAttributeContainer<OTelAttributeValue>

    true if the value implements IAttributeContainer interface, false otherwise

    3.4.0

    const container = createAttributeContainer(config, "test-container");
    if (isAttributeContainer(container)) {
    // TypeScript now knows container is IAttributeContainer
    console.log(container.size);
    container.set("key", "value");
    }

    // Check unknown object
    function processContainer(obj: unknown) {
    if (isAttributeContainer(obj)) {
    obj.forEach((key, value) => console.log(key, value));
    }
    }