• Creates a snapshot container based on the passed IOTelAttributes or IAttributeContainer. The returned container effectively treats the source attributes as immutable as at the time of creation, you may still add / update existing attributes without affecting the original source. And changes to the source attributes / container will not be reflected from the new snapshot container, only changes made to the returned container itself.

    Note: It implements this in a lazy manner, so changes made to the original source after the snapshot is taken will cause the changed attributes to be copied into this snapshot container with it's original value and cause a local version of the changed key (if not already been present) to be added, so when using the IAttributeContainer#has or IAttributeContainer#get methods, with the optional source filter as eAttributeFilter.Inherited it will only return attributes that were present and unchanged at the time of the snapshot. This means for those attributes you must use the eAttributeFilter.Local as source filter (or leave it undefined) to access the local version.

    It is recommended that you always use IAttributeContainer instances for better memory and performance overheads, for this specific function when you pass a IOTelAttributes instance it will create a copy of all present attributes at the point of creation (not lazily).

    Parameters

    Returns IAttributeContainer

    An IAttributeContainer instance that will preserves the attributes and values from the source attributes / container at creation time. The snapshot container will be named "snapshot(xxxx)" where xxxx is the source container ID, or "snapshot(...)" for non-container sources.

    3.4.0

    // Immediate copy for plain attributes
    const attrs = { key1: "value1", key2: "value2" };
    const snapshot = createAttributeSnapshot(attrs);
    // snapshot.id will be "snapshot(...).N"
    attrs.key1 = "changed"; // snapshot.get("key1") is still "value1"

    // Lazy copy-on-change for containers
    const container = createAttributeContainer(config, "my-container");
    container.set("key1", "value1");
    const snapshot2 = createAttributeSnapshot(container);
    // snapshot2.id will be "snapshot(my-container.N).M"
    container.set("key1", "changed"); // snapshot2.get("key1") remains "value1" (previous value copied)