Save custom attributes of product in woocommerce

Finally I got it working with next code:

$product = wc_get_product($productId);
$attrName="my_attribute";
$attrValue="some value"

$attr = new WC_Product_Attribute();
$attr->set_name( $attrName );
$attr->set_options( [$attrValue] );
$attr->set_visible(1);
$attr->set_variation(1);
$attr->set_position(0);
$attr->set_id( 0 );
$attrs[$attrName] = $attr;
$product->set_attributes($attrs);
$product->save();

tech